From 14fef9152c1e1a8a396db01289580c1255e395e0 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Thu, 4 Jun 2009 11:58:48 +0200 Subject: [PATCH] ResourcesBrowser: improved item filtering Filter line-edit is now placed above actual tree view and has been decorated with a small icon as well as a status label, displaying the number of filtered and total number of items. Signed-off-by: Tobias Doerffel --- data/themes/default/edit-find.png | Bin 0 -> 942 bytes include/resources_browser.h | 4 ++++ include/resources_item.h | 5 +++++ include/resources_tree_model.h | 3 +++ src/core/resources_tree_model.cpp | 36 ++++++++++++++++++++++++++++++ src/gui/resources_browser.cpp | 35 +++++++++++++++++++++++++---- 6 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 data/themes/default/edit-find.png diff --git a/data/themes/default/edit-find.png b/data/themes/default/edit-find.png new file mode 100644 index 0000000000000000000000000000000000000000..1b7a252803dd641279df3e3644458dfd6236afea GIT binary patch literal 942 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H3?x5i&EW)6%*9TgAsieWw;%dH0CG7CJR*yM z%CCbkqm#z$3ZS55iEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$QVa}?O9FgC zT>t<74^)o{^z`)f_4UQX#H6I81Ox;y6+lFUgoN1H*#!j!S;2srnHfkkGBU!|17(41 zCMG7JxB?ge)c{3AL_~mw14&U)Q9eFCYinyA9UXHpu(!82G&FQ}b`A*%DJ?Ap8Xg=R z6dDq2V`kLd-RSSjPM}?~qWp4la`Hl4K)s5Jib_gK$^r~3QetXqYPvFly1Kds>WXFxd=?fK zc6N4-j*c!0%U$yCFn9H*sG>^ z7^Ed7rU$uZCMV>WFy`my7lgT$xGR=hFjcsSR#a3}$2!+I^46pV)YsQHH#fJowsv-Q zc6D|2_4Q3iFqtr6!sN-5XC+zAO14^3p4n_7CO&R(@<-PWx;b{;r*{OsAY=Pz8ke&_znS06ro{rdg; zkDot({`&p<&!4}4|Neu5#9LdY08@aLr;B4q#jULqe1i@dFt}Y-$yHq9p&P()s^Rep z>6<%>j6Je_FSw5#w+*J9U$hD`;NseM zwr8a(R@OxN$NqiSD(}y#mh$M!(tK@UCS$jM0`)!|2bav(mKN*26Ro{|Q;}6_%kSb4 zUF&H+Ezj-QSBEYvJMC(`n?FG(V(S5)mg0$LoDXhLj1^SoOuLv-vzh19+00_0zGK_p wPh=~}x@si1{vex^?&HbFf0{ks_A>q>tI>mI%Ql^-pq$Cz>FVdQ&MBb@0Ez8GlK=n! literal 0 HcmV?d00001 diff --git a/include/resources_browser.h b/include/resources_browser.h index e63109832..8f8c22e7f 100644 --- a/include/resources_browser.h +++ b/include/resources_browser.h @@ -29,6 +29,7 @@ #include "side_bar_widget.h" class QAction; +class QLabel; class ResourcesItem; class ResourcesTreeModel; class ResourcesTreeView; @@ -58,6 +59,7 @@ public: private slots: void showContextMenu( const QPoint & _pos ); + void updateFilterStatus(); private: @@ -68,6 +70,8 @@ private: ResourcesTreeModel * m_treeModel; ResourcesTreeView * m_treeView; + QLabel * m_filterStatusLabel; + } ; diff --git a/include/resources_item.h b/include/resources_item.h index c92a82f81..88a7abc32 100644 --- a/include/resources_item.h +++ b/include/resources_item.h @@ -159,6 +159,11 @@ public: return m_treeItem; } + const ResourcesTreeItem * treeItem( void ) const + { + return m_treeItem; + } + const QDateTime & lastMod( void ) const { return m_lastMod; diff --git a/include/resources_tree_model.h b/include/resources_tree_model.h index 5ecabff33..74b34d7e6 100644 --- a/include/resources_tree_model.h +++ b/include/resources_tree_model.h @@ -75,6 +75,9 @@ public: return treeItem( _idx )->item(); } + int totalItems() const; + int shownItems() const; + private: bool filterItems( ResourcesTreeItem * _item, diff --git a/src/core/resources_tree_model.cpp b/src/core/resources_tree_model.cpp index 0ac1381e5..8a76c6da1 100644 --- a/src/core/resources_tree_model.cpp +++ b/src/core/resources_tree_model.cpp @@ -195,6 +195,42 @@ void ResourcesTreeModel::setFilter( const QString & _s ) +int ResourcesTreeModel::totalItems() const +{ + const ResourcesDB::ItemList & items = m_db->items(); + int num = 0; + foreach( const ResourcesItem * i, items ) + { + if( i->type() != ResourcesItem::TypeDirectory ) + { + ++num; + } + } + return num; +} + + + + +int ResourcesTreeModel::shownItems() const +{ + const ResourcesDB::ItemList & items = m_db->items(); + int num = 0; + foreach( const ResourcesItem * i, items ) + { + if( i->type() != ResourcesItem::TypeDirectory && + i->treeItem()->isHidden() == false ) + { + ++num; + } + } + return num; +} + + + + + bool ResourcesTreeModel::filterItems( ResourcesTreeItem * _item, const QModelIndex & _parent, const QStringList & _keywords ) diff --git a/src/gui/resources_browser.cpp b/src/gui/resources_browser.cpp index db3b9f7ba..6846aa25d 100644 --- a/src/gui/resources_browser.cpp +++ b/src/gui/resources_browser.cpp @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -75,25 +76,41 @@ ResourcesBrowser::ResourcesBrowser( QWidget * _parent ) : m_treeModel = new ResourcesTreeModel( engine::getResourcesProvider()->database() ); + // create filter UI + QHBoxLayout * filterLayout = new QHBoxLayout; + + QLabel * filterPixmap = new QLabel; + filterPixmap->setPixmap( embed::getIconPixmap( "edit-find" ) ); + + QLineEdit * filterEdit = new QLineEdit; + + m_filterStatusLabel = new QLabel; + + filterLayout->addWidget( filterPixmap ); + filterLayout->addWidget( filterEdit ); + filterLayout->addWidget( m_filterStatusLabel ); + // create an according tree-view for our tree-model m_treeView = new ResourcesTreeView( m_treeModel, contentParent() ); - QLineEdit * filterEdit = new QLineEdit ( contentParent() ); - // set up context menu handling m_treeView->setContextMenuPolicy( Qt::CustomContextMenu ); connect( m_treeView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) ); - // add widgets to us (we're a SideBarWidget) + // add widgets/layouts to us (we're a SideBarWidget) + addContentLayout( filterLayout ); addContentWidget( m_treeView ); - addContentWidget( filterEdit ); // instantly apply filter when typing into filterEdit connect( filterEdit, SIGNAL( textChanged( const QString & ) ), m_treeView, SLOT( setFilter( const QString & ) ) ); + connect( filterEdit, SIGNAL( textChanged( const QString & ) ), + this, SLOT( updateFilterStatus() ) ); + connect( m_treeModel, SIGNAL( itemsChanged() ), + this, SLOT( updateFilterStatus() ) ); // setup actions to be used in context menu for( int i = 0;i < (int) ( sizeof( resourcesBrowserActions ) / @@ -189,6 +206,16 @@ void ResourcesBrowser::showContextMenu( const QPoint & _pos ) +void ResourcesBrowser::updateFilterStatus() +{ + m_filterStatusLabel->setText( QString( "%1/%2" ). + arg( m_treeModel->shownItems() ). + arg( m_treeModel->totalItems() ) ); +} + + + + void ResourcesBrowser::triggerAction( Actions _action, ResourcesItem * _item ) { // TODO