mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
Add lazyload getters for models to the ViewManager.
This commit is contained in:
@@ -246,13 +246,10 @@ ViewManager::show( const Tomahawk::collection_ptr& collection )
|
|||||||
if ( !m_collectionViews.contains( collection ) || m_collectionViews.value( collection ).isNull() )
|
if ( !m_collectionViews.contains( collection ) || m_collectionViews.value( collection ).isNull() )
|
||||||
{
|
{
|
||||||
view = new CollectionView();
|
view = new CollectionView();
|
||||||
CollectionFlatModel* model = new CollectionFlatModel();
|
view->setTrackModel( flatModelForCollection( collection ) );
|
||||||
view->setTrackModel( model );
|
|
||||||
view->setFrameShape( QFrame::NoFrame );
|
view->setFrameShape( QFrame::NoFrame );
|
||||||
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
||||||
|
|
||||||
model->addCollection( collection );
|
|
||||||
|
|
||||||
m_collectionViews.insert( collection, view );
|
m_collectionViews.insert( collection, view );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -270,13 +267,10 @@ ViewManager::show( const Tomahawk::collection_ptr& collection )
|
|||||||
if ( !m_treeViews.contains( collection ) || m_treeViews.value( collection ).isNull() )
|
if ( !m_treeViews.contains( collection ) || m_treeViews.value( collection ).isNull() )
|
||||||
{
|
{
|
||||||
view = new ArtistView();
|
view = new ArtistView();
|
||||||
TreeModel* model = new TreeModel();
|
view->setTreeModel( treeModelForCollection( collection ) );
|
||||||
view->setTreeModel( model );
|
|
||||||
view->setFrameShape( QFrame::NoFrame );
|
view->setFrameShape( QFrame::NoFrame );
|
||||||
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
||||||
|
|
||||||
model->addCollection( collection );
|
|
||||||
|
|
||||||
m_treeViews.insert( collection, view );
|
m_treeViews.insert( collection, view );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -294,11 +288,9 @@ ViewManager::show( const Tomahawk::collection_ptr& collection )
|
|||||||
if ( !m_collectionAlbumViews.contains( collection ) || m_collectionAlbumViews.value( collection ).isNull() )
|
if ( !m_collectionAlbumViews.contains( collection ) || m_collectionAlbumViews.value( collection ).isNull() )
|
||||||
{
|
{
|
||||||
aview = new AlbumView();
|
aview = new AlbumView();
|
||||||
AlbumModel* amodel = new AlbumModel( aview );
|
aview->setAlbumModel( albumModelForCollection( collection ) );
|
||||||
aview->setAlbumModel( amodel );
|
|
||||||
aview->setFrameShape( QFrame::NoFrame );
|
aview->setFrameShape( QFrame::NoFrame );
|
||||||
aview->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
aview->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
||||||
amodel->addCollection( collection );
|
|
||||||
|
|
||||||
m_collectionAlbumViews.insert( collection, aview );
|
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
|
bool
|
||||||
ViewManager::isSuperCollectionVisible() const
|
ViewManager::isSuperCollectionVisible() const
|
||||||
{
|
{
|
||||||
|
@@ -104,6 +104,12 @@ public:
|
|||||||
// linked to the sidebar. call it right after creating the playlist
|
// linked to the sidebar. call it right after creating the playlist
|
||||||
PlaylistView* createPageForPlaylist( const Tomahawk::playlist_ptr& pl );
|
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:
|
signals:
|
||||||
void numSourcesChanged( unsigned int sources );
|
void numSourcesChanged( unsigned int sources );
|
||||||
void numTracksChanged( unsigned int tracks );
|
void numTracksChanged( unsigned int tracks );
|
||||||
@@ -202,6 +208,11 @@ private:
|
|||||||
QHash< Tomahawk::playlist_ptr, QWeakPointer<PlaylistView> > m_playlistViews;
|
QHash< Tomahawk::playlist_ptr, QWeakPointer<PlaylistView> > m_playlistViews;
|
||||||
QHash< Tomahawk::source_ptr, QWeakPointer<SourceInfoWidget> > m_sourceViews;
|
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;
|
QList<Tomahawk::ViewPage*> m_pageHistory;
|
||||||
|
|
||||||
Tomahawk::collection_ptr m_currentCollection;
|
Tomahawk::collection_ptr m_currentCollection;
|
||||||
|
Reference in New Issue
Block a user