[vlc-devel] [PATCH 15/15] qml: have index as a property for items in ExpandGridView rather then separately attaching it through Object.defineProperty

Prince Gupta guptaprince8832 at gmail.com
Tue Jul 21 14:18:13 CEST 2020


support for Object.defineProperty is not complete in qt and sometimes bindings related to defined property is not evaluated
---
 modules/gui/qt/medialibrary/qml/AudioGridItem.qml |  2 ++
 modules/gui/qt/medialibrary/qml/VideoGridItem.qml |  2 ++
 modules/gui/qt/widgets/qml/ExpandGridView.qml     | 15 ++-------------
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/modules/gui/qt/medialibrary/qml/AudioGridItem.qml b/modules/gui/qt/medialibrary/qml/AudioGridItem.qml
index 08228d5ae3..7d6c88727e 100644
--- a/modules/gui/qt/medialibrary/qml/AudioGridItem.qml
+++ b/modules/gui/qt/medialibrary/qml/AudioGridItem.qml
@@ -24,6 +24,8 @@ import "qrc:///style/"
 
 Widgets.GridItem {
     property var model: ({})
+    property int index: -1
+
     image: model.cover || VLCStyle.noArtAlbum
     title: model.title || i18n.qtr("Unknown title")
     subtitle: model.main_artist || i18n.qtr("Unknown artist")
diff --git a/modules/gui/qt/medialibrary/qml/VideoGridItem.qml b/modules/gui/qt/medialibrary/qml/VideoGridItem.qml
index 894bbab3ac..da7e179570 100644
--- a/modules/gui/qt/medialibrary/qml/VideoGridItem.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoGridItem.qml
@@ -24,6 +24,8 @@ import "qrc:///style/"
 
 Widgets.GridItem {
     property var model: ({})
+    property int index: -1
+
     image: model.thumbnail || VLCStyle.noArtCover
     title: model.title || i18n.qtr("Unknown title")
     subtitle: model.duration || ""
diff --git a/modules/gui/qt/widgets/qml/ExpandGridView.qml b/modules/gui/qt/widgets/qml/ExpandGridView.qml
index eb13646b12..5474a4382f 100644
--- a/modules/gui/qt/widgets/qml/ExpandGridView.qml
+++ b/modules/gui/qt/widgets/qml/ExpandGridView.qml
@@ -156,17 +156,6 @@ NavigableFocusScope {
             animateFlickableContentY(newContentY)
     }
 
-
-    function _defineObjProperty( obj, prop, value )
-    {
-        Object.defineProperty(obj, prop, {
-            "enumerable": true,
-            "configurable": false,
-            "value": value,
-            "writable": true,
-        })
-    }
-
     function _updateSelected() {
         for (var id in _idChildrenMap) {
             var item = _idChildrenMap[id]
@@ -234,7 +223,7 @@ NavigableFocusScope {
             if (item === undefined)
                 throw "wrong toRecycle child " + id + ", len " + toUse.length
 
-            _defineObjProperty(item, "index", id)
+            item.index = id
             item.model = model.getDataAt(id)
 
             item.focus = (id === root.currentIndex) && (root.expandIndex === -1)
@@ -248,6 +237,7 @@ NavigableFocusScope {
             //instanciate a new item
 
             item = root.delegate.createObject( flickable.contentItem, {
+                            index: id,
                             model: model.getDataAt(id),
                             focus: (id === root.currentIndex) && (root.expandIndex === -1),
                             x: pos[0],
@@ -256,7 +246,6 @@ NavigableFocusScope {
                         });
             if (item === undefined)
                 throw "wrong unable to instantiate child " + id
-            _defineObjProperty(item, "index", id)
             _idChildrenMap[id] = item
         }
         return item
-- 
2.25.1



More information about the vlc-devel mailing list