Summary: | View Scalar Values dialog not useful | ||
---|---|---|---|
Product: | [Applications] kst | Reporter: | Andrew Walker <arwalker> |
Component: | general | Assignee: | kst |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | NOR | ||
Version: | 1.x | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: |
Proposed patch
Proposed patch |
Description
Andrew Walker
2007-02-14 23:56:01 UTC
Created attachment 20005 [details]
Proposed patch
Makes the view scalar values dialog useful even when data is updating
There are several problems with this patch including the use of unguarded dynamic casts. I would like to postpone this until 1.4.1 at least and will provide more comments then. -- George Staikos KDE Developer http://www.kde.org/ Staikos Computing Services Inc. http://www.staikos.net/ At present this dialog is annoying to useless. Why would we ship with it in that condition? Created attachment 20126 [details]
Proposed patch
Check that all dynamic_cast's are valid
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 |