From 38155d95c47f2b21f99971c119e9f0bf29b6a4d3 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 17 Aug 2009 22:03:34 +0200 Subject: [PATCH] ResourceTreeModel: moved keyword matching code into ResourceItem class Place functionality to where it belongs. ResourceItem::matchKeywords() now returns whether a given list of strings matches with various string properties of the item. --- include/ResourceItem.h | 4 ++++ src/core/ResourceItem.cpp | 19 +++++++++++++++++++ src/core/ResourceTreeModel.cpp | 18 ++---------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/ResourceItem.h b/include/ResourceItem.h index d2fdc2cc4..f2b645b00 100644 --- a/include/ResourceItem.h +++ b/include/ResourceItem.h @@ -212,6 +212,10 @@ public: void reload(); + // returns true if all given keywords match name, tags etc. + bool keywordMatch( const QStringList & _keywords ); + + // return true, if given ResourceItem is equal bool operator==( const ResourceItem & _other ) const; // rates equality with given item diff --git a/src/core/ResourceItem.cpp b/src/core/ResourceItem.cpp index 3962a309f..7e871aa83 100644 --- a/src/core/ResourceItem.cpp +++ b/src/core/ResourceItem.cpp @@ -94,6 +94,25 @@ void ResourceItem::reload() +bool ResourceItem::keywordMatch( const QStringList & _keywords ) +{ + for( QStringList::ConstIterator it = _keywords.begin(); + it != _keywords.end(); ++it ) + { + if( !( name().toLower().contains( *it ) || + path().toLower().contains( *it ) || + author().toLower().contains( *it ) || + tags().toLower().contains( *it ) ) ) + { + return false; + } + } + return true; +} + + + + bool ResourceItem::operator==( const ResourceItem & _other ) const { return m_nameHash == _other.m_nameHash && diff --git a/src/core/ResourceTreeModel.cpp b/src/core/ResourceTreeModel.cpp index 4945096f5..564f1b2aa 100644 --- a/src/core/ResourceTreeModel.cpp +++ b/src/core/ResourceTreeModel.cpp @@ -124,21 +124,7 @@ bool ResourceTreeModel::filterItems( ResourceItem::Relation * _item, { if( _item->item() ) { - ResourceItem * i = _item->item(); - bool accept = true; - for( QStringList::ConstIterator it = _keywords.begin(); - it != _keywords.end(); ++it ) - { - if( !( i->name().toLower().contains( *it ) || - i->path().toLower().contains( *it ) || - i->author().toLower().contains( *it ) || - i->tags().toLower().contains( *it ) ) ) - { - accept = false; - break; - } - } - if( accept ) + if( _item->item()->keywordMatch( _keywords ) ) { setHidden( _item, _parent, false ); return true; @@ -150,7 +136,7 @@ bool ResourceTreeModel::filterItems( ResourceItem::Relation * _item, foreachResourceItemRelation( _item->children() ) { QModelIndex idx = createIndex( row, 0, *it ); - if( filterItems( *it, idx , _keywords ) ) + if( filterItems( *it, idx, _keywords ) ) { hide = false; }