diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index e67e6f5f3..70d2e108c 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -174,7 +174,7 @@ ViewManager::show( const Tomahawk::playlist_ptr& playlist ) { PlaylistView* view; - if ( !m_playlistViews.contains( playlist ) || !m_playlistViews.value( playlist ).isNull() ) + if ( !m_playlistViews.contains( playlist ) || m_playlistViews.value( playlist ).isNull() ) { view = createPageForPlaylist( playlist ); } @@ -747,11 +747,11 @@ ViewManager::onWidgetDestroyed( QWidget* widget ) { ViewPage* page = m_pageHistory.at( i ); - if ( !playlistForInterface( page->playlistInterface() ).isNull() ) + if ( playlistForInterface( page->playlistInterface() ).isNull() ) { m_playlistViews.remove( playlistForInterface( page->playlistInterface() ) ); } - if ( !dynamicPlaylistForInterface( page->playlistInterface() ).isNull() ) + if ( dynamicPlaylistForInterface( page->playlistInterface() ).isNull() ) { m_dynamicWidgets.remove( dynamicPlaylistForInterface( page->playlistInterface() ) ); } diff --git a/src/sourcetree/sourcesmodel.cpp b/src/sourcetree/sourcesmodel.cpp index caab4d44d..d3f0af496 100644 --- a/src/sourcetree/sourcesmodel.cpp +++ b/src/sourcetree/sourcesmodel.cpp @@ -283,7 +283,7 @@ SourcesModel::viewPageActivated( Tomahawk::ViewPage* page ) if ( !idx.isValid() ) m_sourceTreeLinks.remove( page ); else - emit selectRequest( idx ); + emit selectRequest( QPersistentModelIndex( idx ) ); } else { @@ -420,7 +420,7 @@ SourcesModel::linkSourceItemToPage( SourceTreeItem* item, ViewPage* p ) m_sourceTreeLinks[ p ] = item; if( m_viewPageDelayedCacheItem == p ) - emit selectRequest( indexFromItem( item ) ); + emit selectRequest( QPersistentModelIndex( indexFromItem( item ) ) ); if ( QObject* obj = dynamic_cast< QObject* >( p ) ) { @@ -517,12 +517,12 @@ SourcesModel::rowForItem( SourceTreeItem* item ) const void SourcesModel::itemSelectRequest( SourceTreeItem* item ) { - emit selectRequest( indexFromItem( item ) ); + emit selectRequest( QPersistentModelIndex( indexFromItem( item ) ) ); } void SourcesModel::itemExpandRequest( SourceTreeItem *item ) { qDebug() << "expanding source" << indexFromItem( item ) << item; - emit expandRequest( indexFromItem( item ) ); + emit expandRequest( QPersistentModelIndex( indexFromItem( item ) ) ); } diff --git a/src/sourcetree/sourcesmodel.h b/src/sourcetree/sourcesmodel.h index bf90a9a25..7bf1c2ef0 100644 --- a/src/sourcetree/sourcesmodel.h +++ b/src/sourcetree/sourcesmodel.h @@ -108,8 +108,8 @@ public slots: void itemExpandRequest( SourceTreeItem* item ); signals: - void selectRequest( const QModelIndex& idx ); - void expandRequest( const QModelIndex& idx ); + void selectRequest( const QPersistentModelIndex& idx ); + void expandRequest( const QPersistentModelIndex& idx ); private slots: void onSourcesAdded( const QList& sources ); diff --git a/src/sourcetree/sourcesproxymodel.cpp b/src/sourcetree/sourcesproxymodel.cpp index 66a3e85be..3188cda77 100644 --- a/src/sourcetree/sourcesproxymodel.cpp +++ b/src/sourcetree/sourcesproxymodel.cpp @@ -37,10 +37,10 @@ SourcesProxyModel::SourcesProxyModel( SourcesModel* model, QObject* parent ) setSourceModel( model ); - if ( model && model->metaObject()->indexOfSignal( "expandRequest(QModelIndex)" ) > -1 ) - connect( model, SIGNAL( expandRequest( QModelIndex ) ), this, SLOT( expandRequested( QModelIndex ) ) ); - if ( model && model->metaObject()->indexOfSignal( "selectRequest(QModelIndex)" ) > -1 ) - connect( model, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequested( QModelIndex ) ) ); + if ( model && model->metaObject()->indexOfSignal( "expandRequest(QPersistentModelIndex)" ) > -1 ) + connect( model, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequested( QPersistentModelIndex ) ), Qt::QueuedConnection ); + if ( model && model->metaObject()->indexOfSignal( "selectRequest(QPersistentModelIndex)" ) > -1 ) + connect( model, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequested( QPersistentModelIndex ) ), Qt::QueuedConnection ); } @@ -72,18 +72,18 @@ SourcesProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourcePar void -SourcesProxyModel::selectRequested( const QModelIndex& idx ) +SourcesProxyModel::selectRequested( const QPersistentModelIndex& idx ) { - qDebug() << "selectRequested for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ); - emit selectRequest( mapFromSource( idx ) ); + qDebug() << "selectRequested for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ) << mapFromSource( idx ).data(Qt::DisplayRole).toString(); + emit selectRequest( QPersistentModelIndex( mapFromSource( idx ) ) ); } void -SourcesProxyModel::expandRequested( const QModelIndex& idx ) +SourcesProxyModel::expandRequested( const QPersistentModelIndex& idx ) { - qDebug() << "emitting expand for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ); - emit expandRequest( mapFromSource( idx ) ); + qDebug() << "emitting expand for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ) << mapFromSource( idx ).data(Qt::DisplayRole).toString(); + emit expandRequest( QPersistentModelIndex( mapFromSource( idx ) ) ); } diff --git a/src/sourcetree/sourcesproxymodel.h b/src/sourcetree/sourcesproxymodel.h index 01c0a9f87..a1908b73c 100644 --- a/src/sourcetree/sourcesproxymodel.h +++ b/src/sourcetree/sourcesproxymodel.h @@ -33,12 +33,12 @@ public: public slots: void showOfflineSources( bool offlineSourcesShown ); - void selectRequested( const QModelIndex& ); - void expandRequested( const QModelIndex& ); + void selectRequested( const QPersistentModelIndex& ); + void expandRequested( const QPersistentModelIndex& ); signals: - void selectRequest( const QModelIndex& idx ); - void expandRequest( const QModelIndex& idx ); + void selectRequest( const QPersistentModelIndex& idx ); + void expandRequest( const QPersistentModelIndex& idx ); protected: bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 7156b68f2..91605f93c 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -112,8 +112,8 @@ SourceTreeView::SourceTreeView( QWidget* parent ) m_model = new SourcesModel( this ); m_proxyModel = new SourcesProxyModel( m_model, this ); - connect( m_proxyModel, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequest( QModelIndex ) ), Qt::QueuedConnection ); - connect( m_proxyModel, SIGNAL( expandRequest( QModelIndex ) ), this, SLOT( expandRequest( QModelIndex ) ), Qt::QueuedConnection ); + connect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequest( QPersistentModelIndex ) ) ); + connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequest( QPersistentModelIndex ) ) ); setModel( m_proxyModel ); @@ -243,8 +243,9 @@ SourceTreeView::onItemExpanded( const QModelIndex& idx ) void -SourceTreeView::selectRequest( const QModelIndex& idx ) +SourceTreeView::selectRequest( const QPersistentModelIndex& idx ) { + qDebug() << "Select request for:" << idx << idx.data().toString() << selectionModel()->selectedIndexes().contains( idx ); if ( !selectionModel()->selectedIndexes().contains( idx ) ) { scrollTo( idx, QTreeView::EnsureVisible ); @@ -253,9 +254,9 @@ SourceTreeView::selectRequest( const QModelIndex& idx ) } void -SourceTreeView::expandRequest( const QModelIndex &idx ) +SourceTreeView::expandRequest( const QPersistentModelIndex &idx ) { - qDebug() << "Expanding idx" << idx; + qDebug() << "Expanding idx" << idx << idx.data( Qt::DisplayRole ).toString(); expand( idx ); } diff --git a/src/sourcetree/sourcetreeview.h b/src/sourcetree/sourcetreeview.h index 15c8276f9..2eca36fa2 100644 --- a/src/sourcetree/sourcetreeview.h +++ b/src/sourcetree/sourcetreeview.h @@ -48,8 +48,8 @@ signals: private slots: void onItemExpanded( const QModelIndex& idx ); void onItemActivated( const QModelIndex& index ); - void selectRequest( const QModelIndex& idx ); - void expandRequest( const QModelIndex& idx ); + void selectRequest( const QPersistentModelIndex& idx ); + void expandRequest( const QPersistentModelIndex& idx ); void loadPlaylist(); void deletePlaylist( const QModelIndex& = QModelIndex() ); diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index bd841c2dc..fad12a210 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -389,6 +389,7 @@ TomahawkApp::registerMetaTypes() qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" ); qRegisterMetaType< DirLister::Mode >("DirLister::Mode"); + qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" ); } diff --git a/src/tomahawkapp.h b/src/tomahawkapp.h index 9e36f802b..6aa3fca33 100644 --- a/src/tomahawkapp.h +++ b/src/tomahawkapp.h @@ -145,5 +145,7 @@ private: QxtHttpSessionManager m_session; }; +Q_DECLARE_METATYPE( QPersistentModelIndex ); + #endif // TOMAHAWKAPP_H