[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Sun Aug 8 02:12:04 CEST 2004


CVS commit by staikos: 

review and address a few more FIXMEs, and add an efficient way for a datasource
to reset(), currently implemented by no-one, but supported by KstRVector.


  M +5 -0      kstdatasource.cpp   1.31
  M +5 -0      kstdatasource.h   1.16
  M +19 -17    kstrvector.cpp   1.53
  M +3 -1      kstvcurve.cpp   1.39
  M +2 -3      kstviewwidget.cpp   1.52


--- kdeextragear-2/kst/kst/kstdatasource.cpp  #1.30:1.31
@@ -441,3 +441,8 @@ bool KstDataSource::isEmpty() const {
 }
 
+
+bool KstDataSource::reset() {
+  return false;
+}
+
 // vim: ts=2 sw=2 et

--- kdeextragear-2/kst/kst/kstdatasource.h  #1.15:1.16
@@ -106,4 +106,9 @@ public:
   virtual bool isEmpty() const;
 
+  /** Reset to initial state of the source, just as though no data had been
+   *  read and the file had just been opened.  Return true on success.
+   */
+  virtual bool reset();
+
 protected:
   virtual void virtual_hook(int id, void *data);

--- kdeextragear-2/kst/kst/kstrvector.cpp  #1.52:1.53
@@ -18,17 +18,14 @@
 
 #include <math.h>
-#include <stdio.h>
 #include <stdlib.h>
 
-#include <qmessagebox.h>
-
 #include <kdebug.h>
 #include <klocale.h>
 
-#include "rwlock.h"
 #include "enodes.h"
 #include "kstdatacollection.h"
 #include "kstdebug.h"
 #include "kstrvector.h"
+#include "rwlock.h"
 
 /** Create a KstRVector: raw data from a file */
@@ -55,7 +52,7 @@ KstRVector::KstRVector(QDomElement &e, c
   /* parse the DOM tree */
   QDomNode n = e.firstChild();
-  while( !n.isNull() ) {
-    QDomElement e = n.toElement(); // try to convert the node to an element.
-    if( !e.isNull() ) { // the node was really an element.
+  while (!n.isNull()) {
+    QDomElement e = n.toElement();
+    if (!e.isNull()) {
       if (e.tagName() == "tag") {
         setTagName(e.text());
@@ -194,6 +191,5 @@ void KstRVector::changeFrames(int in_f0,
   DoSkip = in_DoSkip;
   DoAve = in_DoAve;
-  if (DoSkip) {
-    if (Skip < 1)
+  if (DoSkip && Skip < 1) {
       Skip = 1;
   }
@@ -204,6 +200,5 @@ void KstRVector::changeFrames(int in_f0,
   // ReqNF <=0 means read to end of file
   // ReqF0 < 0 means count back ReqNF from end of file
-  if (ReqNF <= 0) {
-    if (ReqF0 < 0)
+  if (ReqNF <= 0 && ReqF0 < 0) {
       ReqF0 = 0;
   }
@@ -213,8 +208,7 @@ KstRVector::~KstRVector() {  
   _file = 0;
 
-  if (AveReadBuf != NULL) {
+  if (AveReadBuf) {
     free(AveReadBuf);
-
-   AveReadBuf = NULL;
+    AveReadBuf = 0L;
   }
 }
@@ -444,4 +438,7 @@ KstObject::UpdateType KstRVector::doUpda
           AveReadBuf = static_cast<double*>
             (realloc(AveReadBuf, N_AveReadBuf*sizeof(double)));
+          if (!AveReadBuf) {
+            // FIXME: handle failed resize
+          }
         }
         ave_nread = _file->readField(AveReadBuf, _field, new_f0+i, Skip);
@@ -527,5 +524,10 @@ void KstRVector::reload() {
   }
 
-  // FIXME: inefficient
+  if (_file->reset()) { // Try the efficient way first
+    reset();
+    return;
+  }
+
+  // The inefficient way
   KstDataSourcePtr newsrc = KstDataSource::loadSource(_file->fileName(), _file->fileType());
   if (newsrc) {

--- kdeextragear-2/kst/kst/kstvcurve.cpp  #1.38:1.39
@@ -139,5 +139,7 @@ bool KstVCurve::loadInputs() {
     EY->readLock();
   }
-  update(); // FIXME: this update happens in the wrong thread
+  update(); // This happens in the GUI thread.  Might be a good idea to provide
+            // a mechanism to ask the update thread to update an object instead.
+            // (which would save us all this ugly locking too :))
   VX->readUnlock();
   VY->readUnlock();

--- kdeextragear-2/kst/kst/kstviewwidget.cpp  #1.51:1.52
@@ -106,6 +106,5 @@ void KstViewWidget::leaveEvent(QEvent *e
 //        objects at one level deep.
 KstViewObjectPtr KstViewWidget::findChildFor(const QPoint& pos) {
-  KstViewObjectPtr rc;
-  KstViewObjectPtr search = _view.data();
+  KstViewObjectPtr rc, search = _view.data();
 
   while (!rc.data()) {
@@ -124,5 +123,5 @@ KstViewObjectPtr KstViewWidget::findChil
 
 
-// FIXME: cache the previous child here to make it faster?  How to invalidate?
+// Optimize: cache the previous child here to make it faster?  How to invalidate?
 void KstViewWidget::mouseMoveEvent(QMouseEvent *e) {
   if (_view->viewMode() == KstTopLevelView::DisplayMode) {





More information about the Kst mailing list