1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

* Break up and split PlayableProxyModel's filters.

This commit is contained in:
Christian Muehlhaeuser 2014-09-26 04:37:55 +02:00
parent 4f0afd2fa9
commit 2165c7b540
2 changed files with 66 additions and 21 deletions

View File

@ -144,6 +144,68 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
bool
PlayableProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
bool dupeFilter = true;
bool visibilityFilter = true;
if ( m_hideDupeItems )
dupeFilter = dupeFilterAcceptsRow( sourceRow, sourceParent );
if ( m_maxVisibleItems > 0 )
visibilityFilter = visibilityFilterAcceptsRow( sourceRow, sourceParent );
return ( dupeFilter && visibilityFilter && nameFilterAcceptsRow( sourceRow, sourceParent ) );
}
bool
PlayableProxyModel::dupeFilterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
if ( !m_hideDupeItems )
return true;
PlayableItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
if ( !pi )
return false;
for ( int i = 0; i < sourceRow; i++ )
{
PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
if ( !di )
continue;
bool b = ( pi->query() && pi->query()->equals( di->query() ) ) ||
( pi->album() && pi->album() == di->album() ) ||
( pi->artist() && pi->artist()->name() == di->artist()->name() );
if ( b && filterAcceptsRow( i, sourceParent ) )
return false;
}
return true;
}
bool
PlayableProxyModel::visibilityFilterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
if ( m_maxVisibleItems <= 0 )
return true;
int items = 0;
for ( int i = 0; i < sourceRow; i++ )
{
if ( dupeFilterAcceptsRow( i, sourceParent ) && nameFilterAcceptsRow( i, sourceParent ) )
{
items++;
}
}
return ( items < m_maxVisibleItems );
}
bool
PlayableProxyModel::nameFilterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
PlayableItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
if ( !pi )
@ -157,26 +219,6 @@ PlayableProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourcePa
}
}
if ( m_maxVisibleItems > 0 && sourceRow > m_maxVisibleItems - 1 )
return false;
if ( m_hideDupeItems )
{
for ( int i = 0; i < sourceRow; i++ )
{
PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
if ( !di )
continue;
bool b = ( pi->query() && pi->query()->equals( di->query() ) ) ||
( pi->album() && pi->album() == di->album() ) ||
( pi->artist() && pi->artist()->name() == di->artist()->name() );
if ( b && filterAcceptsRow( i, sourceParent ) )
return false;
}
}
if ( pi->query() )
{
Tomahawk::result_ptr r;

View File

@ -117,7 +117,10 @@ private slots:
void onCurrentIndexChanged( const QModelIndex& newIndex, const QModelIndex& oldIndex );
private:
virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const;
bool nameFilterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
bool dupeFilterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
bool visibilityFilterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const;
PlayableModel* m_model;