mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
* Change PlayableProxyModelPlaylistInterface's currentIndex when the underlying model's has changed.
This commit is contained in:
@@ -39,6 +39,7 @@ PlayableProxyModelPlaylistInterface::PlayableProxyModelPlaylistInterface( Playab
|
|||||||
connect( proxyModel, SIGNAL( indexPlayable( QModelIndex ) ), SLOT( onItemsChanged() ) );
|
connect( proxyModel, SIGNAL( indexPlayable( QModelIndex ) ), SLOT( onItemsChanged() ) );
|
||||||
connect( proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onItemsChanged() ) );
|
connect( proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onItemsChanged() ) );
|
||||||
connect( proxyModel, SIGNAL( itemCountChanged( unsigned int ) ), SLOT( onItemsChanged() ) );
|
connect( proxyModel, SIGNAL( itemCountChanged( unsigned int ) ), SLOT( onItemsChanged() ) );
|
||||||
|
connect( proxyModel, SIGNAL( currentIndexChanged() ), SLOT( onCurrentIndexChanged() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,6 +84,16 @@ PlayableProxyModelPlaylistInterface::tracks() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableProxyModelPlaylistInterface::onCurrentIndexChanged()
|
||||||
|
{
|
||||||
|
if ( m_proxyModel.data()->currentIndex().isValid() )
|
||||||
|
setCurrentIndex( (qint64) m_proxyModel.data()->mapToSource( m_proxyModel.data()->currentIndex() ).internalPointer() );
|
||||||
|
else
|
||||||
|
setCurrentIndex( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlayableProxyModelPlaylistInterface::setCurrentIndex( qint64 index )
|
PlayableProxyModelPlaylistInterface::setCurrentIndex( qint64 index )
|
||||||
{
|
{
|
||||||
@@ -90,12 +101,14 @@ PlayableProxyModelPlaylistInterface::setCurrentIndex( qint64 index )
|
|||||||
if ( m_proxyModel.isNull() )
|
if ( m_proxyModel.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PlayableItem* item = static_cast<PlayableItem*>( (void*)index );
|
if ( m_currentIndex == index )
|
||||||
if ( index < 0 || !item )
|
return;
|
||||||
{
|
m_currentIndex = index; // we need to manually set m_currentIndex (protected member from PlaylistInterface) here
|
||||||
m_proxyModel.data()->setCurrentIndex( QModelIndex() );
|
// because calling m_proxyModel.data()->setCurrentIndex( ... ) will end up emitting a
|
||||||
}
|
// signal which leads right back here and would cause an infinite loop.
|
||||||
else
|
|
||||||
|
PlayableItem* item = reinterpret_cast<PlayableItem*>( (void*)index );
|
||||||
|
if ( index >= 0 && item )
|
||||||
{
|
{
|
||||||
if ( m_shuffled && m_shuffleHistory.count() > 1 )
|
if ( m_shuffled && m_shuffleHistory.count() > 1 )
|
||||||
{
|
{
|
||||||
@@ -195,7 +208,7 @@ PlayableProxyModelPlaylistInterface::siblingIndex( int itemsAway, qint64 rootInd
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PlayableItem* pitem = static_cast<PlayableItem*>( (void*)rootIndex );
|
PlayableItem* pitem = reinterpret_cast<PlayableItem*>( (void*)rootIndex );
|
||||||
if ( !pitem || !pitem->index.isValid() )
|
if ( !pitem || !pitem->index.isValid() )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -259,7 +272,7 @@ PlayableProxyModelPlaylistInterface::queryAt( qint64 index ) const
|
|||||||
if ( m_proxyModel.isNull() )
|
if ( m_proxyModel.isNull() )
|
||||||
return query_ptr();
|
return query_ptr();
|
||||||
|
|
||||||
PlayableItem* item = static_cast<PlayableItem*>( (void*)index );
|
PlayableItem* item = reinterpret_cast<PlayableItem*>( (void*)index );
|
||||||
if ( item && item->query() )
|
if ( item && item->query() )
|
||||||
return item->query();
|
return item->query();
|
||||||
|
|
||||||
@@ -273,7 +286,7 @@ PlayableProxyModelPlaylistInterface::resultAt( qint64 index ) const
|
|||||||
if ( m_proxyModel.isNull() )
|
if ( m_proxyModel.isNull() )
|
||||||
return result_ptr();
|
return result_ptr();
|
||||||
|
|
||||||
PlayableItem* item = static_cast<PlayableItem*>( (void*)index );
|
PlayableItem* item = reinterpret_cast<PlayableItem*>( (void*)index );
|
||||||
if ( item && item->result() )
|
if ( item && item->result() )
|
||||||
return item->result();
|
return item->result();
|
||||||
|
|
||||||
|
@@ -61,9 +61,8 @@ public slots:
|
|||||||
virtual void setRepeatMode( Tomahawk::PlaylistModes::RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
|
virtual void setRepeatMode( Tomahawk::PlaylistModes::RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); }
|
||||||
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
|
virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); }
|
||||||
|
|
||||||
signals:
|
private slots:
|
||||||
void previousTrackAvailable();
|
void onCurrentIndexChanged();
|
||||||
void nextTrackAvailable();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QWeakPointer< PlayableProxyModel > m_proxyModel;
|
QWeakPointer< PlayableProxyModel > m_proxyModel;
|
||||||
|
Reference in New Issue
Block a user