1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 00:24:12 +02:00

Add lazyload getters for models to the ViewManager.

This commit is contained in:
Dominik Schmidt
2011-09-07 08:50:39 +02:00
parent d49ce2f242
commit 048c82ac24
2 changed files with 77 additions and 11 deletions

View File

@@ -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<CollectionFlatModel>( 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<TreeModel>( 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<AlbumModel>( model ) );
}
else
{
model = m_collectionAlbumModels.value( collection ).data();
}
return model;
}
bool
ViewManager::isSuperCollectionVisible() const
{

View File

@@ -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<PlaylistView> > m_playlistViews;
QHash< Tomahawk::source_ptr, QWeakPointer<SourceInfoWidget> > m_sourceViews;
QHash< Tomahawk::collection_ptr, QWeakPointer<CollectionFlatModel> > m_collectionFlatModels;
QHash< Tomahawk::collection_ptr, QWeakPointer<TreeModel> > m_collectionTreeModels;
QHash< Tomahawk::collection_ptr, QWeakPointer<AlbumModel> > m_collectionAlbumModels;
QList<Tomahawk::ViewPage*> m_pageHistory;
Tomahawk::collection_ptr m_currentCollection;