[Kst] extragear/graphics/kst/src

Eli Fidler eli at staikos.net
Thu Mar 29 20:20:40 CEST 2007


SVN commit 647867 by fidler:

add signal-slot connections to reparse equations and labels when object
tags change.

re: bug 142622

reviewed by George


 M  +4 -1      libkst/kstobject.cpp  
 M  +6 -1      libkst/kstobject.h  
 M  +17 -0     libkstapp/kstviewlabel.cpp  
 M  +1 -0      libkstapp/kstviewlabel.h  
 M  +15 -0     libkstmath/kstequation.cpp  
 M  +6 -1      libkstmath/kstequation.h  


--- trunk/extragear/graphics/kst/src/libkst/kstobject.cpp #647866:647867
@@ -31,7 +31,7 @@
 
 static int i = 0;
 
-KstObject::KstObject() : KstShared(), QObject(), KstRWLock(),
+KstObject::KstObject() : QObject(), KstShared(), KstRWLock(),
                          _lastUpdateCounter(0),
                          _tag(tr("Object %1").arg(++i), KstObjectTag::globalTagContext)
 {
@@ -82,6 +82,8 @@
 
   _tag = tag;
   setName(_tag.tagString().local8Bit().data());
+
+  emit tagChanged();
 }
 
 
@@ -122,4 +124,5 @@
 }
 
 
+#include "kstobject.moc"
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/src/libkst/kstobject.h #647866:647867
@@ -187,7 +187,9 @@
 };
 
 
-class KST_EXPORT KstObject : public KstShared, public QObject, public KstRWLock {
+class KST_EXPORT KstObject : public QObject, public KstShared, public KstRWLock {
+  Q_OBJECT
+
   public:
     KstObject();
 
@@ -217,6 +219,9 @@
     // @since 1.1.0
     bool dirty() const;
 
+  signals:
+    void tagChanged();
+
   protected:
     virtual ~KstObject();
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlabel.cpp #647866:647867
@@ -150,12 +150,29 @@
 }
 
 
+void KstViewLabel::setupConnections() {
+  for (KstScalarMap::iterator i = _scalarsUsed.begin(); i != _scalarsUsed.end(); ++i) {
+    disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse()));
+    connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse()));
+  } 
+  for (KstStringMap::iterator i = _stringsUsed.begin(); i != _stringsUsed.end(); ++i) {
+    disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse()));
+    connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse()));
+  } 
+  for (KstVectorMap::iterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) {
+    disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse()));
+    connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reparse()));
+  } 
+}
+
+
 void KstViewLabel::reparse() {
   delete _parsed;
   _parsed = Label::parse(_txt, _interpret);
   collectObjects(_parsed, _vectorsUsed, _scalarsUsed, _stringsUsed);
   _txt = labelText(_txt, _parsed, _vectorsUsed, _scalarsUsed, _stringsUsed);
   setDirty();
+  setupConnections();
 }
 
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlabel.h #647866:647867
@@ -141,6 +141,7 @@
     };
     DataCache _cache;
 
+    void setupConnections();
     KstScalarMap _scalarsUsed;
     KstStringMap _stringsUsed;
     KstVectorMap _vectorsUsed;
--- trunk/extragear/graphics/kst/src/libkstmath/kstequation.cpp #647866:647867
@@ -242,6 +242,7 @@
     if (rc == 0 && en) {
       if (en->takeVectorsAndScalars(VectorsUsed, ScalarsUsed)) {
         _equation = en->text();
+        setupConnections();
       } else {
         kstdWarning() << "Equation [" << _equation << "] failed to find its vectors/scalars when re-parsing." << endl;
       }
@@ -316,6 +317,7 @@
       KstStringMap sm;
 
       if (_pe->collectObjects(VectorsUsed, ScalarsUsed, sm)) {
+        setupConnections();
         _pe->update(-1, &ctx);
       } else {
         //we have bad objects...
@@ -479,6 +481,7 @@
       Equation::FoldVisitor vis(&ctx, &_pe);
       KstStringMap sm;
       _pe->collectObjects(VectorsUsed, ScalarsUsed, sm);
+      setupConnections();
       ParsedEquation = 0L;
     } else {
       delete (Equation::Node*)ParsedEquation;
@@ -646,4 +649,16 @@
 }
 
 
+void KstEquation::setupConnections() {
+  for (KstScalarMap::iterator i = ScalarsUsed.begin(); i != ScalarsUsed.end(); ++i) {
+    disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reParse()));
+    connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reParse()));
+  } 
+  for (KstVectorMap::iterator i = VectorsUsed.begin(); i != VectorsUsed.end(); ++i) {
+    disconnect(i.data(), SIGNAL(tagChanged()), this, SLOT(reParse()));
+    connect(i.data(), SIGNAL(tagChanged()), this, SLOT(reParse()));
+  } 
+}
+
+#include "kstequation.moc"
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/src/libkstmath/kstequation.h #647866:647867
@@ -31,6 +31,8 @@
 }
 
 class KST_EXPORT KstEquation : public KstDataObject {
+  Q_OBJECT
+
   public:
     KstEquation(const QString& in_tag, const QString& equation, double x0, double x1, int nx);
     KstEquation(const QString& in_tag, const QString& equation, KstVectorPtr xvector, bool do_interp);
@@ -44,7 +46,6 @@
 
     /** equations used to edit the vector */
     void setEquation(const QString &Equation);
-    void reParse();
 
     void setExistingXVector(KstVectorPtr xvector, bool do_interp);
 
@@ -76,11 +77,15 @@
 
     virtual bool uses(KstObjectPtr p) const;
 
+  public slots:
+    void reParse();
+
   private:
     QString _equation;
 
     KstVectorMap VectorsUsed;
     KstScalarMap ScalarsUsed;
+    void setupConnections();
 
     void commonConstructor(const QString& in_tag, const QString& equation);
 


More information about the Kst mailing list