[Kst] branches/work/kst/viewupdates/kst/src
George Staikos
staikos at kde.org
Sun May 28 17:14:35 CEST 2006
SVN commit 545934 by staikos:
This actually seems to be about enough to make scalar updates trigger view
changes in labels. I can genericize this later, but for now it's quite optimal.
M +24 -6 libkst/kstscalar.cpp
M +5 -0 libkst/kstscalar.h
M +6 -0 libkstapp/kstdoc.cpp
M +1 -0 libkstapp/kstviewlabel.h
M +23 -0 libkstapp/updatethread.cpp
--- branches/work/kst/viewupdates/kst/src/libkst/kstscalar.cpp #545933:545934
@@ -18,11 +18,25 @@
#include "kstscalar.h"
#include "kstdatacollection.h"
#include <klocale.h>
+#include "ksdebug.h"
#include <qstylesheet.h>
static int iAnonymousScalarCounter = 0;
+static bool dirtyScalars = false;
+
+bool KstScalar::scalarsDirty() {
+ // Should use a mutex, but let's play with fire to be fast
+ return dirtyScalars;
+}
+
+
+void KstScalar::clearScalarsDirty() {
+ // Should use a mutex, but let's play with fire to be fast
+ dirtyScalars = false;
+}
+
/** Create the base scalar */
KstScalar::KstScalar(const QString& in_tag, double val, bool orphan, bool displayable, bool doLock, bool editable)
: KstObject(), _value(val), _orphan(orphan), _displayable(displayable), _editable(editable) {
@@ -95,8 +109,10 @@
double v = value();
if (_provider) {
_provider->update(updateCounter);
+ } else if (force) {
+ return setLastUpdateResult(UPDATE);
}
-
+
return setLastUpdateResult(v == value() ? NO_CHANGE : UPDATE);
}
@@ -114,8 +130,7 @@
KstScalar& KstScalar::operator=(double v) {
- _value = v;
- emit trigger();
+ setValue(v);
return *this;
}
@@ -130,9 +145,12 @@
void KstScalar::setValue(double inV) {
- setDirty();
- _value = inV;
- emit trigger();
+ if (_value != inV) {
+ setDirty();
+ dirtyScalars = true;
+ _value = inV;
+ emit trigger();
+ }
}
--- branches/work/kst/viewupdates/kst/src/libkst/kstscalar.h #545933:545934
@@ -38,6 +38,11 @@
KstScalar(const QDomElement& e);
virtual ~KstScalar();
+ /* return true if any scalars are dirty at the moment */
+ static bool scalarsDirty();
+ /* For use by the update thread */
+ static void clearScalarsDirty();
+
/* return a string representation of the scalar */
QString label() const;
--- branches/work/kst/viewupdates/kst/src/libkstapp/kstdoc.cpp #545933:545934
@@ -65,6 +65,7 @@
#include "kstrmatrix.h"
#include "kstamatrix.h"
#include "kstsmatrix.h"
+#include "kstviewlabel.h"
#include "kstviewwindow.h"
#include "logevents.h"
#include "threadevents.h"
@@ -1083,6 +1084,11 @@
break;
}
}
+
+ KstViewLabelList vl = view->view()->findChildrenType<KstViewLabel>(true);
+ for (KstViewLabelList::Iterator i = vl.begin(); i != vl.end(); ++i) {
+ (*i)->update(-1);
+ }
}
it->next();
}
--- branches/work/kst/viewupdates/kst/src/libkstapp/kstviewlabel.h #545933:545934
@@ -149,6 +149,7 @@
};
typedef KstSharedPtr<KstViewLabel> KstViewLabelPtr;
+typedef KstObjectList<KstSharedPtr<KstViewLabel> > KstViewLabelList;
#endif
// vim: ts=2 sw=2 et
--- branches/work/kst/viewupdates/kst/src/libkstapp/updatethread.cpp #545933:545934
@@ -229,6 +229,29 @@
KST::dataSourceList.lock().readUnlock();
}
+ if (KstScalar::scalarsDirty()) {
+ KstScalar::clearScalarsDirty(); // Must do this first and take a risk of
+ // falling slightly behind
+ KST::scalarList.lock().readLock();
+ for (KstScalarList::ConstIterator i = KST::scalarList.begin(); i != KST::scalarList.end(); ++i) {
+ KstScalarPtr sp = *i;
+
+ sp->writeLock();
+ KstObject::UpdateType ut = sp->update(_updateCounter);
+ sp->writeUnlock();
+
+ if (ut == KstObject::UPDATE) {
+ U = KstObject::UPDATE;
+ }
+
+ if (_done) {
+ KST::scalarList.lock().readUnlock();
+ return false;
+ }
+ }
+ KST::scalarList.lock().readUnlock();
+ }
+
if (U == KstObject::UPDATE) {
kstdDebug() << "Update plots" << endl;
if (gotData) { // FIXME: do we need to consider all the other exit points?
More information about the Kst
mailing list