mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 23:26:40 +02:00
* Break up and split PlayableProxyModel's filters.
This commit is contained in:
@@ -144,6 +144,68 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
PlayableProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
|
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 ) );
|
PlayableItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
|
||||||
if ( !pi )
|
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() )
|
if ( pi->query() )
|
||||||
{
|
{
|
||||||
Tomahawk::result_ptr r;
|
Tomahawk::result_ptr r;
|
||||||
|
@@ -117,7 +117,10 @@ private slots:
|
|||||||
void onCurrentIndexChanged( const QModelIndex& newIndex, const QModelIndex& oldIndex );
|
void onCurrentIndexChanged( const QModelIndex& newIndex, const QModelIndex& oldIndex );
|
||||||
|
|
||||||
private:
|
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;
|
PlayableModel* m_model;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user