[vlc-commits] Qt, selector: don't rebuild the model when not necessary...

Jean-Baptiste Kempf git at videolan.org
Tue May 10 01:20:44 CEST 2011


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Tue May 10 01:18:40 2011 +0200| [3ae42e74c0b1b3cf7004d0c14985ff25bf48aaa1] | committer: Jean-Baptiste Kempf

Qt, selector: don't rebuild the model when not necessary...

This should fix the build-twice-the-model issue and should avoid
rebuilding when clicking the already selected one.
Rebuilding the model is costly enough in time, to not do it all the
time.

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

 modules/gui/qt4/components/playlist/selector.cpp |   16 ++++++++++------
 modules/gui/qt4/components/playlist/selector.hpp |    1 +
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/selector.cpp b/modules/gui/qt4/components/playlist/selector.cpp
index 6eec384..1486513 100644
--- a/modules/gui/qt4/components/playlist/selector.cpp
+++ b/modules/gui/qt4/components/playlist/selector.cpp
@@ -129,16 +129,18 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf )
               this, inputItemUpdate( input_item_t * ) );
 
     createItems();
+
+    /***
+     * We need to react to both clicks and activation (enter-key) here.
+     * We use curItem to avoid rebuilding twice.
+     * See QStyle::SH_ItemView_ActivateItemOnSingleClick
+     ***/
+    curItem = NULL;
     CONNECT( this, itemActivated( QTreeWidgetItem *, int ),
              this, setSource( QTreeWidgetItem *) );
     CONNECT( this, itemClicked( QTreeWidgetItem *, int ),
              this, setSource( QTreeWidgetItem *) );
 
-    /* I believe this is unnecessary, seeing
-       QStyle::SH_ItemView_ActivateItemOnSingleClick
-        CONNECT( view, itemClicked( QTreeWidgetItem *, int ),
-             this, setSource( QTreeWidgetItem *) ); */
-
     /* select the first item */
 //  view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
 
@@ -258,9 +260,11 @@ void PLSelector::createItems()
 
 void PLSelector::setSource( QTreeWidgetItem *item )
 {
-    if( !item )
+    if( !item || item == curItem )
         return;
 
+    curItem = item;
+
     bool b_ok;
     int i_type = item->data( 0, TYPE_ROLE ).toInt( &b_ok );
     if( !b_ok || i_type == CATEGORY_TYPE )
diff --git a/modules/gui/qt4/components/playlist/selector.hpp b/modules/gui/qt4/components/playlist/selector.hpp
index a9a3d42..acdc476 100644
--- a/modules/gui/qt4/components/playlist/selector.hpp
+++ b/modules/gui/qt4/components/playlist/selector.hpp
@@ -135,6 +135,7 @@ private:
     intf_thread_t    *p_intf;
     QTreeWidgetItem  *podcastsParent;
     int               podcastsParentId;
+    QTreeWidgetItem  *curItem;
 
 private slots:
     void setSource( QTreeWidgetItem *item );



More information about the vlc-commits mailing list