[vlc-commits] [Git][videolan/vlc][3.0.x] 3 commits: gui/qt: playlist_model: add sortInternal helper
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed Dec 8 14:44:43 UTC 2021
Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC
Commits:
7332d1f3 by Marvin Scholz at 2021-12-08T10:47:28+00:00
gui/qt: playlist_model: add sortInternal helper
Moves all relevant sorting logic into the new helper function
that exposes the arguments to playlist_RecursiveNodeSort
directly, need to use sort orders that are not linked to any
column.
- - - - -
0a8fe556 by Marvin Scholz at 2021-12-08T10:47:28+00:00
gui/qt: playlist_model: add action to shuffle playlist
- - - - -
aac177ee by Marvin Scholz at 2021-12-08T10:47:28+00:00
gui/qt: standardpanel: add menu item to shuffle playlist
- - - - -
4 changed files:
- modules/gui/qt/components/playlist/playlist_model.cpp
- modules/gui/qt/components/playlist/playlist_model.hpp
- modules/gui/qt/components/playlist/standardpanel.cpp
- modules/gui/qt/components/playlist/vlc_model.hpp
Changes:
=====================================
modules/gui/qt/components/playlist/playlist_model.cpp
=====================================
@@ -804,6 +804,14 @@ void PLModel::recurseDelete( QList<AbstractPLItem*> children, QModelIndexList *f
}
/******* Volume III: Sorting and searching ********/
+void PLModel::shuffle()
+{
+ msg_Dbg( p_intf, "Shuffling playlist items");
+
+ sortInternal( indexByPLID( rootItem->id(), 0 ),
+ SORT_RANDOM, ORDER_NORMAL );
+}
+
void PLModel::sort( const int column, Qt::SortOrder order )
{
sort( QModelIndex(), indexByPLID( rootItem->id(), 0 ) , column, order );
@@ -816,14 +824,31 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column,
int meta = columnToMeta( column );
if( meta == COLUMN_END || meta == COLUMN_COVER ) return;
- PLItem *item = ( rootIndex.isValid() ) ? getItem( rootIndex )
- : rootItem;
- if( !item ) return;
-
input_item_t* p_caller_item = caller.isValid()
? static_cast<AbstractPLItem*>( caller.internalPointer() )->inputItem()
: NULL;
+ sortInternal( rootIndex, i_column_sorting( meta ),
+ order == Qt::AscendingOrder ?
+ ORDER_NORMAL : ORDER_REVERSE );
+
+ /* if we have popup item, try to make sure that you keep that item visible */
+ if( p_caller_item )
+ {
+ QModelIndex idx = indexByInputItem( p_caller_item, 0 );
+
+ emit currentIndexChanged( idx );
+ }
+ else if( currentIndex().isValid() )
+ emit currentIndexChanged( currentIndex() );
+}
+
+void PLModel::sortInternal( QModelIndex rootIndex, int mode, int type )
+{
+ PLItem *item = ( rootIndex.isValid() ) ? getItem( rootIndex )
+ : rootItem;
+ if( !item ) return;
+
int i_root_id = item->id();
QModelIndex qIndex = index( item, 0 );
@@ -842,10 +867,7 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column,
i_root_id );
if( p_root )
{
- playlist_RecursiveNodeSort( p_playlist, p_root,
- i_column_sorting( meta ),
- order == Qt::AscendingOrder ?
- ORDER_NORMAL : ORDER_REVERSE );
+ playlist_RecursiveNodeSort( p_playlist, p_root, mode, type );
}
if( count )
@@ -855,16 +877,6 @@ void PLModel::sort( QModelIndex caller, QModelIndex rootIndex, const int column,
endInsertRows( );
}
}
-
- /* if we have popup item, try to make sure that you keep that item visible */
- if( p_caller_item )
- {
- QModelIndex idx = indexByInputItem( p_caller_item, 0 );
-
- emit currentIndexChanged( idx );
- }
- else if( currentIndex().isValid() )
- emit currentIndexChanged( currentIndex() );
}
void PLModel::filter( const QString& search_text, const QModelIndex & idx, bool b_recursive )
@@ -986,6 +998,10 @@ bool PLModel::action( QAction *action, const QModelIndexList &indexes )
doDelete( indexes );
return true;
+ case ACTION_SHUFFLE:
+ shuffle();
+ return true;
+
case ACTION_SORT:
if ( !indexes.empty() )
index = indexes.first();
@@ -1037,6 +1053,7 @@ bool PLModel::isSupportedAction( actions action, const QModelIndex &index ) cons
/* Only if we are not already in Current Playing */
return getPLRootType() != ROOTTYPE_CURRENT_PLAYING;
case ACTION_SORT:
+ case ACTION_SHUFFLE:
return rowCount();
case ACTION_PLAY:
{
=====================================
modules/gui/qt/components/playlist/playlist_model.hpp
=====================================
@@ -87,6 +87,7 @@ public:
QStringList mimeTypes() const Q_DECL_OVERRIDE;
/* Sort */
+ void shuffle();
void sort( const int column, Qt::SortOrder order = Qt::AscendingOrder ) Q_DECL_OVERRIDE;
/*** VLCModelSubInterface subclassing ***/
@@ -138,6 +139,7 @@ private:
void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
/* */
+ void sortInternal( QModelIndex rootIndex, int mode, int type );
void sort( QModelIndex caller, QModelIndex rootIndex, const int column, Qt::SortOrder order );
/* Lookups */
=====================================
modules/gui/qt/components/playlist/standardpanel.cpp
=====================================
@@ -268,6 +268,11 @@ bool StandardPLPanel::popup( const QPoint &point )
}
menu.addMenu( sortingMenu );
}
+ if ( model->isSupportedAction( VLCModelSubInterface::ACTION_SHUFFLE, index ) )
+ {
+ ADD_MENU_ENTRY( QIcon(), qtr("Shuffle playlist"),
+ VLCModelSubInterface::ACTION_SHUFFLE );
+ }
/* Zoom */
QMenu *zoomMenu = new QMenu( qtr( "Display size" ), &menu );
=====================================
modules/gui/qt/components/playlist/vlc_model.hpp
=====================================
@@ -95,7 +95,8 @@ public:
ACTION_ENQUEUEFILE,
ACTION_ENQUEUEDIR,
ACTION_ENQUEUEGENERIC,
- ACTION_SAVETOPLAYLIST
+ ACTION_SAVETOPLAYLIST,
+ ACTION_SHUFFLE
};
struct actionsContainerType
{
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/42cf4c4ce7f52aecb9fda3b166c1fb23e9ff8a18...aac177eea60de1fc4498abc7e1a998723ac04e32
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/42cf4c4ce7f52aecb9fda3b166c1fb23e9ff8a18...aac177eea60de1fc4498abc7e1a998723ac04e32
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list