From: Ilkka Ollakka Date: Wed, 23 Jun 2010 09:42:08 +0000 (+0300) Subject: Qt4: cache currentItem index X-Git-Tag: 1.2.0-pre1~6089 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=0455f985986b54085f3651d1cfcdc7d53efda9c7;p=vlc Qt4: cache currentItem index Not sure if it's the best way, but this enables to show the current item even when input is stopped. --- diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp index ae6d7b7329..756ee00d0f 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.cpp +++ b/modules/gui/qt4/components/playlist/playlist_model.cpp @@ -73,6 +73,7 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */ i_cached_input_id = -1; i_popup_item = i_popup_parent = -1; sortingMenu = NULL; + current_index = QModelIndex(); rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */ @@ -98,6 +99,8 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */ this, processItemAppend( int, int ) ); CONNECT( THEMIM, playlistItemRemoved( int ), this, processItemRemoval( int ) ); + CONNECT( this, currentChanged( const QModelIndex &) , + this, cacheCurrent( const QModelIndex &) ); } PLModel::~PLModel() @@ -380,7 +383,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const bool PLModel::isCurrent( const QModelIndex &index ) const { - return getItem( index )->p_input == THEMIM->currentInputItem(); + return index == current_index; } int PLModel::itemId( const QModelIndex &index ) const @@ -429,12 +432,14 @@ QModelIndex PLModel::index( PLItem *item, int column ) const return QModelIndex(); } +void PLModel::cacheCurrent( const QModelIndex ¤t ) +{ + current_index = current; +} + QModelIndex PLModel::currentIndex() { - input_thread_t *p_input_thread = THEMIM->getInput(); - if( !p_input_thread ) return QModelIndex(); - PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id ); - return index( item, 0 ); + return current_index; } QModelIndex PLModel::parent( const QModelIndex &index ) const diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp index 494df32046..033cdc691a 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.hpp +++ b/modules/gui/qt4/components/playlist/playlist_model.hpp @@ -161,6 +161,7 @@ private: PLItem *p_cached_item_bi; int i_cached_id; int i_cached_input_id; + QModelIndex current_index; private slots: void popupPlay(); @@ -175,6 +176,7 @@ private slots: void processInputItemUpdate( input_thread_t* p_input ); void processItemRemoval( int i_id ); void processItemAppend( int item, int parent ); + void cacheCurrent( const QModelIndex & ); }; class PlMimeData : public QMimeData