ResourceDB: new method matchItems(), renamed ItemList to ItemHashMap
Added new method ResourceDB::matchItems() which returns a list of item which somehow match the given list of keywords. Furthermore renamed ItemList to ItemHashMap to better reflect actual container type. Additionally some coding style improvements. Signed-off-by: Tobias Doerffel <tobias.doerffel@gmail.com>
This commit is contained in:
@@ -190,7 +190,7 @@ loadTreeItem( treeItem, e );
|
||||
|
||||
const ResourceItem * ResourceDB::itemByHash( const QString & _hash ) const
|
||||
{
|
||||
ItemList::ConstIterator it = m_items.find( _hash );
|
||||
ItemHashMap::ConstIterator it = m_items.find( _hash );
|
||||
if( it != m_items.end() )
|
||||
{
|
||||
return it.value();
|
||||
@@ -201,11 +201,48 @@ const ResourceItem * ResourceDB::itemByHash( const QString & _hash ) const
|
||||
|
||||
|
||||
|
||||
ResourceItemList ResourceDB::matchItems( const QStringList & _keyWords )
|
||||
{
|
||||
ResourceItemList matchingItems;
|
||||
|
||||
// iterate over all items in our DB
|
||||
for( ItemHashMap::ConstIterator it = m_items.begin();
|
||||
it != m_items.end(); ++it )
|
||||
{
|
||||
const ResourceItem * item = *it;
|
||||
// build up a string containing all searchable strings of item
|
||||
const QString itemString =
|
||||
QString( item->name() +
|
||||
item->path() +
|
||||
item->author() +
|
||||
item->tags() ).toLower();
|
||||
bool accept = true;
|
||||
for( QStringList::ConstIterator jt = _keyWords.begin();
|
||||
jt != _keyWords.end(); ++jt )
|
||||
{
|
||||
if( !itemString.contains( *jt ) )
|
||||
{
|
||||
accept = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( accept )
|
||||
{
|
||||
matchingItems << *it;
|
||||
}
|
||||
}
|
||||
|
||||
return matchingItems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const ResourceItem * ResourceDB::nearestMatch( const ResourceItem & _item )
|
||||
{
|
||||
if( !_item.hash().isEmpty() )
|
||||
{
|
||||
ItemList::ConstIterator it = m_items.find( _item.hash() );
|
||||
ItemHashMap::ConstIterator it = m_items.find( _item.hash() );
|
||||
if( it != m_items.end() )
|
||||
{
|
||||
return it.value();
|
||||
|
||||
@@ -251,7 +251,7 @@ void ResourceTreeModel::setFilter( const QString & _s )
|
||||
|
||||
int ResourceTreeModel::totalItems() const
|
||||
{
|
||||
const ResourceDB::ItemList & items = m_db->items();
|
||||
const ResourceDB::ItemHashMap & items = m_db->items();
|
||||
int num = 0;
|
||||
foreach( const ResourceItem * i, items )
|
||||
{
|
||||
@@ -268,7 +268,7 @@ int ResourceTreeModel::totalItems() const
|
||||
|
||||
int ResourceTreeModel::shownItems() const
|
||||
{
|
||||
const ResourceDB::ItemList & items = m_db->items();
|
||||
const ResourceDB::ItemHashMap & items = m_db->items();
|
||||
int num = 0;
|
||||
foreach( const ResourceItem * i, items )
|
||||
{
|
||||
|
||||
@@ -89,11 +89,11 @@ void UnifiedResourceProvider::remergeItems( void )
|
||||
const ResourceItem *> PointerHashMap;
|
||||
PointerHashMap itemsSeen;
|
||||
|
||||
ResourceDB::ItemList & items = database()->items();
|
||||
ResourceDB::ItemHashMap & items = database()->items();
|
||||
|
||||
itemsSeen.reserve( items.size() );
|
||||
|
||||
for( ResourceDB::ItemList::Iterator it = items.begin();
|
||||
for( ResourceDB::ItemHashMap::Iterator it = items.begin();
|
||||
it != items.end(); ++it )
|
||||
{
|
||||
itemsSeen[*it] = *it;
|
||||
@@ -101,7 +101,7 @@ void UnifiedResourceProvider::remergeItems( void )
|
||||
|
||||
foreach( ResourceDB * db, m_mergedDatabases )
|
||||
{
|
||||
for( ResourceDB::ItemList::ConstIterator it =
|
||||
for( ResourceDB::ItemHashMap::ConstIterator it =
|
||||
db->items().begin();
|
||||
it != db->items().end(); ++it )
|
||||
{
|
||||
@@ -117,7 +117,7 @@ void UnifiedResourceProvider::remergeItems( void )
|
||||
}
|
||||
}
|
||||
|
||||
for( ResourceDB::ItemList::Iterator it = items.begin();
|
||||
for( ResourceDB::ItemHashMap::Iterator it = items.begin();
|
||||
it != items.end(); )
|
||||
{
|
||||
if( itemsSeen[*it] == *it )
|
||||
|
||||
Reference in New Issue
Block a user