[vlc-commits] qml: use count directly provided by models

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


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Feb 26 17:45:13 2020 +0100| [94c0f377b43764d8331df337035d745e758391be] | committer: Pierre Lamot

qml: use count directly provided by models

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

 modules/gui/qt/medialibrary/qml/MusicAlbums.qml    | 32 ++++++++++----------
 .../qt/medialibrary/qml/MusicArtistsDisplay.qml    | 30 ++++++++++---------
 modules/gui/qt/medialibrary/qml/MusicGenres.qml    | 31 +++++++++++---------
 modules/gui/qt/medialibrary/qml/VideoDisplay.qml   | 34 ++++++++++++----------
 4 files changed, 69 insertions(+), 58 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
index 6ee01252a5..68e80ca8e0 100644
--- a/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicAlbums.qml
@@ -60,40 +60,42 @@ Widgets.NavigableFocusScope {
     onParentIdChanged: resetFocus()
 
     function resetFocus() {
-        if (delegateModelId.items.count === 0) {
+        if (albumModelId.count === 0) {
             return
         }
         var initialIndex = root.initialIndex
-        if (initialIndex >= delegateModelId.items.count)
+        if (initialIndex >= albumModelId.count)
             initialIndex = 0
         delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
         view.currentItem.currentIndex = initialIndex
         view.currentItem.positionViewAtIndex(initialIndex, ItemView.Contain)
     }
 
+    MLAlbumModel {
+        id: albumModelId
+        ml: medialib
+
+        onCountChanged: {
+            if (albumModelId.count > 0 && !delegateModelId.hasSelection) {
+                root.resetFocus()
+            }
+        }
+    }
+
     Util.SelectableDelegateModel {
         id: delegateModelId
         property alias parentId: albumModelId.parentId
 
-        model: MLAlbumModel {
-            id: albumModelId
-            ml: medialib
-        }
+        model: albumModelId
 
         delegate: Item {
         }
 
-        onCountChanged: {
-            if (delegateModelId.items.count > 0 && !delegateModelId.hasSelection) {
-                root.resetFocus()
-            }
-        }
-
         function actionAtIndex(index) {
             if (delegateModelId.selectedGroup.count > 1) {
                 medialib.addAndPlay( model.getIdsForIndexes( delegateModelId.selectedIndexes() ) )
             } else {
-                medialib.addAndPlay( model.getIdsForIndexes([index]) )
+                medialib.addAndPlay( model.getIdForIndex(index) )
             }
         }
     }
@@ -215,7 +217,7 @@ Widgets.NavigableFocusScope {
         id: view
 
         anchors.fill: parent
-        focus: delegateModelId.items.count !== 0
+        focus: albumModelId.count !== 0
 
         initialItem: medialib.gridView ? gridComponent : listComponent
 
@@ -241,7 +243,7 @@ Widgets.NavigableFocusScope {
 
     EmptyLabel {
         anchors.fill: parent
-        visible: delegateModelId.items.count === 0
+        visible: albumModelId.count === 0
         focus: visible
         text: i18n.qtr("No albums found\nPlease try adding sources, by going to the Network tab")
         navigationParent: root
diff --git a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
index 877d75f243..a097092061 100644
--- a/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicArtistsDisplay.qml
@@ -47,11 +47,11 @@ Widgets.NavigableFocusScope {
     }
 
     function resetFocus() {
-        if (delegateModel.items.count === 0) {
+        if (artistModel.count === 0) {
             return
         }
         var initialIndex = root.initialIndex
-        if (initialIndex >= delegateModel.items.count)
+        if (initialIndex >= artistModel.count)
             initialIndex = 0
         if (initialIndex !== artistList.currentIndex) {
             delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
@@ -60,21 +60,23 @@ Widgets.NavigableFocusScope {
         }
     }
 
-    Util.SelectableDelegateModel {
-        id: delegateModel
-        model: MLArtistModel {
-            id: artistModel
-            ml: medialib
-        }
+    MLArtistModel {
+        id: artistModel
+        ml: medialib
 
         onCountChanged: {
-            if (delegateModel.items.count > 0 && !delegateModel.hasSelection) {
+            if (artistModel.count > 0 && !delegateModel.hasSelection) {
                 var initialIndex = root.initialIndex
-                if (initialIndex >= delegateModel.items.count)
+                if (initialIndex >= artistModel.count)
                     initialIndex = 0
                 artistList.currentIndex = initialIndex
             }
         }
+    }
+
+    Util.SelectableDelegateModel {
+        id: delegateModel
+        model: artistModel
 
         delegate: Item {}
 
@@ -84,7 +86,7 @@ Widgets.NavigableFocusScope {
     }
 
     FocusScope {
-        visible: delegateModel.count > 0
+        visible: artistModel.count > 0
         focus: visible
         anchors.fill: parent
 
@@ -106,8 +108,8 @@ Widgets.NavigableFocusScope {
             onSelectAll: delegateModel.selectAll()
             onSelectionUpdated: delegateModel.updateSelection( keyModifiers, oldIndex, newIndex )
             onCurrentIndexChanged: {
-                if (artistList.currentIndex < delegateModel.count) {
-                    root.artistId = delegateModel.items.get(artistList.currentIndex).model.id
+                if (artistList.currentIndex < artistModel.count) {
+                    root.artistId =  artistModel.getIdForIndex(artistList.currentIndex)
                 } else {
                     root.artistId = undefined
                 }
@@ -207,7 +209,7 @@ Widgets.NavigableFocusScope {
 
     EmptyLabel {
         anchors.fill: parent
-        visible: delegateModel.count === 0
+        visible: artistModel.count === 0
         focus: visible
         text: i18n.qtr("No artists found\nPlease try adding sources, by going to the Network tab")
         navigationParent: root
diff --git a/modules/gui/qt/medialibrary/qml/MusicGenres.qml b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
index 92ac0e02a9..cdcb36a232 100644
--- a/modules/gui/qt/medialibrary/qml/MusicGenres.qml
+++ b/modules/gui/qt/medialibrary/qml/MusicGenres.qml
@@ -60,11 +60,11 @@ Widgets.NavigableFocusScope {
     }
 
     function resetFocus() {
-        if (delegateModelId.items.count === 0) {
+        if (genreModel.count === 0) {
             return
         }
         var initialIndex = root.initialIndex
-        if (initialIndex >= delegateModelId.items.count)
+        if (initialIndex >= genreModel.count)
             initialIndex = 0
         delegateModelId.select(initialIndex, ItemSelectionModel.ClearAndSelect)
         view.currentItem.currentIndex = initialIndex
@@ -83,22 +83,25 @@ Widgets.NavigableFocusScope {
             width: root.width
         }
     }
+    MLGenreModel {
+        id: genreModel
+        ml: medialib
+
+        onCountChanged: {
+            if (genreModel.count > 0 && !delegateModelId.hasSelection) {
+                root.resetFocus()
+            }
+        }
+    }
 
     Util.SelectableDelegateModel {
         id: delegateModelId
-        model: MLGenreModel {
-            id: genreModel
-            ml: medialib
-        }
+
+        model: genreModel
 
         delegate: Item {
         }
 
-        onCountChanged: {
-            if (delegateModelId.items.count > 0 && !delegateModelId.hasSelection) {
-                root.resetFocus()
-            }
-        }
 
         function actionAtIndex(index) {
             if (delegateModelId.selectedGroup.count > 1) {
@@ -115,7 +118,7 @@ Widgets.NavigableFocusScope {
      * selectedGroup update itself after this event
      */
     onActiveFocusChanged: {
-        if (activeFocus && delegateModelId.items.count > 0 && !delegateModelId.hasSelection) {
+        if (activeFocus && genreModel.count > 0 && !delegateModelId.hasSelection) {
             var initialIndex = 0
             if (view.currentItem.currentIndex !== -1)
                 initialIndex = view.currentItem.currentIndex
@@ -230,12 +233,12 @@ Widgets.NavigableFocusScope {
         initialItem: medialib.gridView ? gridComponent : listComponent
 
         anchors.fill: parent
-        focus: delegateModelId.items.count !== 0
+        focus: genreModel.count !== 0
     }
 
     EmptyLabel {
         anchors.fill: parent
-        visible: delegateModelId.items.count === 0
+        visible: genreModel.count === 0
         focus: visible
         text: i18n.qtr("No genres found\nPlease try adding sources, by going to the Network tab")
         navigationParent: root
diff --git a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
index db77718c09..9a819e46c6 100644
--- a/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoDisplay.qml
@@ -32,7 +32,7 @@ Widgets.NavigableFocusScope {
     //the index to "go to" when the view is loaded
     property var initialIndex: 0
 
-    property alias contentModel: videosDelegate.model;
+    property alias contentModel: videoModel ;
 
     navigationCancel: function() {
         if (view.currentItem.currentIndex <= 0) {
@@ -51,11 +51,11 @@ Widgets.NavigableFocusScope {
     onContentModelChanged: resetFocus()
 
     function resetFocus() {
-        if (videosDelegate.items.count === 0) {
+        if (videoModel.count === 0) {
             return
         }
         var initialIndex = root.initialIndex
-        if (initialIndex >= videosDelegate.items.count)
+        if (initialIndex >= videoModel.count)
             initialIndex = 0
         videosDelegate.select(initialIndex, ItemSelectionModel.ClearAndSelect)
         view.currentItem.currentIndex = initialIndex
@@ -112,21 +112,25 @@ Widgets.NavigableFocusScope {
         onClosed: contextMenu.parent.forceActiveFocus()
 
     }
-    Util.SelectableDelegateModel {
-        id: videosDelegate
 
-        model: MLVideoModel {
-            id: videoModel
-            ml: medialib
-        }
-        delegate: Item{
-        }
+    MLVideoModel {
+        id: videoModel
+        ml: medialib
 
         onCountChanged: {
-            if (videosDelegate.items.count > 0 && !videosDelegate.hasSelection) {
+            if (videoModel.count > 0 && !videosDelegate.hasSelection) {
                 root.resetFocus()
             }
         }
+    }
+
+    Util.SelectableDelegateModel {
+        id: videosDelegate
+
+        model: videoModel
+
+        delegate: Item{
+        }
 
         function actionAtIndex(index) {
             medialib.addAndPlay( videoModel.getIdsForIndexes( videosDelegate.selectedIndexes() ) )
@@ -190,7 +194,7 @@ Widgets.NavigableFocusScope {
              * selectedGroup update itself after this event
              */
             onActiveFocusChanged: {
-                if (activeFocus && videosDelegate.items.count > 0 && !videosDelegate.hasSelection) {
+                if (activeFocus && videoModel.count > 0 && !videosDelegate.hasSelection) {
                     videosDelegate.select(0, ItemSelectionModel.ClearAndSelect)
                 }
             }
@@ -229,7 +233,7 @@ Widgets.NavigableFocusScope {
         id: view
         anchors.fill:parent
         clip: true
-        focus: videosDelegate.items.count !== 0
+        focus: videoModel.count !== 0
         initialItem: medialib.gridView ? gridComponent : listComponent
         Connections {
             target: medialib
@@ -245,7 +249,7 @@ Widgets.NavigableFocusScope {
 
     EmptyLabel {
         anchors.fill: parent
-        visible: videosDelegate.items.count === 0
+        visible: videoModel.count === 0
         focus: visible
         text: i18n.qtr("No video found\nPlease try adding sources, by going to the Network tab")
         navigationParent: root



More information about the vlc-commits mailing list