[vlc-devel] [PATCH 07/12] qml: use parent provided selection model in KeyNavigableTableView

Prince Gupta guptaprince8832 at gmail.com
Mon Aug 24 17:08:24 CEST 2020


---
 .../gui/qt/medialibrary/qml/MusicAlbums.qml   |  5 ++--
 .../gui/qt/medialibrary/qml/MusicArtist.qml   |  7 +++++
 .../medialibrary/qml/MusicArtistsDisplay.qml  |  1 +
 .../gui/qt/medialibrary/qml/MusicGenres.qml   |  1 +
 .../qml/MusicTrackListDisplay.qml             | 22 ++++++++++----
 .../qt/medialibrary/qml/VideoListDisplay.qml  |  4 +++
 .../qt/widgets/qml/KeyNavigableTableView.qml  | 29 +++++++------------
 7 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index 983a0eefdc..b6b9acef10 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -72,7 +72,7 @@ Widgets.NavigableFocusScope {
     }
 
     function _actionAtIndex(index) {
-        if (selectionModel.selectedGroup.count > 1) {
+        if (selectionModel.selectedIndexes.length > 1) {
             medialib.addAndPlay( model.getIdsForIndexes( selectionModel.selectedIndexes ) )
         } else {
             medialib.addAndPlay( model.getIdForIndex(index) )
@@ -189,8 +189,9 @@ Widgets.NavigableFocusScope {
             readonly property int _nbCols: VLCStyle.gridColumnsForWidth(tableView_id.availableRowWidth)
 
             model: albumModelId
+            selectionDelegateModel: selectionModel
             headerColor: VLCStyle.colors.bg
-            onActionForSelection: _actionAtIndex(index)
+            onActionForSelection: _actionAtIndex(selection[0]);
             navigationParent: root
             section.property: "title_first_symbol"
             header: root.header
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtist.qml b/modules/gui/qt/medialibrary/qml/MusicArtist.qml
index ae07cec5aa..0845d59ca2 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtist.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtist.qml
@@ -314,6 +314,7 @@ Widgets.NavigableFocusScope {
             readonly property int _nbCols: VLCStyle.gridColumnsForWidth(tableView_id.availableRowWidth)
 
             model: trackModel
+            selectionDelegateModel: trackSelectionModel
             headerColor: VLCStyle.colors.bg
             onActionForSelection: {
                 medialib.addAndPlay( model.getIdsForIndexes( selection ) )
@@ -348,6 +349,12 @@ Widgets.NavigableFocusScope {
                 positionViewAtIndex(currentIndex, ItemView.Contain)
                 currentItem.forceActiveFocus()
             }
+
+            Util.SelectableDelegateModel {
+                id: trackSelectionModel
+
+                model: trackModel
+            }
         }
     }
 
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index 208addaf1f..c88facb7be 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -208,6 +208,7 @@ Widgets.NavigableFocusScope {
                     readonly property int _nbCols: VLCStyle.gridColumnsForWidth(artistTable.availableRowWidth)
 
                     anchors.fill: parent
+                    selectionDelegateModel: selectionModel
                     model: artistModel
                     focus: true
                     headerColor: VLCStyle.colors.bg
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index 7ab58c65e0..eeeebb4e69 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -245,6 +245,7 @@ Widgets.NavigableFocusScope {
             }
 
             model: genreModel
+            selectionDelegateModel: selectionModel
             headerColor: VLCStyle.colors.bg
             focus: true
             onActionForSelection: _actionAtIndex(selection)
diff --git a/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
index 509372251b..f50f7ded1f 100644
--- a/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicTrackListDisplay.qml
@@ -22,6 +22,7 @@ import QtQuick.Layouts 1.3
 
 import org.videolan.medialib 0.1
 
+import "qrc:///util/" as Util
 import "qrc:///widgets/" as Widgets
 import "qrc:///style/"
 
@@ -58,7 +59,18 @@ Widgets.KeyNavigableTableView {
 
     headerColor: VLCStyle.colors.bg
 
-    model: MLAlbumTrackModel {
+    model: rootmodel
+    selectionDelegateModel: selectionModel
+
+    property alias parentId: rootmodel.parentId
+
+    onActionForSelection:  medialib.addAndPlay(model.getIdsForIndexes( selection ))
+
+    Widgets.TableColumns {
+        id: tableColumns
+    }
+
+    MLAlbumTrackModel {
         id: rootmodel
         ml: medialib
         onSortCriteriaChanged: {
@@ -74,11 +86,9 @@ Widgets.KeyNavigableTableView {
         }
     }
 
-    property alias parentId: rootmodel.parentId
+    Util.SelectableDelegateModel {
+        id: selectionModel
 
-    onActionForSelection:  medialib.addAndPlay(model.getIdsForIndexes( selection ))
-
-    Widgets.TableColumns {
-        id: tableColumns
+        model: rootmodel
     }
 }
diff --git a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
index a8ef059f51..9835890f96 100644
--- a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
@@ -21,6 +21,7 @@ import QtQml.Models 2.2
 
 import org.videolan.medialib 0.1
 
+import "qrc:///util" as Util
 import "qrc:///widgets/" as Widgets
 import "qrc:///style/"
 
@@ -30,6 +31,9 @@ Widgets.KeyNavigableTableView {
     model: MLVideoModel {
         ml: medialib
     }
+    selectionDelegateModel: Util.SelectableDelegateModel {
+        model: listView_id.model
+    }
 
     property Component thumbnailHeader: Item {
         Widgets.IconLabel {
diff --git a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
index bfe3342ea6..adfb4fbe9d 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
@@ -63,7 +63,7 @@ NavigableFocusScope {
     property alias tableHeaderItem: view.headerItem
     property color headerColor
 
-    property alias selectionModel: selectionModel
+    property var selectionDelegateModel
     property real rowHeight: VLCStyle.fontHeight_normal + VLCStyle.margin_large
     readonly property real availableRowWidth: width - ( VLCStyle.table_section_width * 2 )
     property alias spacing: view.spacing
@@ -82,13 +82,6 @@ NavigableFocusScope {
         view.positionViewAtIndex(index, mode)
     }
 
-    Util.SelectableDelegateModel {
-        id: selectionModel
-
-        model: root.model
-    }
-
-
     KeyNavigableListView {
         id: view
 
@@ -188,7 +181,7 @@ NavigableFocusScope {
             id: lineView
 
             property var rowModel: model
-            property bool selected: selectionModel.isSelected(root.model.index(index, 0))
+            property bool selected: selectionDelegateModel.isSelected(root.model.index(index, 0))
             property alias showSeparator: separator.visible
             readonly property bool highlighted: selected || hoverArea.containsMouse || activeFocus
 
@@ -204,8 +197,8 @@ NavigableFocusScope {
             }
 
             Connections {
-                target: selectionModel
-                onSelectionChanged: lineView.selected = selectionModel.isSelected(root.model.index(index, 0))
+                target: selectionDelegateModel
+                onSelectionChanged: lineView.selected = selectionDelegateModel.isSelected(root.model.index(index, 0))
             }
 
             MouseArea {
@@ -216,7 +209,7 @@ NavigableFocusScope {
                 acceptedButtons: Qt.RightButton | Qt.LeftButton
 
                 onClicked: {
-                    selectionModel.updateSelection( mouse.modifiers , view.currentIndex, index)
+                    selectionDelegateModel.updateSelection( mouse.modifiers , view.currentIndex, index)
                     view.currentIndex = rowModel.index
                     lineView.forceActiveFocus()
 
@@ -226,7 +219,7 @@ NavigableFocusScope {
                 }
 
                 onDoubleClicked: {
-                    actionForSelection(selectionModel.selectedIndexes)
+                    actionForSelection(selectionDelegateModel.selectedIndexes)
                     root.itemDoubleClicked(model)
                 }
 
@@ -297,9 +290,9 @@ NavigableFocusScope {
             }
         }
 
-        onSelectAll: selectionModel.selectAll()
-        onSelectionUpdated: selectionModel.updateSelection( keyModifiers, oldIndex, newIndex )
-        onActionAtIndex: root.actionForSelection( selectionModel.selectedIndexes )
+        onSelectAll: selectionDelegateModel.selectAll()
+        onSelectionUpdated: selectionDelegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
+        onActionAtIndex: root.actionForSelection( selectionDelegateModel.selectedIndexes )
 
         navigationParent: root
     }
@@ -310,11 +303,11 @@ NavigableFocusScope {
      * selectedGroup update itself after this event
      */
     onActiveFocusChanged: {
-        if (activeFocus && view.count > 0 && !selectionModel.hasSelection) {
+        if (activeFocus && view.count > 0 && !selectionDelegateModel.hasSelection) {
             var initialIndex = 0
             if (view.currentIndex !== -1)
                 initialIndex = view.currentIndex
-            selectionModel.select(model.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
+            selectionDelegateModel.select(model.index(initialIndex, 0), ItemSelectionModel.ClearAndSelect)
             view.currentIndex = initialIndex
         }
     }
-- 
2.25.1



More information about the vlc-devel mailing list