]> git.sesse.net Git - vlc/commitdiff
Qt4: implement PLModel::popupSort[Asc/Desc]()
authorJakob Leben <jleben@videolan.org>
Tue, 18 Aug 2009 16:11:11 +0000 (18:11 +0200)
committerJakob Leben <jleben@videolan.org>
Tue, 18 Aug 2009 16:11:11 +0000 (18:11 +0200)
Implement recursive sorting of a single playlist node from popup menu,
in either ascending or descending order. Node is sorted by values in
column which was right clicked to bring up the popup menu.

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

index 7fc6fe8f1ba22a2955b9ec445f788939dd2bc0e7..9cf25095ecaffbb1f6f6e03ddadfb746d0786d0d 100644 (file)
@@ -891,6 +891,11 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
 
 /******* Volume III: Sorting and searching ********/
 void PLModel::sort( int column, Qt::SortOrder order )
+{
+    sort( rootItem->i_id, column, order );
+}
+
+void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
 {
     int i_index = -1;
     int i_flag = 0;
@@ -912,7 +917,7 @@ next:
     PL_LOCK;
     {
         playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
-                                                        rootItem->i_id );
+                                                        i_root_id );
         if( p_root && i_flag )
         {
             playlist_RecursiveNodeSort( p_playlist, p_root,
@@ -946,6 +951,7 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
     int i_id;
     if( index.isValid() ) i_id = itemId( index );
     else i_id = rootItem->i_id;
+    i_popup_column = index.column();
     PL_LOCK;
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
     if( p_item )
@@ -979,8 +985,11 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
             menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
             if( node )
             {
+                QMenu *sort_menu = new QMenu( qtr(I_POP_SORT) );
+                sort_menu->addAction( qtr( "Ascending" ), this, SLOT( popupSortAsc() ) );
+                sort_menu->addAction( qtr( "Descending" ), this, SLOT( popupSortDesc() ) );
                 menu->addSeparator();
-                menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
+                menu->addMenu( sort_menu );
             }
         }
         if( node && tree )
@@ -1137,6 +1146,16 @@ void PLModel::popupAddNode()
     }
     PL_UNLOCK;
 }
+
+void PLModel::popupSortAsc()
+{
+    sort( i_popup_item, i_popup_column, Qt::AscendingOrder );
+}
+
+void PLModel::popupSortDesc()
+{
+    sort( i_popup_item, i_popup_column, Qt::DescendingOrder );
+}
 /**********************************************************************
  * Playlist callbacks
  **********************************************************************/
index 41d93fd6e13bbc45eb4e39b9b554180810f72754..caa4386bdf131fee73b448d1eabb63a2e4916aeb 100644 (file)
@@ -116,6 +116,7 @@ public:
     void doDelete( QModelIndexList selected );
     void search( const QString& search_text );
     void sort( int column, Qt::SortOrder order );
+    void sort( int i_root_id, int column, Qt::SortOrder order );
     void removeItem( int );
 
     /* DnD handling */
@@ -155,7 +156,7 @@ private:
     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
 
     /* Popup */
-    int i_popup_item, i_popup_parent;
+    int i_popup_item, i_popup_parent, i_popup_column;
     QModelIndexList current_selection;
     QSignalMapper *ContextUpdateMapper;
 
@@ -188,6 +189,8 @@ private slots:
     void popupSave();
     void popupExplore();
     void popupAddNode();
+    void popupSortAsc();
+    void popupSortDesc();
     void viewchanged( int );
     void ProcessInputItemUpdate( input_item_t *);
     void ProcessInputItemUpdate( input_thread_t* p_input );