[vlc-devel] [PATCH 04/16] qml: expose Selection API in SelectableDelegate model

Pierre Lamot pierre at videolabs.io
Wed May 27 17:06:45 CEST 2020


  it follows ItemSelectionModel select API
---
 .../gui/qt/medialibrary/qml/MusicAlbums.qml   |  3 +--
 .../medialibrary/qml/MusicArtistsDisplay.qml  |  3 +--
 .../gui/qt/medialibrary/qml/MusicGenres.qml   |  5 ++---
 .../gui/qt/medialibrary/qml/VideoDisplay.qml  |  5 ++---
 .../qt/network/qml/NetworkBrowseDisplay.qml   |  2 +-
 .../qt/util/qml/SelectableDelegateModel.qml   | 22 +++++++++++++++++++
 .../qt/widgets/qml/KeyNavigableTableView.qml  |  2 +-
 7 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index 8d35835f7e..16ab1375c9 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -66,8 +66,7 @@ Widgets.NavigableFocusScope {
         var initialIndex = root.initialIndex
         if (initialIndex >= delegateModelId.items.count)
             initialIndex = 0
-        delegateModelId.selectNone()
-        delegateModelId.items.get(initialIndex).inSelected = true
+        delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
         view.currentItem.currentIndex = initialIndex
         view.currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
     }
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index e6164c6e20..73badd0960 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -54,8 +54,7 @@ Widgets.NavigableFocusScope {
         if (initialIndex >= delegateModel.items.count)
             initialIndex = 0
         if (initialIndex !== artistList.currentIndex) {
-            delegateModel.selectNone()
-            delegateModel.items.get(initialIndex).inSelected = true
+            delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
             artistList.currentIndex = initialIndex
             artistList.positionViewAtIndex(initialIndex, ItemView.Contain)
         }
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index ca06179e5c..7c1a1fb9a1 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -66,8 +66,7 @@ Widgets.NavigableFocusScope {
         var initialIndex = root.initialIndex
         if (initialIndex >= delegateModelId.items.count)
             initialIndex = 0
-        delegateModelId.selectNone()
-        delegateModelId.items.get(initialIndex).inSelected = true
+        delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
         view.currentItem.currentIndex = initialIndex
         view.currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
     }
@@ -150,7 +149,7 @@ Widgets.NavigableFocusScope {
             var initialIndex = 0
             if (view.currentItem.currentIndex !== -1)
                 initialIndex = view.currentItem.currentIndex
-            delegateModelId.items.get(initialIndex).inSelected = true
+            delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
             view.currentItem.currentIndex = initialIndex
         }
     }
diff --git a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
index d0fd13fe1c..5dc91a0028 100644
--- a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
@@ -57,8 +57,7 @@ Widgets.NavigableFocusScope {
         var initialIndex = root.initialIndex
         if (initialIndex >= videosDelegate.items.count)
             initialIndex = 0
-        videosDelegate.selectNone()
-        videosDelegate.items.get(initialIndex).inSelected = true
+        videosDelegate.select(initialIndex, ItemSelectionModel.ClearAndSelect)
         view.currentItem.currentIndex = initialIndex
         view.currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
     }
@@ -193,7 +192,7 @@ Widgets.NavigableFocusScope {
              */
             onActiveFocusChanged: {
                 if (activeFocus && videosDelegate.items.count > 0 && !videosDelegate.hasSelection) {
-                    videosDelegate.items.get(0).inSelected = true
+                    videosDelegate.select(0, ItemSelectionModel.ClearAndSelect)
                 }
             }
 
diff --git a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
index effe203786..e8f5c5049d 100644
--- a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
@@ -49,7 +49,7 @@ Widgets.NavigableFocusScope {
             var initialIndex = 0
             if (delegateModelId.currentIndex !== -1)
                 initialIndex = delegateModelId.currentIndex
-            delegateModelId.items.get(initialIndex).inSelected = true
+            delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
             delegateModelId.currentIndex = initialIndex
         }
     }
diff --git a/modules/gui/qt/util/qml/SelectableDelegateModel.qml b/modules/gui/qt/util/qml/SelectableDelegateModel.qml
index fa545f04eb..af7fa67ce1 100644
--- a/modules/gui/qt/util/qml/SelectableDelegateModel.qml
+++ b/modules/gui/qt/util/qml/SelectableDelegateModel.qml
@@ -58,6 +58,28 @@ DelegateModel {
         return list
     }
 
+    function select( index, command ) {
+        switch (command) {
+            case ItemSelectionModel.Select:
+                items.get(index).inSelected = true
+                break;
+            case ItemSelectionModel.Deselect:
+                items.get(index).inSelected = false
+                break;
+            case ItemSelectionModel.Toggle:
+                items.get(index).inSelected = !items.get(index).inSelected
+                break;
+            case ItemSelectionModel.Clear:
+                selectNone()
+                break;
+            case ItemSelectionModel.ClearAndSelect:
+                selectNone()
+                items.get(index).inSelected = true
+                selectionChanged()
+                break;
+        }
+    }
+
     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 c5a7247ceb..ff07686edb 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
@@ -228,7 +228,7 @@ NavigableFocusScope {
             var initialIndex = 0
             if (view.currentIndex !== -1)
                 initialIndex = view.currentIndex
-            delegateModel.items.get(initialIndex).inSelected = true
+            delegateModel.select(initialIndex, ItemSelectionModel.ClearAndSelect)
             view.currentIndex = initialIndex
         }
     }
-- 
2.25.1



More information about the vlc-devel mailing list