From 8db8e42ec43570916422be91d9bb739f134db5c1 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 5 Jul 2012 12:41:06 +0200 Subject: [PATCH] * Filter tree-model based on query, not result. --- src/libtomahawk/playlist/TreeProxyModel.cpp | 41 ++++++++++++--------- src/libtomahawk/playlist/TreeProxyModel.h | 2 +- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/libtomahawk/playlist/TreeProxyModel.cpp b/src/libtomahawk/playlist/TreeProxyModel.cpp index e5ed82325..ab21647d2 100644 --- a/src/libtomahawk/playlist/TreeProxyModel.cpp +++ b/src/libtomahawk/playlist/TreeProxyModel.cpp @@ -190,18 +190,18 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent PlayableItem* item = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) ); Q_ASSERT( item ); - if ( m_model->mode() == Tomahawk::DatabaseMode && !item->result().isNull() ) + if ( m_model->mode() == Tomahawk::DatabaseMode && !item->query().isNull() ) { - QList< Tomahawk::result_ptr > rl = m_cache.values( sourceParent ); - foreach ( const Tomahawk::result_ptr& cachedResult, rl ) + QList< Tomahawk::query_ptr > rl = m_cache.values( sourceParent ); + foreach ( const Tomahawk::query_ptr& cachedQuery, rl ) { - if ( cachedResult.isNull() ) + if ( cachedQuery.isNull() ) continue; - if ( cachedResult->track() == item->result()->track() && - ( cachedResult->albumpos() == item->result()->albumpos() || cachedResult->albumpos() == 0 ) ) + if ( cachedQuery->track() == item->query()->track() && + ( cachedQuery->albumpos() == item->query()->albumpos() || cachedQuery->albumpos() == 0 ) ) { - return ( cachedResult.data() == item->result().data() ); + return ( cachedQuery.data() == item->query().data() ); } } @@ -212,17 +212,24 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent PlayableItem* ti = sourceModel()->itemFromIndex( sourceModel()->index( i, 0, sourceParent ) ); - if ( ti->name() == item->name() && - ( ti->result()->albumpos() == item->result()->albumpos() || - ti->result()->albumpos() == 0 || item->result()->albumpos() == 0 ) ) + if ( ti && ti->name() == item->name() ) { - if ( !item->result()->isOnline() && ti->result()->isOnline() ) - return false; - - if ( ( item->result()->collection().isNull() || !item->result()->collection()->source()->isLocal() ) && - !ti->result()->collection().isNull() && ti->result()->collection()->source()->isLocal() ) + if ( ti->query()->albumpos() == item->query()->albumpos() || ti->query()->albumpos() == 0 || item->query()->albumpos() == 0 ) { - return false; + if ( item->result().isNull() ) + return false; + + if ( !ti->result().isNull() ) + { + if ( !item->result()->isOnline() && ti->result()->isOnline() ) + return false; + + if ( ( item->result()->collection().isNull() || !item->result()->collection()->source()->isLocal() ) && + !ti->result()->collection().isNull() && ti->result()->collection()->source()->isLocal() ) + { + return false; + } + } } } } @@ -250,7 +257,7 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent } } - m_cache.insertMulti( sourceParent, item->result() ); + m_cache.insertMulti( sourceParent, item->query() ); return true; } diff --git a/src/libtomahawk/playlist/TreeProxyModel.h b/src/libtomahawk/playlist/TreeProxyModel.h index bca8676b0..6477a3c02 100644 --- a/src/libtomahawk/playlist/TreeProxyModel.h +++ b/src/libtomahawk/playlist/TreeProxyModel.h @@ -65,7 +65,7 @@ private: void filterFinished(); QString textForItem( PlayableItem* item ) const; - mutable QMap< QPersistentModelIndex, Tomahawk::result_ptr > m_cache; + mutable QMap< QPersistentModelIndex, Tomahawk::query_ptr > m_cache; QList m_artistsFilter; QList m_albumsFilter;