[ui] GraphEditor: Improve node selected status logic

Instead of connecting to onSelectionChanged, use ItemSelectionModel.hasSelection
property, that can be use for direct bindings with the same behavior.
https://doc.qt.io/qt-6/qml-qtqml-models-itemselectionmodel.html#hasSelection-prop
This commit is contained in:
Yann Lanthony 2024-12-06 10:47:20 +01:00
parent a3268f456c
commit 4a60e24c2e

View file

@ -831,10 +831,6 @@ Item {
property bool updateSelectionOnClick: false
property var temporaryEdgeAboutToBeRemoved: undefined
function isNodeSelected(index: int) {
return uigraph.nodeSelection.isRowSelected(index);
}
delegate: Node {
id: nodeDelegate
@ -844,19 +840,12 @@ Item {
mainSelected: uigraph.selectedNode === node
hovered: uigraph.hoveredNode === node
selected: nodeRepeater.isNodeSelected(index);
// ItemSelectionModel.hasSelection triggers updates anytime the selectionChanged() signal is emitted.
selected: uigraph.nodeSelection.hasSelection ? uigraph.nodeSelection.isRowSelected(index) : false
onAttributePinCreated: function(attribute, pin) { registerAttributePin(attribute, pin) }
onAttributePinDeleted: function(attribute, pin) { unregisterAttributePin(attribute, pin) }
Connections {
target: uigraph.nodeSelection
function onSelectionChanged() {
selected = nodeRepeater.isNodeSelected(index);
}
}
onPressed: function(mouse) {
nodeRepeater.updateSelectionOnClick = true;
nodeRepeater.ongoingDrag = true;