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

Mike Fenton mike at staikos.net
Wed Jul 9 16:20:40 CEST 2008


SVN commit 830013 by fenton:

Add tracking of displayed relations to LegendItem.


 M  +5 -0      legenditem.h  
 M  +15 -17    legenditemdialog.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/legenditem.h #830012:830013
@@ -14,6 +14,7 @@
 
 #include "viewitem.h"
 #include "graphicsfactory.h"
+#include "relation.h"
 
 namespace Label {
   struct Parsed;
@@ -49,6 +50,9 @@
 
     PlotItem* plot() { return _plotItem; }
 
+    RelationList relations() { return _relations; }
+    void setRelations(RelationList relations) { _relations = relations; }
+
   public Q_SLOTS:
     virtual void edit();
 
@@ -59,6 +63,7 @@
     QFont _font;
     qreal _fontScale;
     bool _verticalDisplay;
+    RelationList _relations;
 };
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/legenditemdialog.cpp #830012:830013
@@ -59,9 +59,16 @@
   CurveList curves = _store->getObjects<Curve>();
   ImageList images = _store->getObjects<Image>();
 
-  foreach (RelationPtr relation, _legendItem->plot()->renderItem(PlotRenderItem::Cartesian)->relationList()) {
-    displayedRelations.append(relation->Name());
-    displayedRelationTips.append(relation->descriptionTip());
+  if (_legendItem->relations().isEmpty()) {
+    foreach (RelationPtr relation, _legendItem->plot()->renderItem(PlotRenderItem::Cartesian)->relationList()) {
+      displayedRelations.append(relation->Name());
+      displayedRelationTips.append(relation->descriptionTip());
+    }
+  } else {
+    foreach (RelationPtr relation, _legendItem->relations()) {
+      displayedRelations.append(relation->Name());
+      displayedRelationTips.append(relation->descriptionTip());
+    }
   }
 
   foreach (CurvePtr curve, curves) {
@@ -101,25 +108,16 @@
   _legendItem->setAutoContents(_legendTab->autoContents());
   _legendItem->setVerticalDisplay(_legendTab->verticalDisplay());
 
-  QStringList currentRelations;
   QStringList displayedRelations = _legendTab->displayedRelations();
 
-  foreach (RelationPtr relation, _legendItem->plot()->renderItem(PlotRenderItem::Cartesian)->relationList()) {
-    currentRelations.append(relation->Name());
-    if (!displayedRelations.contains(relation->Name())) {
-      _legendItem->plot()->renderItem(PlotRenderItem::Cartesian)->removeRelation(relation);
-      _legendItem->plot()->update();
-    }
-  }
-
+  RelationList newRelations;
   foreach (QString relationName, displayedRelations) {
-    if (!currentRelations.contains(relationName)) {
-      if (RelationPtr relation = kst_cast<Relation>(_store->retrieveObject(relationName))) {
-        _legendItem->plot()->renderItem(PlotRenderItem::Cartesian)->addRelation(relation);
-        _legendItem->plot()->update();
-      }
+    qDebug() << "adding" << relationName;
+    if (RelationPtr relation = kst_cast<Relation>(_store->retrieveObject(relationName))) {
+      newRelations.append(relation);
     }
   }
+  _legendItem->setRelations(newRelations);
 }
 
 }


More information about the Kst mailing list