From 96b9f38b2e0bc24ee52af1e51a235345d7eeda13 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 23 Dec 2012 08:12:49 +0100 Subject: [PATCH] * Reset PlayableModel's currentIndex when it gets removed from the model. --- src/libtomahawk/playlist/PlayableModel.cpp | 7 ++++++- src/libtomahawk/playlist/PlayableModel.h | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index c78872f01..76f4d2016 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -312,7 +312,7 @@ PlayableModel::headerData( int section, Qt::Orientation orientation, int role ) void -PlayableModel::setCurrentItem( const QModelIndex& index ) +PlayableModel::setCurrentIndex( const QModelIndex& index ) { PlayableItem* oldEntry = itemFromIndex( m_currentIndex ); if ( oldEntry ) @@ -332,6 +332,8 @@ PlayableModel::setCurrentItem( const QModelIndex& index ) m_currentIndex = QModelIndex(); m_currentUuid = QString(); } + + emit currentIndexChanged(); } @@ -596,6 +598,9 @@ PlayableModel::removeIndex( const QModelIndex& index, bool moreToCome ) PlayableItem* item = itemFromIndex( index ); if ( item ) { + if ( index == m_currentIndex ) + setCurrentIndex( QModelIndex() ); + emit beginRemoveRows( index.parent(), index.row(), index.row() ); delete item; emit endRemoveRows(); diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index c0b1810ed..56b5836b3 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -123,8 +123,10 @@ signals: void indexPlayable( const QModelIndex& index ); void changed(); + void currentIndexChanged(); + public slots: - virtual void setCurrentItem( const QModelIndex& index ); + virtual void setCurrentIndex( const QModelIndex& index ); virtual void clear();