[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: klistviewsearchline
From: Daniel Teske <teske () squorn ! de>
Date: 2005-07-06 21:05:53
Message-ID: 200507062305.53302.teske () squorn ! de
[Download RAW message or body]
Hi
This patch fixes bug: http://bugs.kde.org/show_bug.cgi?id=91476
That's the same bug, my last patch was about. This patch is significantly rewritten.
Thanks to Richard's work, it's a lot more readable and even more efficient.
It now should be the minimal number of itemMatches() call and is correct.
He refactored my code and we had a good discussion about the code.
If noone objects, I'll commit this code.
daniel
["klistviewsearchline5.patch" (text/x-diff)]
Index: klistviewsearchline.cpp
===================================================================
--- klistviewsearchline.cpp (revision 431553)
+++ klistviewsearchline.cpp (working copy)
@@ -353,15 +353,48 @@
}
}
-bool KListViewSearchLine::checkItemParentsVisible(QListViewItem *item)
+#include <kdebug.h>
+
+/** Check whether \p item, its siblings and their descendents should be shown. Show \
or hide the items as necessary. + *
+ * \p item The list view item to start showing / hiding items at. Typically, this \
is the first child of another item, or the + * the first child of the \
list view. + * \p highestHiddenParent The highest (closest to root) ancestor of \p \
item which is hidden. If 0, all parents of + * \p item must \
be visible. + * \return \c true if an item which should be visible is found, \c \
false if all items found should be hidden. If this function + * returns \
true and \p highestHiddenParent was not 0, highestHiddenParent will have been shown. \
+ */ +bool KListViewSearchLine::checkItemParentsVisible(QListViewItem *item, \
QListViewItem *highestHiddenParent) {
bool visible = false;
- for(; item; item = item->nextSibling()) {
- if((item->firstChild() && checkItemParentsVisible(item->firstChild())) ||
- itemMatches(item, d->search))
+ QListViewItem * first = item;
+ for(; item; item = item->nextSibling())
+ {
+ //What we pass to our children as highestHiddenParent:
+ QListViewItem * hhp = highestHiddenParent ? highestHiddenParent : \
item->isVisible() ? 0L : item; + bool childMatch = false;
+ if(item->firstChild() && checkItemParentsVisible(item->firstChild(), hhp))
+ childMatch = true;
+ // Should this item be shown? It should if any children should be, or if it \
matches. + if(childMatch || itemMatches(item, d->search))
{
- item->setVisible( true );
visible = true;
+ if (highestHiddenParent)
+ {
+ highestHiddenParent->setVisible(true);
+ // Calling setVisible on our ancestor will unhide all its \
descendents. Hide the ones + // before us that should not be shown.
+ for(QListViewItem *hide = first; hide != item; hide = \
hide->nextSibling()) + hide->setVisible(false);
+ highestHiddenParent = 0;
+ // If we matched, than none of our children matched, yet the \
setVisible() call on our + // ancestor unhid them, undo the damage:
+ if(!childMatch)
+ for(QListViewItem *hide = item->firstChild(); hide; hide = \
hide->nextSibling()) + hide->setVisible(false);
+ }
+ else
+ item->setVisible(true);
}
else
item->setVisible(false);
Index: klistviewsearchline.h
===================================================================
--- klistviewsearchline.h (revision 431553)
+++ klistviewsearchline.h (working copy)
@@ -190,7 +190,7 @@
* It makes a recursive call to all children. It returns true if at least
* one item in the subtree with the given root item is visible.
*/
- bool checkItemParentsVisible(QListViewItem *item);
+ bool checkItemParentsVisible(QListViewItem *item, QListViewItem \
*highestHiddenParent = 0);
private slots:
void itemAdded(QListViewItem *item) const;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic