mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
* Filter tree-model based on query, not result.
This commit is contained in:
@@ -182,18 +182,18 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
|
|||||||
PlayableItem* item = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
|
PlayableItem* item = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
|
||||||
Q_ASSERT( item );
|
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 );
|
QList< Tomahawk::query_ptr > rl = m_cache.values( sourceParent );
|
||||||
foreach ( const Tomahawk::result_ptr& cachedResult, rl )
|
foreach ( const Tomahawk::query_ptr& cachedQuery, rl )
|
||||||
{
|
{
|
||||||
if ( cachedResult.isNull() )
|
if ( cachedQuery.isNull() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( cachedResult->track() == item->result()->track() &&
|
if ( cachedQuery->track() == item->query()->track() &&
|
||||||
( cachedResult->albumpos() == item->result()->albumpos() || cachedResult->albumpos() == 0 ) )
|
( cachedQuery->albumpos() == item->query()->albumpos() || cachedQuery->albumpos() == 0 ) )
|
||||||
{
|
{
|
||||||
return ( cachedResult.data() == item->result().data() );
|
return ( cachedQuery.data() == item->query().data() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,9 +204,14 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
|
|||||||
|
|
||||||
PlayableItem* ti = sourceModel()->itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
|
PlayableItem* ti = sourceModel()->itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
|
||||||
|
|
||||||
if ( ti->name() == item->name() &&
|
if ( ti && ti->name() == item->name() )
|
||||||
( ti->result()->albumpos() == item->result()->albumpos() ||
|
{
|
||||||
ti->result()->albumpos() == 0 || item->result()->albumpos() == 0 ) )
|
if ( ti->query()->albumpos() == item->query()->albumpos() || ti->query()->albumpos() == 0 || item->query()->albumpos() == 0 )
|
||||||
|
{
|
||||||
|
if ( item->result().isNull() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( !ti->result().isNull() )
|
||||||
{
|
{
|
||||||
if ( !item->result()->isOnline() && ti->result()->isOnline() )
|
if ( !item->result()->isOnline() && ti->result()->isOnline() )
|
||||||
return false;
|
return false;
|
||||||
@@ -219,6 +224,8 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool accepted = false;
|
bool accepted = false;
|
||||||
if ( m_filter.isEmpty() )
|
if ( m_filter.isEmpty() )
|
||||||
@@ -242,7 +249,7 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cache.insertMulti( sourceParent, item->result() );
|
m_cache.insertMulti( sourceParent, item->query() );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,7 +64,7 @@ private:
|
|||||||
void filterFinished();
|
void filterFinished();
|
||||||
QString textForItem( PlayableItem* item ) const;
|
QString textForItem( PlayableItem* item ) const;
|
||||||
|
|
||||||
mutable QMap< QPersistentModelIndex, Tomahawk::result_ptr > m_cache;
|
mutable QMap< QPersistentModelIndex, Tomahawk::query_ptr > m_cache;
|
||||||
|
|
||||||
QList<Tomahawk::artist_ptr> m_artistsFilter;
|
QList<Tomahawk::artist_ptr> m_artistsFilter;
|
||||||
QList<int> m_albumsFilter;
|
QList<int> m_albumsFilter;
|
||||||
|
Reference in New Issue
Block a user