mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 15:47:38 +02:00
* Break up and split PlayableProxyModel's filters.
This commit is contained in:
@@ -145,23 +145,28 @@ 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 ) );
|
PlayableItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
|
||||||
if ( !pi )
|
if ( !pi )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( m_hideEmptyParents && pi->source() )
|
|
||||||
{
|
|
||||||
if ( !sourceModel()->rowCount( sourceModel()->index( sourceRow, 0, sourceParent ) ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_maxVisibleItems > 0 && sourceRow > m_maxVisibleItems - 1 )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ( m_hideDupeItems )
|
|
||||||
{
|
|
||||||
for ( int i = 0; i < sourceRow; i++ )
|
for ( int i = 0; i < sourceRow; i++ )
|
||||||
{
|
{
|
||||||
PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
|
PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
|
||||||
@@ -175,6 +180,43 @@ PlayableProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourcePa
|
|||||||
if ( b && filterAcceptsRow( i, sourceParent ) )
|
if ( b && filterAcceptsRow( i, sourceParent ) )
|
||||||
return false;
|
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 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( m_hideEmptyParents && pi->source() )
|
||||||
|
{
|
||||||
|
if ( !sourceModel()->rowCount( sourceModel()->index( sourceRow, 0, sourceParent ) ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( pi->query() )
|
if ( pi->query() )
|
||||||
|
@@ -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