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 <tobias.doerffel@gmail.com>
This commit is contained in:
Tobias Doerffel
2009-06-04 11:58:48 +02:00
parent 1ee8d38ca7
commit 14fef9152c
6 changed files with 79 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 B

View File

@@ -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;
} ;

View File

@@ -159,6 +159,11 @@ public:
return m_treeItem;
}
const ResourcesTreeItem * treeItem( void ) const
{
return m_treeItem;
}
const QDateTime & lastMod( void ) const
{
return m_lastMod;

View File

@@ -75,6 +75,9 @@ public:
return treeItem( _idx )->item();
}
int totalItems() const;
int shownItems() const;
private:
bool filterItems( ResourcesTreeItem * _item,

View File

@@ -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 )

View File

@@ -23,6 +23,7 @@
*/
#include <QtGui/QAction>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QMenu>
@@ -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