[Kst] [Bug 141715] View Scalar Values dialog not useful

Andrew Walker arwalker at sumusltd.com
Thu Apr 12 20:08:28 CEST 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=141715         
arwalker sumusltd com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From arwalker sumusltd com  2007-04-12 20:08 -------
SVN commit 653146 by arwalker:

BUG:141715 Make the hierarchical view scalars dialog useful

 M  +86 -8     kstscalarlistview.cpp  
 M  +8 -0      kstscalarlistview.h  


--- branches/work/kst/1.5/kst/src/libkstapp/kstscalarlistview.cpp #653145:653146
 @ -41,6 +41,7  @
       setRenameEnabled(1, false);
     }
   }
+  _remove = false;
 }
 
 QString KstScalarListViewItem::text(int column) const {
 @ -78,6 +79,14  @
   }
 }
 
+bool KstScalarListViewItem::remove() const {
+  return _remove;
+}
+
+void KstScalarListViewItem::setRemove(bool remove) {
+  _remove = remove;
+}
+
 /*----------------------------------------------------------------------------*/
 
 KstScalarListView::KstScalarListView(QWidget *parent, KstObjectCollection<KstScalar> *coll) : KListView(parent), _coll(coll) {
 @ -90,29 +99,98  @
   update();
 }
 
-
-static void addChildItems(KstScalarListViewItem *parentItem, KstObjectTreeNode<KstScalar> *parentNode) {
+void KstScalarListView::addChildItems(KstScalarListViewItem *parentItem, KstObjectTreeNode<KstScalar> *parentNode) {
   if (!parentItem || !parentNode) {
     return;
   }
 
   QValueList<KstObjectTreeNode<KstScalar>*> children = parentNode->children().values();
   for (QValueList<KstObjectTreeNode<KstScalar>*>::ConstIterator i = children.begin(); i != children.end(); ++i) {
-    KstScalarListViewItem *item = new KstScalarListViewItem(parentItem, *i);
-    addChildItems(item, *i);
+    QListViewItem *item = parentItem->firstChild();
+    bool found = false;
+
+    while (item) {
+      if (item->text(0) == (*i)->nodeTag()) {
+        found = true;
+
+        KstScalarListViewItem *kItem = dynamic_cast<KstScalarListViewItem*>(item);
+        if (kItem) {
+          kItem->setRemove(false);
+          repaintItem(kItem);
+          addChildItems(kItem, *i);
+        }
+
+        break;
+      }
+      item = item->nextSibling();
+    }
+
+    if (!found) {
+      KstScalarListViewItem *item = new KstScalarListViewItem(parentItem, *i);
+      addChildItems(item, *i);
+    }
   }
 }
 
 void KstScalarListView::update() {
-  clear();
-
   if (_coll) {
     KstReadLocker(&_coll->lock());
+
+    {
+      QListViewItemIterator it(this);
+
+      while (it.current()) {
+        KstScalarListViewItem *kItem = dynamic_cast<KstScalarListViewItem*>(it.current());
+        if (kItem) {
+          kItem->setRemove(true);
+        }
+        ++it;
+      }
+    }
+
     QValueList<KstObjectTreeNode<KstScalar>*> rootItems = _coll->nameTreeRoot()->children().values();
     for (QValueList<KstObjectTreeNode<KstScalar>*>::ConstIterator i = rootItems.begin(); i != rootItems.end(); ++i) {
-      KstScalarListViewItem *item = new KstScalarListViewItem(this, *i);
-      addChildItems(item, *i);
+      QListViewItem *item = firstChild();
+      bool found = false;
+
+      while (item) {
+        if (item->text(0) == (*i)->nodeTag()) {
+          found = true;
+
+          KstScalarListViewItem *kItem = dynamic_cast<KstScalarListViewItem*>(item);
+          if (kItem) {
+            kItem->setRemove(false);
+            repaintItem(kItem);
+            addChildItems(kItem, *i);
+          }
+
+          break;
+        }
+        item = item->nextSibling();
+      }
+
+      if (!found) {
+        KstScalarListViewItem *item = new KstScalarListViewItem(this, *i);
+        addChildItems(item, *i);
+      }
     }
+
+    {
+      QListViewItemIterator it(this);
+
+      while (it.current()) {
+        KstScalarListViewItem *kItem = dynamic_cast<KstScalarListViewItem*>(it.current());
+        if (kItem) {
+          if (kItem->remove()) {
+            delete it.current();
+          } else {
+            ++it;
+          }
+        } else {
+          ++it;
+        }
+      }
+    }
   }
 
 /*
--- branches/work/kst/1.5/kst/src/libkstapp/kstscalarlistview.h #653145:653146
 @ -23,6 +23,8  @
 #include "kstobject.h"
 #include "kstobjectcollection.h"
 
+class KstScalarListViewItem;
+
 class KstScalarListView : public KListView
 {
   public:
 @ -31,6 +33,8  @
     void update();
 
   private:
+    void addChildItems(KstScalarListViewItem *parentItem, KstObjectTreeNode<KstScalar> *parentNode);
+    
     KstObjectCollection<KstScalar> *_coll;
 };
 
 @ -44,12 +48,16  @
     QString text(int column) const;
     void setText(int column, const QString& text);
 
+    bool remove() const;
+    void setRemove(bool remove);
+
     KstObjectTreeNode<KstScalar> *node() const { return _node; }
 
   private:
     void commonConstructor();
 
     QGuardedPtr<KstObjectTreeNode<KstScalar> > _node;
+    bool _remove;
 };
 
 #endif


More information about the Kst mailing list