1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +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;
if ( !m_playlistViews.contains( playlist ) || !m_playlistViews.value( playlist ).isNull() )
if ( !m_playlistViews.contains( playlist ) || m_playlistViews.value( playlist ).isNull() )
{
view = createPageForPlaylist( playlist );
}
@@ -747,11 +747,11 @@ ViewManager::onWidgetDestroyed( QWidget* widget )
{
ViewPage* page = m_pageHistory.at( i );
if ( !playlistForInterface( page->playlistInterface() ).isNull() )
if ( playlistForInterface( page->playlistInterface() ).isNull() )
{
m_playlistViews.remove( playlistForInterface( page->playlistInterface() ) );
}
if ( !dynamicPlaylistForInterface( page->playlistInterface() ).isNull() )
if ( dynamicPlaylistForInterface( page->playlistInterface() ).isNull() )
{
m_dynamicWidgets.remove( dynamicPlaylistForInterface( page->playlistInterface() ) );
}

View File

@@ -283,7 +283,7 @@ SourcesModel::viewPageActivated( Tomahawk::ViewPage* page )
if ( !idx.isValid() )
m_sourceTreeLinks.remove( page );
else
emit selectRequest( idx );
emit selectRequest( QPersistentModelIndex( idx ) );
}
else
{
@@ -420,7 +420,7 @@ SourcesModel::linkSourceItemToPage( SourceTreeItem* item, ViewPage* p )
m_sourceTreeLinks[ p ] = item;
if( m_viewPageDelayedCacheItem == p )
emit selectRequest( indexFromItem( item ) );
emit selectRequest( QPersistentModelIndex( indexFromItem( item ) ) );
if ( QObject* obj = dynamic_cast< QObject* >( p ) )
{
@@ -517,12 +517,12 @@ SourcesModel::rowForItem( SourceTreeItem* item ) const
void
SourcesModel::itemSelectRequest( SourceTreeItem* item )
{
emit selectRequest( indexFromItem( item ) );
emit selectRequest( QPersistentModelIndex( indexFromItem( item ) ) );
}
void
SourcesModel::itemExpandRequest( SourceTreeItem *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 );
signals:
void selectRequest( const QModelIndex& idx );
void expandRequest( const QModelIndex& idx );
void selectRequest( const QPersistentModelIndex& idx );
void expandRequest( const QPersistentModelIndex& idx );
private slots:
void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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