[Kst] extragear/graphics/kst/kst
Rick Chern
rchern at interchange.ubc.ca
Tue Jun 28 02:57:40 CEST 2005
SVN commit 429540 by rchern:
Support for equations in dependency duplication
M +61 -6 kstequation.cpp
M +6 -2 kstequation.h
--- trunk/extragear/graphics/kst/kst/kstequation.cpp #429539:429540
@@ -436,12 +436,6 @@
}
-bool KstEquation::uses(KstObjectPtr p) const {
- // Inefficient to call values().contains()
- return KstDataObject::uses(p) || VectorsUsed.values().contains(kst_cast<KstVector>(p)) || _inputScalars.values().contains(kst_cast<KstScalar>(p));
-}
-
-
KstDataObjectPtr KstEquation::makeDuplicate(QMap<KstDataObjectPtr, KstDataObjectPtr> &duplicatedMap) {
KstEquationPtr eq = new KstEquation(tagName() + "'", _equation, _inputVectors[XVECTOR], _doInterp);
duplicatedMap.insert(this, KstDataObjectPtr(eq));
@@ -449,4 +443,65 @@
}
+void KstEquation::replaceDependency(KstDataObjectPtr oldObject, KstDataObjectPtr newObject) {
+
+ QString newExp = _equation;
+
+ // replace all occurences of outputVectors, outputScalars, and outputStrings from oldObject
+ for (KstVectorMap::Iterator j = oldObject->outputVectors().begin(); j != oldObject->outputVectors().end(); ++j) {
+ QString oldTag = j.data()->tagName();
+ QString newTag = ((newObject->outputVectors())[j.key()])->tagName();
+ newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]");
+ }
+
+ for (KstScalarMap::Iterator j = oldObject->outputScalars().begin(); j != oldObject->outputScalars().end(); ++j) {
+ QString oldTag = j.data()->tagName();
+ QString newTag = ((newObject->outputScalars())[j.key()])->tagName();
+ newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]");
+ }
+
+ setEquation(newExp);
+
+ // do the other dependency replacements
+ KstDataObject::replaceDependency(oldObject, newObject);
+}
+
+
+void KstEquation::replaceDependency(KstVectorPtr oldVector, KstVectorPtr newVector) {
+ QString oldTag = oldVector->tagName();
+ QString newTag = newVector->tagName();
+
+ // replace all occurences of oldTag with newTag
+ QString newExp = _equation.replace("["+oldTag+"]", "["+newTag+"]");
+ setEquation(newExp);
+
+ // do the other dependency replacements
+ KstDataObject::replaceDependency(oldVector, newVector);
+}
+
+
+bool KstEquation::uses(KstObjectPtr p) const {
+
+ // check VectorsUsed in addition to _input*'s
+
+ if (KstVectorPtr vect = kst_cast<KstVector>(p)) {
+ for (KstVectorMap::ConstIterator j = VectorsUsed.begin(); j != VectorsUsed.end(); ++j) {
+ if (j.data() == vect) {
+ return true;
+ }
+ }
+ } else if (KstDataObjectPtr obj = kst_cast<KstDataObject>(p) ) {
+ // check all connections from this expression to p
+ for (KstVectorMap::Iterator j = obj->outputVectors().begin(); j != obj->outputVectors().end(); ++j) {
+ for (KstVectorMap::ConstIterator k = VectorsUsed.begin(); k != VectorsUsed.end(); ++k) {
+ if (j.data() == k.data()) {
+ return true;
+ }
+ }
+ }
+ }
+ return KstDataObject::uses(p);
+}
+
+
// vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstequation.h #429539:429540
@@ -60,12 +60,16 @@
virtual QString xVTag() const { return (*_xVector)->tagName(); }
virtual QString yVTag() const { return (*_yVector)->tagName(); }
- virtual bool uses(KstObjectPtr p) const;
-
const KstCurveHintList *curveHints() const;
virtual KstDataObjectPtr makeDuplicate(QMap<KstDataObjectPtr, KstDataObjectPtr> &duplicatedMap);
+
+ virtual void replaceDependency(KstDataObjectPtr oldObject, KstDataObjectPtr newObject);
+ virtual void replaceDependency(KstVectorPtr oldVector, KstVectorPtr newVector);
+
+ virtual bool uses(KstObjectPtr p) const;
+
private:
QString _equation;
More information about the Kst
mailing list