[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-02 13:26:16
Message-ID: 200507021526.16726.teske () squorn ! de
[Download RAW message or body]

Hi

The attached patch fixes a bug.
Steps to reproduce:
Start keditbookmarks[1]
Type into the searchline until no item matches.
Delete the last char
Notice that all items are shown.

The problem is in the algorithm.
Assume the following structure:

f1
|->i1
|->i2

and the searchline text i1a.
=> No items are visible:
Backspace the last char
=> Searchline text is now i1

checkItemParentsVisible( f1 );
 checks if any children should be visible
 or it matches:
 
 checkItemParentsVisible( i1 );
   i1 matches now, setVisible is called
   and ignored by QT (because the parent is invisble)
   returns true

 checkItemParentsVisble( i2 );
   return false;

 As a children should be visible:
 setVisible(f1);
 => QT calls setVisible() for i1 and i2.

End:
i2 is visible, but doesn't match

The patch fixes it, by making all items visible and then hiding.
I could optimize it, to make less changes to the visibility.

Is this patch okay to commit?

daniel

[1] 
Any other listview with a klistview searchline is affected too, if it 
shows a tree and uses keepParentsVisible = true (the default).
Note: I recently changed keditbookmarks to use a derived version, but 
that doesn't change the bug.

["klistviewsearchline.patch" (text/x-diff)]

Index: klistviewsearchline.cpp
===================================================================
--- klistviewsearchline.cpp	(revision 429160)
+++ klistviewsearchline.cpp	(working copy)
@@ -152,7 +152,10 @@
     }
 
     if(d->keepParentsVisible)
+    {
+        showAllChildren(d->listView->firstChild());
         checkItemParentsVisible(d->listView->firstChild());
+    }
     else
         checkItemParentsNotVisible();
 
@@ -353,16 +356,25 @@
     }
 }
 
+void KListViewSearchLine::showAllChildren(QListViewItem *item)
+{
+    for(; item; item = item->nextSibling())
+    {
+        if(!item->isVisible())
+            item->setVisible(true);
+        else
+            if(item->firstChild())
+                showAllChildren(item->firstChild());
+    }
+}
+
 bool KListViewSearchLine::checkItemParentsVisible(QListViewItem *item)
 {
     bool visible = false;
     for(; item; item = item->nextSibling()) {
         if((item->firstChild() && checkItemParentsVisible(item->firstChild())) ||
            itemMatches(item, d->search))
-        {
-            item->setVisible( true );
             visible = true;
-        }
         else
             item->setVisible(false);
     }
Index: klistviewsearchline.h
===================================================================
--- klistviewsearchline.h	(revision 429160)
+++ klistviewsearchline.h	(working copy)
@@ -192,6 +192,11 @@
      */
     bool checkItemParentsVisible(QListViewItem *item);
 
+    /**
+     * Make all children visible
+     */
+    void showAllChildren(QListViewItem *item);
+
 private slots:
     void itemAdded(QListViewItem *item) const;
     void listViewDeleted();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic