[Kst] branches/work/kst/portto4/kst/src

Mike Fenton mike at staikos.net
Thu Apr 24 21:18:53 CEST 2008


SVN commit 800746 by fenton:

Initial signal / slot based update for Data Based Vector paths.


 M  +19 -1     libkst/datasource.cpp  
 M  +8 -0      libkst/datasource.h  
 M  +21 -0     libkst/datavector.cpp  
 M  +3 -0      libkst/datavector.h  
 M  +3 -0      libkst/object.h  
 M  +7 -0      libkst/vector.cpp  
 M  +5 -0      libkst/vector.h  
 M  +19 -4     libkstapp/plotrenderitem.cpp  
 M  +1 -0      libkstapp/plotrenderitem.h  
 M  +34 -1     libkstmath/curve.cpp  
 M  +6 -0      libkstmath/curve.h  
 M  +16 -0     libkstmath/dataobject.cpp  
 M  +5 -0      libkstmath/dataobject.h  
 M  +2 -0      libkstmath/equation.cpp  
 M  +8 -1      libkstmath/histogram.cpp  
 M  +5 -0      libkstmath/psd.cpp  


--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #800745:800746
@@ -29,6 +29,7 @@
 #include <QTextDocument>
 #include <QUrl>
 #include <QXmlStreamWriter>
+#include <QTimer>
 
 #include "kst_i18n.h"
 #include "datacollection.h"
@@ -473,7 +474,7 @@
 
 
 DataSource::DataSource(ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type)
-    : Object(), _filename(filename), _cfg(cfg) {
+    : Object(), _filename(filename), _cfg(cfg), _dataSourceVersion(0) {
   Q_UNUSED(type)
   _valid = false;
   _reusable = true;
@@ -496,6 +497,8 @@
   Q_ASSERT(store);
   _numFramesScalar = store->createObject<Scalar>(ObjectTag("frames", tag()));
   // Don't set provider - this is always up-to-date
+
+  QTimer::singleShot(1000, this, SLOT(checkUpdate()));
 }
 
 
@@ -504,6 +507,18 @@
 }
 
 
+void DataSource::checkUpdate() {
+  if (update()) {
+#if DEBUG_UPDATE_CYCLE
+    qDebug() << "DataSource" << shortName() << "updated to verison " << _dataSourceVersion;
+#endif
+    emit dataSourceUpdated(shortName(), _dataSourceVersion);
+  }
+
+  QTimer::singleShot(1000, this, SLOT(checkUpdate()));
+}
+
+
 void DataSource::deleteDependents() {
   _store->removeObject(_numFramesScalar);
   _numFramesScalar = 0L;
@@ -528,6 +543,9 @@
 
 
 void DataSource::updateNumFramesScalar() {
+  if (_numFramesScalar->value() != frameCount()) {
+    _dataSourceVersion++;
+  }
   _numFramesScalar->setValue(frameCount());
 }
 
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #800745:800746
@@ -227,6 +227,12 @@
 
     virtual void deleteDependents();
 
+  Q_SIGNALS:
+    void dataSourceUpdated(QString sourceName, int version);
+
+  public Q_SLOTS:
+    virtual void checkUpdate();
+
   protected:
     void updateNumFramesScalar();
 
@@ -257,6 +263,8 @@
 
     ScalarPtr _numFramesScalar;
 
+    int _dataSourceVersion;
+
     virtual QString _automaticDescriptiveName();
 
     // NOTE: You must bump the version key if you add new member variables
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #800745:800746
@@ -189,10 +189,27 @@
 
   if (!in_file) {
     Debug::self()->log(i18n("Data file for vector %1 was not opened.", tag().tagString()), Debug::Warning);
+  } else {
+    connect(in_file, SIGNAL(dataSourceUpdated(QString, int)), this, SLOT(dataSourceUpdated(QString, int)));
   }
 }
 
 
+void DataVector::dataSourceUpdated(QString sourceName, int version) {
+#if DEBUG_UPDATE_CYCLE
+  qDebug() << "Data Source update required by Vector" << shortName() << "for" << sourceName << version;
+#endif
+  writeLock();
+  if (update(version)) {
+#if DEBUG_UPDATE_CYCLE
+  qDebug() << "triggering vector of " << shortName() << "for" << sourceName << version;
+#endif
+    emit vectorUpdated(sourceName, version);
+  }
+  unlock();
+}
+
+
 void DataVector::change(DataSourcePtr in_file, const QString &in_field,
                         int in_f0, int in_n,
                         int in_skip, bool in_DoSkip,
@@ -224,6 +241,10 @@
     ReqF0 = 0;
   }
 
+  if (in_file) {
+    connect(in_file, SIGNAL(dataSourceUpdated(QString, int)), this, SLOT(dataSourceUpdated(QString, int)));
+  }
+
 }
 
 
--- branches/work/kst/portto4/kst/src/libkst/datavector.h #800745:800746
@@ -111,6 +111,9 @@
     /** the data source */
     DataSourcePtr dataSource() const;
 
+  public Q_SLOTS:
+    void dataSourceUpdated(QString sourceName, int);
+
   protected:
     /** Create an RVECTOR */
     DataVector(ObjectStore *store, const ObjectTag& tag,
--- branches/work/kst/portto4/kst/src/libkst/object.h #800745:800746
@@ -31,6 +31,9 @@
 #include "rwlock.h"
 #include "objecttag.h"
 
+// Provides additional output during update cycle.
+#define DEBUG_UPDATE_CYCLE 1
+
 namespace Kst {
 
 class ObjectStore;
--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #800745:800746
@@ -548,7 +548,14 @@
 }
 
 
+void Vector::triggerUpdateSignal(QString sourceName, int version) {
+#if DEBUG_UPDATE_CYCLE
+  qDebug() << "triggering vector update of" << shortName() << "for" << sourceName << version;
+#endif
+  emit vectorUpdated(sourceName, version);
+}
 
+
 void Vector::save(QXmlStreamWriter &s) {
   if (provider()) {
     return;
--- branches/work/kst/portto4/kst/src/libkst/vector.h #800745:800746
@@ -155,6 +155,11 @@
     bool saveData() const;
     virtual void setSaveData(bool save);
 
+    void triggerUpdateSignal(QString sourceName, int version);
+
+  Q_SIGNALS:
+    void vectorUpdated(QString sourceName, int version);
+
   protected:
     /** current number of samples */
     int _size;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #800745:800746
@@ -91,19 +91,34 @@
 }
 
 
+void PlotRenderItem::relationUpdated(QString sourceName, int version) {
+  qDebug() << "Relation Updated" << sourceName << version;
+  update();
+}
+
+
 void PlotRenderItem::addRelation(RelationPtr relation) {
-  _relationList.append(relation);
-  plotItem()->zoomMaximum();
+  if (relation) {
+    connect(relation, SIGNAL(relationUpdated(QString, int)), this, SLOT(relationUpdated(QString, int)));
+    _relationList.append(relation);
+    plotItem()->zoomMaximum();
+  }
 }
 
 
 void PlotRenderItem::removeRelation(RelationPtr relation) {
-  _relationList.removeAll(relation);
-  plotItem()->zoomMaximum();
+  if (relation) {
+    disconnect(relation, SIGNAL(relationUpdated(QString, int)));
+    _relationList.removeAll(relation);
+    plotItem()->zoomMaximum();
+  }
 }
 
 
 void PlotRenderItem::clearRelations() {
+  foreach (RelationPtr relation, _relationList) {
+    disconnect(relation, SIGNAL(relationUpdated(QString, int)));
+  }
   _relationList.clear();
   plotItem()->zoomMaximum();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #800745:800746
@@ -71,6 +71,7 @@
     virtual void createLayout();
     virtual void breakLayout();
     virtual void remove();
+    virtual void relationUpdated(QString sourceName, int version);
 
   protected:
     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
--- branches/work/kst/portto4/kst/src/libkstmath/curve.cpp #800745:800746
@@ -81,26 +81,32 @@
   commonConstructor(in_color);
   if (in_X) {
     _inputVectors[COLOR_XVECTOR] = in_X;
+    connect(in_X, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   }
 
   if (in_Y) {
     _inputVectors[COLOR_YVECTOR] = in_Y;
+    connect(in_Y, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   }
 
   if (in_EX) {
     _inputVectors[EXVECTOR] = in_EX;
+    connect(in_EX, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   }
 
   if (in_EY) {
     _inputVectors[EYVECTOR] = in_EY;
+    connect(in_EY, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   }
 
   if (in_EXMinus) {
     _inputVectors[EXMINUSVECTOR] = in_EXMinus;
+    connect(in_EXMinus, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   }
 
   if (in_EYMinus) {
     _inputVectors[EYMINUSVECTOR] = in_EYMinus;
+    connect(in_EYMinus, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   }
 
   _shortName = "C"+QString::number(_cnum++);
@@ -217,6 +223,21 @@
 }
 
 
+void Curve::vectorUpdated(QString sourceName, int version) {
+#if DEBUG_UPDATE_CYCLE
+  qDebug() << "Vector update required by Curve" << shortName() << "for" << sourceName << version;
+#endif
+  writeLock();
+  if (update(version)) {
+#if DEBUG_UPDATE_CYCLE
+  qDebug() << "triggering relation update of curve" << shortName() << "for" << sourceName << version;
+#endif
+    emit relationUpdated(sourceName, version);
+  }
+  unlock();
+}
+
+
 Object::UpdateType Curve::update(int update_counter) {
   Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
 
@@ -235,7 +256,7 @@
 
   writeLockInputsAndOutputs();
 
-  bool depUpdated = force;
+  bool depUpdated = true;
 
   depUpdated = UPDATE == cxV->update(update_counter) || depUpdated;
   depUpdated = UPDATE == cyV->update(update_counter) || depUpdated;
@@ -517,7 +538,9 @@
 void Curve::setXVector(VectorPtr new_vx) {
   if (new_vx) {
     _inputVectors[COLOR_XVECTOR] = new_vx;
+    connect(new_vx, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   } else {
+    disconnect(_inputVectors[COLOR_XVECTOR], SIGNAL(vectorUpdated(QString, int)));
     _inputVectors.remove(COLOR_XVECTOR);
   }
   setDirty();
@@ -527,7 +550,9 @@
 void Curve::setYVector(VectorPtr new_vy) {
   if (new_vy) {
     _inputVectors[COLOR_YVECTOR] = new_vy;
+    connect(new_vy, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   } else {
+    disconnect(_inputVectors[COLOR_YVECTOR], SIGNAL(vectorUpdated(QString, int)));
     _inputVectors.remove(COLOR_YVECTOR);
   }
   setDirty();
@@ -537,7 +562,9 @@
 void Curve::setXError(VectorPtr new_ex) {
   if (new_ex) {
     _inputVectors[EXVECTOR] = new_ex;
+    connect(new_ex, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   } else {
+    disconnect(_inputVectors[EXVECTOR], SIGNAL(vectorUpdated(QString, int)));
     _inputVectors.remove(EXVECTOR);
   }
   setDirty();
@@ -547,7 +574,9 @@
 void Curve::setYError(VectorPtr new_ey) {
   if (new_ey) {
     _inputVectors[EYVECTOR] = new_ey;
+    connect(new_ey, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   } else {
+    disconnect(_inputVectors[EYVECTOR], SIGNAL(vectorUpdated(QString, int)));
     _inputVectors.remove(EYVECTOR);
   }
   setDirty();
@@ -557,7 +586,9 @@
 void Curve::setXMinusError(VectorPtr new_ex) {
   if (new_ex) {
     _inputVectors[EXMINUSVECTOR] = new_ex;
+    connect(new_ex, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   } else {
+    disconnect(_inputVectors[EXMINUSVECTOR], SIGNAL(vectorUpdated(QString, int)));
     _inputVectors.remove(EXMINUSVECTOR);
   }
   setDirty();
@@ -567,7 +598,9 @@
 void Curve::setYMinusError(VectorPtr new_ey) {
   if (new_ey) {
     _inputVectors[EYMINUSVECTOR] = new_ey;
+    connect(new_ey, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   } else {
+    disconnect(_inputVectors[EYMINUSVECTOR], SIGNAL(vectorUpdated(QString, int)));
     _inputVectors.remove(EYMINUSVECTOR);
   }
   setDirty();
--- branches/work/kst/portto4/kst/src/libkstmath/curve.h #800745:800746
@@ -152,6 +152,12 @@
     // see KstRelation::providerDataObject
     virtual DataObjectPtr providerDataObject() const;
 
+  Q_SIGNALS:
+    void relationUpdated(QString relationName, int version);
+
+  public Q_SLOTS:
+    void vectorUpdated(QString sourceName, int version);
+
   protected:
     Curve(ObjectStore *store, const ObjectTag &in_tag,
         VectorPtr in_X=0L, VectorPtr in_Y=0L,
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.cpp #800745:800746
@@ -41,6 +41,7 @@
   //qDebug() << "+++ CREATING DATA OBJECT: " << (void*)this << endl;
   _curveHints = new CurveHintList;
   _isInputLoaded = false;
+  _updateVersion = 0;
 }
 
 DataObject::DataObject(ObjectStore *store, const QDomElement& e) : Object() {
@@ -48,6 +49,7 @@
   //qDebug() << "+++ CREATING DATA OBJECT: " << (void*)this << endl;
   _curveHints = new CurveHintList;
   _isInputLoaded = false;
+  _updateVersion = 0;
 }
 
 
@@ -165,6 +167,20 @@
 }
 
 
+void DataObject::vectorUpdated(QString sourceName, int version) {
+#if DEBUG_UPDATE_CYCLE
+  qDebug() << "Vector update required by DataObject " << shortName() << "for" << sourceName << version;
+#endif
+  writeLock();
+  if (update(version)) {
+#if DEBUG_UPDATE_CYCLE
+  qDebug() << "Update complete of DataObject" << shortName() << "Vector updates triggered for outputs";
+#endif
+  }
+  unlock();
+}
+
+
 void DataObject::load(const QXmlStreamReader &e) {
   qDebug() << QString("FIXME! Loading of %1 is not implemented yet.").arg(typeString()) << endl;
   Q_UNUSED(e)
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.h #800745:800746
@@ -121,6 +121,9 @@
 
     void showDialog(bool isNew = true);
 
+  public Q_SLOTS:
+    void vectorUpdated(QString sourceName, int version);
+
   protected slots:
     virtual void showNewDialog() = 0;
     virtual void showEditDialog() = 0;
@@ -143,6 +146,8 @@
     virtual void writeLockInputsAndOutputs() const;
     virtual void unlockInputsAndOutputs() const;
 
+    int _updateVersion;
+
     VectorMap _inputVectors;
     VectorMap _outputVectors;
     ScalarMap _inputScalars;
--- branches/work/kst/portto4/kst/src/libkstmath/equation.cpp #800745:800746
@@ -284,6 +284,8 @@
   _xInVector = in_xv;
   _inputVectors.insert(XINVECTOR, in_xv);
 
+  connect(in_xv, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
+
   _ns = 2; // reset the updating
   _doInterp = do_interp;
 }
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.cpp #800745:800746
@@ -279,6 +279,10 @@
   _hVector->setDirty();
   _hVector->update(update_counter);
 
+  _updateVersion++;
+  _bVector->triggerUpdateSignal(shortName(), _updateVersion);
+  _hVector->triggerUpdateSignal(shortName(), _updateVersion);
+
   unlockInputsAndOutputs();
 
   return setLastUpdateResult(UPDATE);
@@ -335,7 +339,10 @@
 
 
 void Histogram::setVector(VectorPtr new_v) {
-  _inputVectors[RAWVECTOR] = new_v;
+  if (new_v) {
+    connect(new_v, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
+    _inputVectors[RAWVECTOR] = new_v;
+  }
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstmath/psd.cpp #800745:800746
@@ -267,6 +267,10 @@
   _fVector->setDirty();
   _fVector->update(update_counter);
 
+  _updateVersion++;
+  _sVector->triggerUpdateSignal(shortName(), _updateVersion);
+  _fVector->triggerUpdateSignal(shortName(), _updateVersion);
+
   unlockInputsAndOutputs();
 
   return setLastUpdateResult(UPDATE);
@@ -408,6 +412,7 @@
   _inputVectors.remove(INVECTOR);
   new_v->writeLock();
   _inputVectors[INVECTOR] = new_v;
+  connect(new_v, SIGNAL(vectorUpdated(QString, int)), this, SLOT(vectorUpdated(QString, int)));
   setDirty();
 }
 


More information about the Kst mailing list