1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

Reload Collection-related models when it changed.

This commit is contained in:
Christian Muehlhaeuser
2014-10-20 03:49:23 +02:00
parent 1a6a15844b
commit e9c7fd7a16
2 changed files with 56 additions and 28 deletions

View File

@@ -126,70 +126,70 @@ CollectionViewPage::~CollectionViewPage()
void void
CollectionViewPage::loadCollection( const collection_ptr& collection ) CollectionViewPage::loadCollection( const collection_ptr& collection )
{ {
m_collection = collection; if ( m_collection )
TreeModel* model = new TreeModel();
PlayableModel* flatModel = new PlayableModel();
PlayableModel* albumModel = new PlayableModel();
setTreeModel( model );
setFlatModel( flatModel );
setAlbumModel( albumModel );
model->addCollection( collection );
flatModel->appendTracks( collection );
albumModel->appendAlbums( collection );
if ( collection && collection->source() && collection->source()->isLocal() )
{ {
setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) ); disconnect( collection.data(), SIGNAL( changed() ), this, SLOT( onCollectionChanged() ) );
} }
else
setEmptyTip( tr( "This collection is empty." ) );
if ( collection.objectCast<ScriptCollection>() ) m_collection = collection;
m_trackView->setEmptyTip( tr( "Cloud collections aren't supported in the flat view yet. We will have them covered soon. Switch to another view to navigate them." ) ); connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection );
onCollectionChanged();
} }
void void
CollectionViewPage::setTreeModel( TreeModel* model ) CollectionViewPage::setTreeModel( TreeModel* model )
{ {
if ( m_model ) QPointer<PlayableModel> oldModel = m_model;
{
disconnect( m_model, SIGNAL( changed() ), this, SLOT( onModelChanged() ) );
delete m_model;
}
m_model = model; m_model = model;
m_columnView->setTreeModel( model ); m_columnView->setTreeModel( model );
connect( model, SIGNAL( changed() ), SLOT( onModelChanged() ), Qt::UniqueConnection ); connect( model, SIGNAL( changed() ), SLOT( onModelChanged() ), Qt::UniqueConnection );
onModelChanged(); onModelChanged();
if ( oldModel )
{
disconnect( oldModel.data(), SIGNAL( changed() ), this, SLOT( onModelChanged() ) );
delete oldModel.data();
}
} }
void void
CollectionViewPage::setFlatModel( PlayableModel* model ) CollectionViewPage::setFlatModel( PlayableModel* model )
{ {
if ( m_flatModel ) QPointer<PlayableModel> oldModel = m_flatModel;
delete m_flatModel;
m_flatModel = model; m_flatModel = model;
m_trackView->setPlayableModel( model ); m_trackView->setPlayableModel( model );
m_trackView->setSortingEnabled( true ); m_trackView->setSortingEnabled( true );
m_trackView->sortByColumn( 0, Qt::AscendingOrder ); m_trackView->sortByColumn( 0, Qt::AscendingOrder );
if ( oldModel )
{
disconnect( oldModel.data(), SIGNAL( changed() ), this, SLOT( onModelChanged() ) );
delete oldModel.data();
}
} }
void void
CollectionViewPage::setAlbumModel( PlayableModel* model ) CollectionViewPage::setAlbumModel( PlayableModel* model )
{ {
QPointer<PlayableModel> oldModel = m_albumModel;
if ( m_albumModel ) if ( m_albumModel )
delete m_albumModel; delete m_albumModel;
m_albumModel = model; m_albumModel = model;
m_albumView->setPlayableModel( model ); m_albumView->setPlayableModel( model );
if ( oldModel )
{
disconnect( oldModel.data(), SIGNAL( changed() ), this, SLOT( onModelChanged() ) );
delete oldModel.data();
}
} }
@@ -357,6 +357,33 @@ CollectionViewPage::onModelChanged()
} }
void
CollectionViewPage::onCollectionChanged()
{
TreeModel* model = new TreeModel();
PlayableModel* flatModel = new PlayableModel();
PlayableModel* albumModel = new PlayableModel();
setTreeModel( model );
setFlatModel( flatModel );
setAlbumModel( albumModel );
model->addCollection( m_collection );
flatModel->appendTracks( m_collection );
albumModel->appendAlbums( m_collection );
if ( m_collection && m_collection->source() && m_collection->source()->isLocal() )
{
setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) );
}
else
setEmptyTip( tr( "This collection is empty." ) );
if ( m_collection.objectCast<ScriptCollection>() )
m_trackView->setEmptyTip( tr( "Cloud collections aren't supported in the flat view yet. We will have them covered soon. Switch to another view to navigate them." ) );
}
bool bool
CollectionViewPage::isTemporaryPage() const CollectionViewPage::isTemporaryPage() const
{ {

View File

@@ -76,6 +76,7 @@ signals:
private slots: private slots:
void onModelChanged(); void onModelChanged();
void onCollectionChanged();
private: private:
FilterHeader* m_header; FilterHeader* m_header;