diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 5ee170ef5..6aacf7673 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -246,13 +246,10 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) if ( !m_collectionViews.contains( collection ) || m_collectionViews.value( collection ).isNull() ) { view = new CollectionView(); - CollectionFlatModel* model = new CollectionFlatModel(); - view->setTrackModel( model ); + view->setTrackModel( flatModelForCollection( collection ) ); view->setFrameShape( QFrame::NoFrame ); view->setAttribute( Qt::WA_MacShowFocusRect, 0 ); - model->addCollection( collection ); - m_collectionViews.insert( collection, view ); } else @@ -270,13 +267,10 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) if ( !m_treeViews.contains( collection ) || m_treeViews.value( collection ).isNull() ) { view = new ArtistView(); - TreeModel* model = new TreeModel(); - view->setTreeModel( model ); + view->setTreeModel( treeModelForCollection( collection ) ); view->setFrameShape( QFrame::NoFrame ); view->setAttribute( Qt::WA_MacShowFocusRect, 0 ); - model->addCollection( collection ); - m_treeViews.insert( collection, view ); } else @@ -294,11 +288,9 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) if ( !m_collectionAlbumViews.contains( collection ) || m_collectionAlbumViews.value( collection ).isNull() ) { aview = new AlbumView(); - AlbumModel* amodel = new AlbumModel( aview ); - aview->setAlbumModel( amodel ); + aview->setAlbumModel( albumModelForCollection( collection ) ); aview->setFrameShape( QFrame::NoFrame ); aview->setAttribute( Qt::WA_MacShowFocusRect, 0 ); - amodel->addCollection( collection ); m_collectionAlbumViews.insert( collection, aview ); } @@ -864,6 +856,69 @@ ViewManager::collectionForInterface( Tomahawk::PlaylistInterface* interface ) co } +CollectionFlatModel* +ViewManager::flatModelForCollection( const collection_ptr& collection ) +{ + CollectionFlatModel* model = 0; + if ( !m_collectionFlatModels.contains( collection ) || m_collectionFlatModels.value( collection ).isNull() ) + { + model = new CollectionFlatModel(); + model->addCollection( collection ); + + m_collectionFlatModels.insert( collection, QWeakPointer( model ) ); + } + else + { + model = m_collectionFlatModels.value( collection ).data(); + } + + + return model; +} + + +TreeModel* +ViewManager::treeModelForCollection( const collection_ptr& collection ) +{ + TreeModel* model = 0; + if ( !m_collectionTreeModels.contains( collection ) || m_collectionTreeModels.value( collection ).isNull() ) + { + model = new TreeModel(); + model->addCollection( collection ); + + m_collectionTreeModels.insert( collection, QWeakPointer( model ) ); + } + else + { + model = m_collectionTreeModels.value( collection ).data(); + } + + + return model; +} + + +AlbumModel* +ViewManager::albumModelForCollection( const collection_ptr& collection ) +{ + AlbumModel* model = 0; + if ( !m_collectionAlbumModels.contains( collection ) || m_collectionAlbumModels.value( collection ).isNull() ) + { + model = new AlbumModel(); + model->addCollection( collection ); + + m_collectionAlbumModels.insert( collection, QWeakPointer( model ) ); + } + else + { + model = m_collectionAlbumModels.value( collection ).data(); + } + + + return model; +} + + bool ViewManager::isSuperCollectionVisible() const { diff --git a/src/libtomahawk/viewmanager.h b/src/libtomahawk/viewmanager.h index edcba014c..62cb552c5 100644 --- a/src/libtomahawk/viewmanager.h +++ b/src/libtomahawk/viewmanager.h @@ -104,6 +104,12 @@ public: // linked to the sidebar. call it right after creating the playlist PlaylistView* createPageForPlaylist( const Tomahawk::playlist_ptr& pl ); + + // outsource to a modelManager (?) + CollectionFlatModel* flatModelForCollection( const Tomahawk::collection_ptr& collection ); + TreeModel* treeModelForCollection( const Tomahawk::collection_ptr& collection ); + AlbumModel* albumModelForCollection( const Tomahawk::collection_ptr& collection ); + signals: void numSourcesChanged( unsigned int sources ); void numTracksChanged( unsigned int tracks ); @@ -202,6 +208,11 @@ private: QHash< Tomahawk::playlist_ptr, QWeakPointer > m_playlistViews; QHash< Tomahawk::source_ptr, QWeakPointer > m_sourceViews; + QHash< Tomahawk::collection_ptr, QWeakPointer > m_collectionFlatModels; + QHash< Tomahawk::collection_ptr, QWeakPointer > m_collectionTreeModels; + QHash< Tomahawk::collection_ptr, QWeakPointer > m_collectionAlbumModels; + + QList m_pageHistory; Tomahawk::collection_ptr m_currentCollection;