diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 8ef05113f..ec878a232 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -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(); } diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 194ff0313..31c113911 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -147,6 +147,8 @@ signals: void changed(); void currentIndexChanged(); + void expandRequest( const QPersistentModelIndex& index ); + public slots: virtual void setCurrentIndex( const QModelIndex& index ); diff --git a/src/libtomahawk/playlist/PlayableProxyModel.cpp b/src/libtomahawk/playlist/PlayableProxyModel.cpp index 823f1f5f9..fa4b90fb0 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.cpp +++ b/src/libtomahawk/playlist/PlayableProxyModel.cpp @@ -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 ) ) ); +} diff --git a/src/libtomahawk/playlist/PlayableProxyModel.h b/src/libtomahawk/playlist/PlayableProxyModel.h index c02f806b3..f92b3b520 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.h +++ b/src/libtomahawk/playlist/PlayableProxyModel.h @@ -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; diff --git a/src/libtomahawk/playlist/PlaylistModel.cpp b/src/libtomahawk/playlist/PlaylistModel.cpp index 0219162fd..42212b1d8 100644 --- a/src/libtomahawk/playlist/PlaylistModel.cpp +++ b/src/libtomahawk/playlist/PlaylistModel.cpp @@ -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 ); } diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index e33e5e98f..b6ef8d57f 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -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 ); +} diff --git a/src/libtomahawk/playlist/TrackView.h b/src/libtomahawk/playlist/TrackView.h index feb0fca19..128220158 100644 --- a/src/libtomahawk/playlist/TrackView.h +++ b/src/libtomahawk/playlist/TrackView.h @@ -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;