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.
This commit is contained in:
Tobias Doerffel
2009-08-17 22:03:34 +02:00
parent 0a9d3aba6f
commit 38155d95c4
3 changed files with 25 additions and 16 deletions

View File

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

View File

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