1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

* Auto-expand grouped PlayableModels.

This commit is contained in:
Christian Muehlhaeuser
2014-08-18 12:53:21 +02:00
parent 5220f164e6
commit 7433287eb4
7 changed files with 42 additions and 9 deletions

View File

@@ -711,6 +711,8 @@ PlayableModel::insertInternal( const QList< T >& items, int row, const QList< To
emit endInsertRows();
emit itemCountChanged( rowCount( QModelIndex() ) );
if ( parent.isValid() )
emit expandRequest( parent );
finishLoading();
}

View File

@@ -147,6 +147,8 @@ signals:
void changed();
void currentIndexChanged();
void expandRequest( const QPersistentModelIndex& index );
public slots:
virtual void setCurrentIndex( const QModelIndex& index );

View File

@@ -112,6 +112,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
disconnect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), this, SLOT( onIndexPlayable( QModelIndex ) ) );
disconnect( m_model, SIGNAL( indexResolved( QModelIndex ) ), this, SLOT( onIndexResolved( QModelIndex ) ) );
disconnect( m_model, SIGNAL( currentIndexChanged() ), this, SIGNAL( currentIndexChanged() ) );
disconnect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequested( QPersistentModelIndex ) ) );
}
m_model = sourceModel;
@@ -124,6 +125,7 @@ PlayableProxyModel::setSourcePlayableModel( PlayableModel* sourceModel )
connect( m_model, SIGNAL( indexPlayable( QModelIndex ) ), SLOT( onIndexPlayable( QModelIndex ) ) );
connect( m_model, SIGNAL( indexResolved( QModelIndex ) ), SLOT( onIndexResolved( QModelIndex ) ) );
connect( m_model, SIGNAL( currentIndexChanged() ), SIGNAL( currentIndexChanged() ) );
connect( m_model, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expandRequested( QPersistentModelIndex ) ) );
}
QSortFilterProxyModel::setSourceModel( m_model );
@@ -660,3 +662,10 @@ PlayableProxyModel::onIndexResolved( const QModelIndex& index )
{
emit indexResolved( mapFromSource( index ) );
}
void
PlayableProxyModel::expandRequested( const QPersistentModelIndex& idx )
{
emit expandRequest( QPersistentModelIndex( mapFromSource( idx ) ) );
}

View File

@@ -99,6 +99,8 @@ signals:
void itemCountChanged( unsigned int items );
void expandRequest( const QPersistentModelIndex& index );
protected:
virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;
virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
@@ -109,6 +111,8 @@ private slots:
void onIndexPlayable( const QModelIndex& index );
void onIndexResolved( const QModelIndex& index );
void expandRequested( const QPersistentModelIndex& index );
private:
virtual bool lessThan( int column, const Tomahawk::query_ptr& left, const Tomahawk::query_ptr& right ) const;

View File

@@ -331,6 +331,8 @@ PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int
emit endInsertRows();
emit itemCountChanged( rowCount( QModelIndex() ) );
if ( parent.isValid() )
emit expandRequest( parent );
}

View File

@@ -63,6 +63,7 @@ TrackView::TrackView( QWidget* parent )
, m_dragging( false )
, m_updateContextView( true )
, m_alternatingRowColors( false )
, m_autoExpanding( true )
, m_contextMenu( new ContextMenu( this ) )
{
setFrameShape( QFrame::NoFrame );
@@ -162,6 +163,7 @@ TrackView::setProxyModel( PlayableProxyModel* model )
disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( onViewChanged() ) );
disconnect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( verifySize() ) );
disconnect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( verifySize() ) );
disconnect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expand( QPersistentModelIndex ) ) );
}
m_proxyModel = model;
@@ -172,6 +174,7 @@ TrackView::setProxyModel( PlayableProxyModel* model )
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) );
connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( verifySize() ) );
connect( m_proxyModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ), SLOT( verifySize() ) );
connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), SLOT( expand( QPersistentModelIndex ) ) );
m_delegate = new PlaylistItemDelegate( this, m_proxyModel );
QTreeView::setItemDelegate( m_delegate );
@@ -205,11 +208,8 @@ void
TrackView::setPlayableModel( PlayableModel* model )
{
if ( m_model ) {
disconnect( m_model, SIGNAL( loadingStarted() ),
m_loadingSpinner, SLOT( fadeIn() ) );
disconnect( m_model, SIGNAL( loadingFinished() ),
m_loadingSpinner, SLOT( fadeOut() ) );
disconnect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) );
disconnect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
}
m_model = model;
@@ -236,10 +236,13 @@ TrackView::setPlayableModel( PlayableModel* model )
setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
}
connect( m_model, SIGNAL( loadingStarted() ),
m_loadingSpinner, SLOT( fadeIn() ) );
connect( m_model, SIGNAL( loadingFinished() ),
m_loadingSpinner, SLOT( fadeOut() ) );
connect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) );
connect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
if ( m_autoExpanding )
{
expandAll();
}
onViewChanged();
emit modelChanged();
@@ -842,3 +845,10 @@ TrackView::setAlternatingRowColors( bool enable )
m_alternatingRowColors = enable;
QTreeView::setAlternatingRowColors( enable );
}
void
TrackView::expand( const QPersistentModelIndex& idx )
{
QTreeView::expand( idx );
}

View File

@@ -85,6 +85,7 @@ public:
void setAutoResize( bool b );
void setAlternatingRowColors( bool enable );
void setAutoExpanding( bool enable );
// Starts playing from the beginning if resolved, or waits until a track is playable
void startPlayingFromStart();
@@ -100,6 +101,8 @@ public slots:
void onViewChanged();
void onScrollTimeout();
void expand( const QPersistentModelIndex& idx );
signals:
void itemActivated( const QModelIndex& index );
void querySelected( const Tomahawk::query_ptr& query );
@@ -155,6 +158,7 @@ private:
bool m_updateContextView;
bool m_autoResize;
bool m_alternatingRowColors;
bool m_autoExpanding;
QModelIndex m_contextMenuIndex;