[vlc-commits] qml: enqueue in playlist using selected index

Pierre Lamot git at videolan.org
Wed Jun 3 12:06:39 CEST 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Tue Feb 25 15:31:03 2020 +0100| [0c06121407aaeb95aa913df6ad02bde14b163726] | committer: Pierre Lamot

qml: enqueue in playlist using selected index

  this allows decoupling from the DelegateModel

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

 modules/gui/qt/medialibrary/qml/MusicAlbums.qml    |  7 ++---
 modules/gui/qt/medialibrary/qml/MusicGenres.qml    |  5 +---
 .../qt/medialibrary/qml/MusicTrackListDisplay.qml  |  8 +-----
 modules/gui/qt/medialibrary/qml/VideoDisplay.qml   |  5 +---
 .../gui/qt/medialibrary/qml/VideoListDisplay.qml   |  9 ++----
 modules/gui/qt/network/networkmediamodel.cpp       | 32 ++++++++++++++--------
 .../gui/qt/network/qml/NetworkBrowseDisplay.qml    |  7 +++--
 .../qt/network/qml/NetworksSectionSelectableDM.qml | 22 ++-------------
 .../gui/qt/util/qml/SelectableDelegateModel.qml    |  9 ++++++
 .../gui/qt/widgets/qml/KeyNavigableTableView.qml   |  4 +--
 10 files changed, 45 insertions(+), 63 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index a6f6785414..8d35835f7e 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -117,12 +117,9 @@ Widgets.NavigableFocusScope {
 
         function actionAtIndex(index) {
             if (delegateModelId.selectedGroup.count > 1) {
-                var list = []
-                for (var i = 0; i < delegateModelId.selectedGroup.count; i++)
-                    list.push(delegateModelId.selectedGroup.get(i).model.id)
-                medialib.addAndPlay( list )
+                medialib.addAndPlay( model.getIdsForIndexes( delegateModelId.selectedIndexes() ) )
             } else {
-                medialib.addAndPlay( delegateModelId.items.get(index).model.id )
+                medialib.addAndPlay( model.getIdsForIndexes([index]) )
             }
         }
     }
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index 49f0bd493b..ca06179e5c 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -133,10 +133,7 @@ Widgets.NavigableFocusScope {
 
         function actionAtIndex(index) {
             if (delegateModelId.selectedGroup.count > 1) {
-                var list = []
-                for (var i = 0; i < delegateModelId.selectedGroup.count; i++)
-                    list.push(delegateModelId.selectedGroup.get(i).model.id)
-                medialib.addAndPlay( list )
+                medialib.addAndPlay(model.getIdsForIndexes(delegateModelId.selectedIndexes()))
             } else if (delegateModelId.selectedGroup.count === 1) {
                 showAlbumView(delegateModelId.selectedGroup.get(0).model.id, delegateModelId.selectedGroup.get(0).model.name)
             }
diff --git a/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
index be67b9c069..17fc26f7f8 100644
--- a/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
@@ -83,11 +83,5 @@ Widgets.KeyNavigableTableView {
         }
     }
 
-    onActionForSelection: {
-        var list = []
-        for (var i = 0; i < selection.count; i++ ) {
-            list.push(selection.get(i).model.id)
-        }
-        medialib.addAndPlay(list)
-    }
+    onActionForSelection:  medialib.addAndPlay(model.getIdsForIndexes( selection ))
 }
diff --git a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
index 23c370b7ea..d0fd13fe1c 100644
--- a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
@@ -131,10 +131,7 @@ Widgets.NavigableFocusScope {
         }
 
         function actionAtIndex(index) {
-            var list = []
-            for (var i = 0; i < videosDelegate.selectedGroup.count; i++)
-                list.push(videosDelegate.selectedGroup.get(i).model.id)
-            medialib.addAndPlay( list )
+            medialib.addAndPlay( videoModel.getIdsForIndexes( videosDelegate.selectedIndexes() ) )
             history.push(["player"])
         }
     }
diff --git a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
index aabfc6b579..8528b6f108 100644
--- a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
@@ -135,13 +135,8 @@ Widgets.KeyNavigableTableView {
     headerColor: VLCStyle.colors.bg
     spacing: VLCStyle.margin_small
 
-    onActionForSelection: {
-        var list = []
-        for (var i = 0; i < selection.count; i++ ) {
-            list.push(selection.get(i).model.id)
-        }
-        medialib.addAndPlay(list)
-    }
+    onActionForSelection: medialib.addAndPlay(model.getIdsForIndexes( selection ))
+
     navigationLeft:  function(index) {
         if (isFocusOnContextButton )
             isFocusOnContextButton = false
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index 1e44d7476d..1bfa2cfefc 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -198,11 +198,16 @@ bool NetworkMediaModel::addToPlaylist(const QVariantList &itemIdList)
     bool ret = false;
     for (const QVariant& varValue: itemIdList)
     {
+        int index = -1;
+
         if (varValue.canConvert<int>())
-        {
-            auto index = varValue.value<int>();
-            ret |= addToPlaylist(index);
-        }
+            index = varValue.value<int>();
+        else if (varValue.canConvert<QModelIndex>())
+            index = varValue.value<QModelIndex>().row();
+        else
+            continue;
+
+        ret |= addToPlaylist(index);
     }
     return ret;
 }
@@ -224,14 +229,19 @@ bool NetworkMediaModel::addAndPlay(const QVariantList& itemIdList)
     bool ret = false;
     for (const QVariant& varValue: itemIdList)
     {
+        int index = -1;
+
         if (varValue.canConvert<int>())
-        {
-            auto index = varValue.value<int>();
-            if (!ret)
-                ret |= addAndPlay(index);
-            else
-                ret |= addToPlaylist(index);
-        }
+            index = varValue.value<int>();
+        else if (varValue.canConvert<QModelIndex>())
+            index = varValue.value<QModelIndex>().row();
+        else
+            continue;
+
+        if (!ret)
+            ret |= addAndPlay(index);
+        else
+            ret |= addToPlaylist(index);
     }
     return ret;
 }
diff --git a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
index 305fed3307..effe203786 100644
--- a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
@@ -66,13 +66,14 @@ Widgets.NavigableFocusScope {
             property var modelActions: {
                 "play": function() {
                     if (delegateModelId) {
-                        delegateModelId.playSelection()
+                        providerModel.addAndPlay(delegateModelId.selectedIndexes())
                     }
                     contextMenu.close()
                 },
                 "enqueue": function() {
-                    if (delegateModelId)
-                        delegateModelId.enqueueSelection()
+                    if (delegateModelId) {
+                        providerModel.addToPlaylist(delegateModelId.selectedIndexes())
+                    }
                     contextMenu.close()
                 },
                 "index": function(index) {
diff --git a/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml b/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml
index 5d3da53551..8ca62b32ad 100644
--- a/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml
+++ b/modules/gui/qt/network/qml/NetworksSectionSelectableDM.qml
@@ -99,33 +99,15 @@ Util.SelectableDelegateModel {
         }
     }
 
-    function playSelection() {
-        var list = []
-        for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
-            var index = delegateModel.selectedGroup.get(i).itemsIndex;
-            list.push(index)
-        }
-        delegateModel.model.addAndPlay( list )
-    }
-
-    function enqueueSelection() {
-        var list = []
-        for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
-            var index = delegateModel.selectedGroup.get(i).itemsIndex;
-            list.push(index)
-        }
-        delegateModel.model.addToPlaylist( list )
-    }
-
     function actionAtIndex(index) {
         if ( delegateModel.selectedGroup.count > 1 ) {
-            playSelection()
+            model.addAndPlay( delegateModel.selectedIndexes() )
         } else {
             if (delegateModel.items.get(index).model.type === NetworkMediaModel.TYPE_DIRECTORY
                     || delegateModel.items.get(index).model.type === NetworkMediaModel.TYPE_NODE)  {
                 history.push(["mc", "network", { tree: delegateModel.items.get(index).model.tree }]);
             } else {
-                playSelection()
+                model.addAndPlay( delegateModel.selectedIndexes() )
             }
         }
     }
diff --git a/modules/gui/qt/util/qml/SelectableDelegateModel.qml b/modules/gui/qt/util/qml/SelectableDelegateModel.qml
index 6a18d39611..fa545f04eb 100644
--- a/modules/gui/qt/util/qml/SelectableDelegateModel.qml
+++ b/modules/gui/qt/util/qml/SelectableDelegateModel.qml
@@ -49,6 +49,15 @@ DelegateModel {
         delegateModel.items.addGroups(0, delegateModel.items.count, ["selected"])
     }
 
+    function selectedIndexes() {
+        var list = []
+        for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
+            var index = delegateModel.selectedGroup.get(i).itemsIndex;
+            list.push(index)
+        }
+        return list
+    }
+
     function updateSelection( keymodifiers, oldIndex, newIndex ) {
         if ((keymodifiers & Qt.ShiftModifier)) {
             if ( shiftIndex === oldIndex) {
diff --git a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
index c96013f719..c5a7247ceb 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
@@ -94,7 +94,7 @@ NavigableFocusScope {
                     }
 
                     onDoubleClicked: {
-                        actionForSelection(delegateModel.selectedGroup)
+                        actionForSelection(delegateModel.selectedIndexes())
                     }
 
                         Row {
@@ -213,7 +213,7 @@ NavigableFocusScope {
 
         onSelectAll: delegateModel.selectAll()
         onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
-        onActionAtIndex: root.actionForSelection( delegateModel.selectedGroup )
+        onActionAtIndex: root.actionForSelection( delegateModel.selectedIndexes() )
 
         navigationParent: root
     }



More information about the vlc-commits mailing list