[vlc-commits] commit: Qt4: cache currentItem index (Ilkka Ollakka )

git at videolan.org git at videolan.org
Wed Jun 23 11:52:45 CEST 2010


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Wed Jun 23 12:42:08 2010 +0300| [0455f985986b54085f3651d1cfcdc7d53efda9c7] | committer: Ilkka Ollakka 

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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0455f985986b54085f3651d1cfcdc7d53efda9c7
---

 .../gui/qt4/components/playlist/playlist_model.cpp |   15 ++++++++++-----
 .../gui/qt4/components/playlist/playlist_model.hpp |    2 ++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index ae6d7b7..756ee00 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 &current )
+{
+    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 494df32..033cdc6 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



More information about the vlc-commits mailing list