[vlc-commits] Qt: Preferences tree filter
Yuval Tze
git at videolan.org
Fri Jul 29 13:06:16 CEST 2011
vlc | branch: master | Yuval Tze <yuvaltze at gmail.com> | Tue Jul 26 21:52:43 2011 +0300| [9b80d194855abc15cbbd4f4468805a7e325f458e] | committer: Francois Cartegnie
Qt: Preferences tree filter
add filter function to expand and show matched tree items and hide the rest
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9b80d194855abc15cbbd4f4468805a7e325f458e
---
.../gui/qt4/components/complete_preferences.cpp | 69 ++++++++++++++++++++
.../gui/qt4/components/complete_preferences.hpp | 3 +
2 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/modules/gui/qt4/components/complete_preferences.cpp b/modules/gui/qt4/components/complete_preferences.cpp
index 94866d2..798b4bb 100644
--- a/modules/gui/qt4/components/complete_preferences.cpp
+++ b/modules/gui/qt4/components/complete_preferences.cpp
@@ -343,6 +343,75 @@ void PrefsTree::doAll( bool doclean )
}
}
+/* apply filter on tree item and recursively on its sub items
+ * returns whether the item was filtered */
+bool PrefsTree::filterItems( QTreeWidgetItem *item, const QString &text,
+ Qt::CaseSensitivity cs )
+{
+ bool sub_filtered = true;
+
+ for( int i = 0; i < item->childCount(); i++ )
+ {
+ QTreeWidgetItem *sub_item = item->child( i );
+ if ( !filterItems( sub_item, text, cs ) )
+ {
+ /* not all the sub items were filtered */
+ sub_filtered = false;
+ }
+ }
+
+ PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData *>();
+
+ bool filtered = sub_filtered && !data->contains( text, cs );
+ item->setExpanded( !sub_filtered );
+ item->setHidden( filtered );
+
+ return filtered;
+}
+
+
+/* collapse item if it's not selected or one of its sub items
+ * returns whether the item was collapsed */
+bool PrefsTree::collapseUnselectedItems( QTreeWidgetItem *item )
+{
+ bool sub_collapsed = true;
+
+ for( int i = 0; i < item->childCount(); i++ )
+ {
+ QTreeWidgetItem *sub_item = item->child( i );
+ if ( !collapseUnselectedItems( sub_item ) )
+ {
+ /* not all the sub items were collapsed */
+ sub_collapsed = false;
+ }
+ }
+
+ bool collapsed = sub_collapsed && !item->isSelected();
+ item->setExpanded( !sub_collapsed );
+ item->setHidden( false );
+
+ return collapsed;
+}
+
+/* apply filter on tree */
+void PrefsTree::filter( const QString &text )
+{
+ bool clear_filter = text.isEmpty();
+
+ for( int i = 0 ; i < topLevelItemCount(); i++ )
+ {
+ QTreeWidgetItem *cat_item = topLevelItem( i );
+ if ( clear_filter )
+ {
+ collapseUnselectedItems( cat_item );
+ }
+ else
+ {
+ filterItems( cat_item, text, Qt::CaseInsensitive );
+ }
+ }
+}
+
/* go over the module config items and search text in psz_text
* also search the module name and head */
bool PrefsItemData::contains( const QString &text, Qt::CaseSensitivity cs )
diff --git a/modules/gui/qt4/components/complete_preferences.hpp b/modules/gui/qt4/components/complete_preferences.hpp
index f58b50f..2c24cd6 100644
--- a/modules/gui/qt4/components/complete_preferences.hpp
+++ b/modules/gui/qt4/components/complete_preferences.hpp
@@ -72,9 +72,12 @@ public:
void applyAll();
void cleanAll();
+ void filter( const QString &text );
private:
void doAll( bool );
+ bool filterItems( QTreeWidgetItem *item, const QString &text, Qt::CaseSensitivity cs );
+ bool collapseUnselectedItems( QTreeWidgetItem *item );
intf_thread_t *p_intf;
};
More information about the vlc-commits
mailing list