]> git.sesse.net Git - vlc/commitdiff
QT: move sortingIndicator to correct position when columns are added/removed
authorIlkka Ollakka <ileoo@videolan.org>
Sun, 2 Aug 2009 15:06:14 +0000 (18:06 +0300)
committerIlkka Ollakka <ileoo@videolan.org>
Sun, 2 Aug 2009 15:52:25 +0000 (18:52 +0300)
This should be more clearer to user what column is used to sort (eg if
it's hidden, then hide sortIndicator also).

modules/gui/qt4/components/playlist/panels.hpp
modules/gui/qt4/components/playlist/playlist_model.cpp
modules/gui/qt4/components/playlist/playlist_model.hpp
modules/gui/qt4/components/playlist/standardpanel.cpp

index 18915649393a3c8f8e81a471736b385c9e19508c..6876f0c03598b09e4e4686d77292d7f68aaaecd0 100644 (file)
@@ -90,6 +90,7 @@ private slots:
     void setCurrentRootId( int );
     void popupAdd();
     void popupSelectColumn( QPoint );
+    void checkSortingIndicator( int );
 };
 
 #endif
index 6a47ad7b316e033ae38a91a2ac9489bf1594638d..87de8a03677b7a8c744216bd2c310a1a1858f5a7 100644 (file)
@@ -873,6 +873,7 @@ void PLModel::viewchanged( int meta )
             rootItem->updateColumnHeaders();
             endInsertColumns();
         }
+        emit columnsChanged( meta );
         rebuild();
     }
 }
index a28c3a8dbb45a07e113b41352eb2a9ce07ce70c8..d4c2e4e9004a3aab08ad54bf42b024eaf959ba33 100644 (file)
@@ -168,6 +168,7 @@ private:
 signals:
     void shouldRemove( int );
     void currentChanged( const QModelIndex& );
+    void columnsChanged( int );
 
 
 public slots:
index 3178c7db864c4ae9e1c95291d98129f4135d969a..43b656d70462bbbb685117ff191fa2f598c92ff0 100644 (file)
@@ -100,6 +100,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 ) );
@@ -257,14 +259,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 )
     {
@@ -276,6 +322,8 @@ void StandardPLPanel::popupSelectColumn( QPoint pos )
         CONNECT( option, triggered(), ContextUpdateMapper, map() );
     }
 
+    CONNECT( ContextUpdateMapper, mapped( int ),  model, viewchanged( int ) );
+
     selectColMenu.exec( QCursor::pos() );
 }