[vlc-commits] [Git][videolan/vlc][master] qml: correct binding loop in drop indicator

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Fri Feb 18 11:39:58 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
9382ef38 by Fatih Uzunoglu at 2022-02-18T11:03:01+00:00
qml: correct binding loop in drop indicator

- - - - -


1 changed file:

- modules/gui/qt/playlist/qml/PlaylistListView.qml


Changes:

=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -302,7 +302,7 @@ Control {
 
             property int shiftIndex: -1
 
-            property PlaylistDelegate delegateContainsDrag: null
+            property Item itemContainsDrag: null
 
             onDeselectAll: {
                 root.model.deselectAll()
@@ -334,6 +334,16 @@ Control {
 
                 readonly property bool containsDrag: dropArea.containsDrag
 
+                onContainsDragChanged: {
+                    if (root.model.count > 0) {
+                        listView.updateItemContainsDrag(this, containsDrag)
+                    } else if (!containsDrag && listView.itemContainsDrag === this) {
+                        // In case model count is changed somehow while
+                        // containsDrag is set
+                        listView.updateItemContainsDrag(this, false)
+                    }
+                }
+
                 Rectangle {
                     id: firstItemIndicator
 
@@ -389,41 +399,46 @@ Control {
             Rectangle {
                 id: dropIndicator
 
-                parent: visible ? (listView.delegateContainsDrag ? listView.delegateContainsDrag
-                                                                 : listView.footerItem)
-                                : null
+                parent: listView.itemContainsDrag
+
                 z: 99
 
                 anchors {
                     left: !!parent ? parent.left : undefined
                     right: !!parent ? parent.right : undefined
-                    top: listView.delegateContainsDrag ? (parent.topContainsDrag ? parent.top : undefined)
-                                                       : (parent ? parent.top : undefined)
-                    bottom: listView.delegateContainsDrag ? (parent.bottomContainsDrag ? parent.bottom : undefined)
-                                                          : undefined
-                    bottomMargin: -height
+                    top: !!parent ? (parent.bottomContainsDrag === true ? parent.bottom : parent.top)
+                                  : undefined
                 }
 
                 implicitHeight: VLCStyle.dp(1)
 
-                visible: !!listView.delegateContainsDrag || (listView.footerItem.containsDrag && !listView.footerItem.firstItemIndicatorVisible)
+                visible: !!parent
                 color: colors.accent
             }
 
+            function updateItemContainsDrag(item, set) {
+                if (set) {
+                    // This callLater is needed because in Qt 5.15,
+                    // an item might set itemContainsDrag, before
+                    // the owning item releases it.
+                    Qt.callLater(function() {
+                        if (itemContainsDrag)
+                            console.debug(item + " set itemContainsDrag before it was released!")
+                        itemContainsDrag = item
+                    })
+                } else {
+                    if (itemContainsDrag !== item)
+                        console.debug(item + " released itemContainsDrag that is not owned!")
+                    itemContainsDrag = null
+                }
+            }
+
             delegate: PlaylistDelegate {
                 id: delegate
 
                 width: listView.width
 
-                onContainsDragChanged: {
-                    if (delegate.topContainsDrag || delegate.bottomContainsDrag) {
-                        console.assert(listView.delegateContainsDrag === null)
-                        listView.delegateContainsDrag = delegate
-                    } else {
-                        console.assert(listView.delegateContainsDrag === delegate)
-                        listView.delegateContainsDrag = null
-                    }
-                }
+                onContainsDragChanged: listView.updateItemContainsDrag(this, containsDrag)
             }
 
             add: Transition {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/9382ef3826b3684dc5200bb9e6883fc808396a46

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/9382ef3826b3684dc5200bb9e6883fc808396a46
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list