[vlc-devel] commit: QT: move sortingIndicator to correct position when columns are added/removed ( Ilkka Ollakka )

git version control git at videolan.org
Mon Aug 3 12:48:22 CEST 2009


vlc | branch: 1.0-bugfix | Ilkka Ollakka <ileoo at videolan.org> | Sun Aug  2 18:06:14 2009 +0300| [86174f841c6fe5cca4f25fecf46d0378f0537034] | committer: Ilkka Ollakka 

QT: move sortingIndicator to correct position when columns are added/removed

This should be more clearer to user what column is used to sort (eg if
it's hidden, then hide sortIndicator also).
(cherry picked from commit 9577d830528cbfd80a8dd001a4cf02f6832246a0)

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

 modules/gui/qt4/components/playlist/panels.hpp     |    1 +
 .../gui/qt4/components/playlist/playlist_model.cpp |    1 +
 .../gui/qt4/components/playlist/playlist_model.hpp |    1 +
 .../gui/qt4/components/playlist/standardpanel.cpp  |   52 +++++++++++++++++++-
 4 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/panels.hpp b/modules/gui/qt4/components/playlist/panels.hpp
index 1891564..6876f0c 100644
--- a/modules/gui/qt4/components/playlist/panels.hpp
+++ b/modules/gui/qt4/components/playlist/panels.hpp
@@ -90,6 +90,7 @@ private slots:
     void setCurrentRootId( int );
     void popupAdd();
     void popupSelectColumn( QPoint );
+    void checkSortingIndicator( int );
 };
 
 #endif
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 1f756fc..d0fbd57 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -854,6 +854,7 @@ void PLModel::viewchanged( int meta )
             rootItem->updateColumnHeaders();
             endInsertColumns();
         }
+        emit columnsChanged( meta );
         rebuild();
     }
 }
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index a28c3a8..d4c2e4e 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -168,6 +168,7 @@ private:
 signals:
     void shouldRemove( int );
     void currentChanged( const QModelIndex& );
+    void columnsChanged( int );
 
 
 public slots:
diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index 3c02c66..5a65e81 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -104,6 +104,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
              this, popupSelectColumn( QPoint ) );
     CONNECT( model, currentChanged( const QModelIndex& ),
              this, handleExpansion( const QModelIndex& ) );
+    CONNECT( model, columnsChanged( int ),
+            this, checkSortingIndicator( int ) );
 
     currentRootId = -1;
     CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) );
@@ -260,14 +262,58 @@ void StandardPLPanel::popupAdd()
                         + QPoint( 0, addButton->height() ) );
 }
 
+/* Set sortingindicator to -1 if it's on column thats removed,
+ * else check that it's still showing on correct column
+ */
+void StandardPLPanel::checkSortingIndicator( int meta )
+{
+    int index=0;
+
+    if( view->header()->isSortIndicatorShown() == false )
+        return;
+
+    int sortIndex = view->header()->sortIndicatorSection();
+    if( sortIndex < 0 || sortIndex > view->header()->count() || meta == 0 )
+        return;
+
+    int _meta = meta;
+
+    while( _meta )
+    {
+        if( _meta & model->shownFlags() )
+            index++;
+        _meta >>= 1;
+    }
+
+    /* Adding column */
+    if( model->shownFlags() & meta )
+    {
+        /* If column is added before sortIndex, move it one to right*/
+        if( sortIndex >= index )
+        {
+            sortIndex += 1;
+        }
+    } else {
+        /* Column removed */
+        if( sortIndex == index )
+        {
+            sortIndex = -1;
+        } else if( sortIndex > index )
+        {
+            /* Move indicator left one step*/
+            sortIndex -= 1;
+        }
+    }
+    view->header()->setSortIndicator( sortIndex  ,
+                view->header()->sortIndicatorOrder() );
+}
+
 void StandardPLPanel::popupSelectColumn( QPoint pos )
 {
     ContextUpdateMapper = new QSignalMapper(this);
 
     QMenu selectColMenu;
 
-    CONNECT( ContextUpdateMapper, mapped( int ),  model, viewchanged( int ) );
-
     int i_column = 1;
     for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
     {
@@ -279,6 +325,8 @@ void StandardPLPanel::popupSelectColumn( QPoint pos )
         CONNECT( option, triggered(), ContextUpdateMapper, map() );
     }
 
+    CONNECT( ContextUpdateMapper, mapped( int ),  model, viewchanged( int ) );
+
     selectColMenu.exec( QCursor::pos() );
 }
 




More information about the vlc-devel mailing list