1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

TWK-414: Fix selecting newly created playlists and stations.

God this was a PITA. What is going on:

Playlists are created by collection item. SourcesModel::linkSourceItemToPage is called from *constructor* of PlaylistItem, so BEFORE
the CollectionItem calls endRowsAdded(). This means when the SourcesProxyModel does the mapFromSource() during the activateIndex() call
(from linkSourceItemToPage) it won't have the new index in the mapping yet as endRowsAdded() hasn't been called. So that will fail.

We have to queue the signal *from the source model to the proxy* not from the proxy to the view.

EUGH.

Also, fix a few logic errors from teh ViewManager/WeakPointer refactor that had bad logic
This commit is contained in:
Leo Franchi
2011-08-20 00:47:53 -04:00
parent 6521198127
commit 9737f765e5
9 changed files with 34 additions and 30 deletions

View File

@@ -174,7 +174,7 @@ ViewManager::show( const Tomahawk::playlist_ptr& playlist )
{ {
PlaylistView* view; 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 ); view = createPageForPlaylist( playlist );
} }
@@ -747,11 +747,11 @@ ViewManager::onWidgetDestroyed( QWidget* widget )
{ {
ViewPage* page = m_pageHistory.at( i ); ViewPage* page = m_pageHistory.at( i );
if ( !playlistForInterface( page->playlistInterface() ).isNull() ) if ( playlistForInterface( page->playlistInterface() ).isNull() )
{ {
m_playlistViews.remove( playlistForInterface( page->playlistInterface() ) ); m_playlistViews.remove( playlistForInterface( page->playlistInterface() ) );
} }
if ( !dynamicPlaylistForInterface( page->playlistInterface() ).isNull() ) if ( dynamicPlaylistForInterface( page->playlistInterface() ).isNull() )
{ {
m_dynamicWidgets.remove( dynamicPlaylistForInterface( page->playlistInterface() ) ); m_dynamicWidgets.remove( dynamicPlaylistForInterface( page->playlistInterface() ) );
} }

View File

@@ -283,7 +283,7 @@ SourcesModel::viewPageActivated( Tomahawk::ViewPage* page )
if ( !idx.isValid() ) if ( !idx.isValid() )
m_sourceTreeLinks.remove( page ); m_sourceTreeLinks.remove( page );
else else
emit selectRequest( idx ); emit selectRequest( QPersistentModelIndex( idx ) );
} }
else else
{ {
@@ -420,7 +420,7 @@ SourcesModel::linkSourceItemToPage( SourceTreeItem* item, ViewPage* p )
m_sourceTreeLinks[ p ] = item; m_sourceTreeLinks[ p ] = item;
if( m_viewPageDelayedCacheItem == p ) if( m_viewPageDelayedCacheItem == p )
emit selectRequest( indexFromItem( item ) ); emit selectRequest( QPersistentModelIndex( indexFromItem( item ) ) );
if ( QObject* obj = dynamic_cast< QObject* >( p ) ) if ( QObject* obj = dynamic_cast< QObject* >( p ) )
{ {
@@ -517,12 +517,12 @@ SourcesModel::rowForItem( SourceTreeItem* item ) const
void void
SourcesModel::itemSelectRequest( SourceTreeItem* item ) SourcesModel::itemSelectRequest( SourceTreeItem* item )
{ {
emit selectRequest( indexFromItem( item ) ); emit selectRequest( QPersistentModelIndex( indexFromItem( item ) ) );
} }
void void
SourcesModel::itemExpandRequest( SourceTreeItem *item ) SourcesModel::itemExpandRequest( SourceTreeItem *item )
{ {
qDebug() << "expanding source" << indexFromItem( item ) << item; qDebug() << "expanding source" << indexFromItem( item ) << item;
emit expandRequest( indexFromItem( item ) ); emit expandRequest( QPersistentModelIndex( indexFromItem( item ) ) );
} }

View File

@@ -108,8 +108,8 @@ public slots:
void itemExpandRequest( SourceTreeItem* item ); void itemExpandRequest( SourceTreeItem* item );
signals: signals:
void selectRequest( const QModelIndex& idx ); void selectRequest( const QPersistentModelIndex& idx );
void expandRequest( const QModelIndex& idx ); void expandRequest( const QPersistentModelIndex& idx );
private slots: private slots:
void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources ); void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources );

View File

@@ -37,10 +37,10 @@ SourcesProxyModel::SourcesProxyModel( SourcesModel* model, QObject* parent )
setSourceModel( model ); setSourceModel( model );
if ( model && model->metaObject()->indexOfSignal( "expandRequest(QModelIndex)" ) > -1 ) if ( model && model->metaObject()->indexOfSignal( "expandRequest(QPersistentModelIndex)" ) > -1 )
connect( model, SIGNAL( expandRequest( QModelIndex ) ), this, SLOT( expandRequested( QModelIndex ) ) ); connect( model, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequested( QPersistentModelIndex ) ), Qt::QueuedConnection );
if ( model && model->metaObject()->indexOfSignal( "selectRequest(QModelIndex)" ) > -1 ) if ( model && model->metaObject()->indexOfSignal( "selectRequest(QPersistentModelIndex)" ) > -1 )
connect( model, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequested( QModelIndex ) ) ); connect( model, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequested( QPersistentModelIndex ) ), Qt::QueuedConnection );
} }
@@ -72,18 +72,18 @@ SourcesProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourcePar
void void
SourcesProxyModel::selectRequested( const QModelIndex& idx ) SourcesProxyModel::selectRequested( const QPersistentModelIndex& idx )
{ {
qDebug() << "selectRequested for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ); qDebug() << "selectRequested for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ) << mapFromSource( idx ).data(Qt::DisplayRole).toString();
emit selectRequest( mapFromSource( idx ) ); emit selectRequest( QPersistentModelIndex( mapFromSource( idx ) ) );
} }
void void
SourcesProxyModel::expandRequested( const QModelIndex& idx ) SourcesProxyModel::expandRequested( const QPersistentModelIndex& idx )
{ {
qDebug() << "emitting expand for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ); qDebug() << "emitting expand for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ) << mapFromSource( idx ).data(Qt::DisplayRole).toString();
emit expandRequest( mapFromSource( idx ) ); emit expandRequest( QPersistentModelIndex( mapFromSource( idx ) ) );
} }

View File

@@ -33,12 +33,12 @@ public:
public slots: public slots:
void showOfflineSources( bool offlineSourcesShown ); void showOfflineSources( bool offlineSourcesShown );
void selectRequested( const QModelIndex& ); void selectRequested( const QPersistentModelIndex& );
void expandRequested( const QModelIndex& ); void expandRequested( const QPersistentModelIndex& );
signals: signals:
void selectRequest( const QModelIndex& idx ); void selectRequest( const QPersistentModelIndex& idx );
void expandRequest( const QModelIndex& idx ); void expandRequest( const QPersistentModelIndex& idx );
protected: protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const;

View File

@@ -112,8 +112,8 @@ SourceTreeView::SourceTreeView( QWidget* parent )
m_model = new SourcesModel( this ); m_model = new SourcesModel( this );
m_proxyModel = new SourcesProxyModel( m_model, this ); m_proxyModel = new SourcesProxyModel( m_model, this );
connect( m_proxyModel, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequest( QModelIndex ) ), Qt::QueuedConnection ); connect( m_proxyModel, SIGNAL( selectRequest( QPersistentModelIndex ) ), this, SLOT( selectRequest( QPersistentModelIndex ) ) );
connect( m_proxyModel, SIGNAL( expandRequest( QModelIndex ) ), this, SLOT( expandRequest( QModelIndex ) ), Qt::QueuedConnection ); connect( m_proxyModel, SIGNAL( expandRequest( QPersistentModelIndex ) ), this, SLOT( expandRequest( QPersistentModelIndex ) ) );
setModel( m_proxyModel ); setModel( m_proxyModel );
@@ -243,8 +243,9 @@ SourceTreeView::onItemExpanded( const QModelIndex& idx )
void 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 ) ) if ( !selectionModel()->selectedIndexes().contains( idx ) )
{ {
scrollTo( idx, QTreeView::EnsureVisible ); scrollTo( idx, QTreeView::EnsureVisible );
@@ -253,9 +254,9 @@ SourceTreeView::selectRequest( const QModelIndex& idx )
} }
void 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 ); expand( idx );
} }

View File

@@ -48,8 +48,8 @@ signals:
private slots: private slots:
void onItemExpanded( const QModelIndex& idx ); void onItemExpanded( const QModelIndex& idx );
void onItemActivated( const QModelIndex& index ); void onItemActivated( const QModelIndex& index );
void selectRequest( const QModelIndex& idx ); void selectRequest( const QPersistentModelIndex& idx );
void expandRequest( const QModelIndex& idx ); void expandRequest( const QPersistentModelIndex& idx );
void loadPlaylist(); void loadPlaylist();
void deletePlaylist( const QModelIndex& = QModelIndex() ); void deletePlaylist( const QModelIndex& = QModelIndex() );

View File

@@ -389,6 +389,7 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" ); qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" );
qRegisterMetaType< DirLister::Mode >("DirLister::Mode"); qRegisterMetaType< DirLister::Mode >("DirLister::Mode");
qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" );
} }

View File

@@ -145,5 +145,7 @@ private:
QxtHttpSessionManager m_session; QxtHttpSessionManager m_session;
}; };
Q_DECLARE_METATYPE( QPersistentModelIndex );
#endif // TOMAHAWKAPP_H #endif // TOMAHAWKAPP_H