From 6f1ac9a06e9901badcfeffd6273313304d4c94e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Wed, 8 Mar 2023 16:45:28 +0100 Subject: [PATCH] [ui] Hide disabled File attributes and their edges but keep the connections This commit effectively hides a node's attributes when they are disabled. If these attributes have connections, the edges representing these connections are hidden but not destroyed. When the edges are hidden, if one of the connected attributes is still enabled, its pin becomes empty as if it was not connected to anything. If the disabled attribute is re-enabled and the connection has not been broken (if the enabled attribute on the other side of the edge has not been reconnected to another attribute, for example), the edge re-appears. If the connection has been broken, then the attribute will be unconnected. Hidden connections are saved in project files and taken into account when a project file containing some is loaded. --- meshroom/ui/qml/GraphEditor/AttributePin.qml | 18 ++++++++++++-- meshroom/ui/qml/GraphEditor/GraphEditor.qml | 26 +++++++++++++++++++- meshroom/ui/qml/GraphEditor/Node.qml | 6 ++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/meshroom/ui/qml/GraphEditor/AttributePin.qml b/meshroom/ui/qml/GraphEditor/AttributePin.qml index 0d079e92..feba0c24 100755 --- a/meshroom/ui/qml/GraphEditor/AttributePin.qml +++ b/meshroom/ui/qml/GraphEditor/AttributePin.qml @@ -35,6 +35,16 @@ RowLayout { layoutDirection: Qt.LeftToRight spacing: 3 + function updatePin(isSrc, isVisible) + { + if (isSrc) { + innerOutputAnchor.linkEnabled = isVisible + } else { + innerInputAnchor.linkEnabled = isVisible + } + + } + // Instantiate empty Items for each child attribute Repeater { id: childrenRepeater @@ -59,7 +69,9 @@ RowLayout { color: Colors.sysPalette.base Rectangle { - visible: inputConnectMA.containsMouse || childrenRepeater.count > 0 || (attribute && attribute.isLink) || inputConnectMA.drag.active || inputDropArea.containsDrag + id: innerInputAnchor + property bool linkEnabled: true + visible: inputConnectMA.containsMouse || childrenRepeater.count > 0 || (attribute && attribute.isLink && linkEnabled) || inputConnectMA.drag.active || inputDropArea.containsDrag radius: isList ? 0 : 2 anchors.fill: parent anchors.margins: 2 @@ -207,7 +219,9 @@ RowLayout { color: Colors.sysPalette.base Rectangle { - visible: attribute.hasOutputConnections || outputConnectMA.containsMouse || outputConnectMA.drag.active || outputDropArea.containsDrag + id: innerOutputAnchor + property bool linkEnabled: true + visible: (attribute.hasOutputConnections && linkEnabled) || outputConnectMA.containsMouse || outputConnectMA.drag.active || outputDropArea.containsDrag radius: isList ? 0 : 2 anchors.fill: parent anchors.margins: 2 diff --git a/meshroom/ui/qml/GraphEditor/GraphEditor.qml b/meshroom/ui/qml/GraphEditor/GraphEditor.qml index e7b0d3e5..8d3a0c1e 100755 --- a/meshroom/ui/qml/GraphEditor/GraphEditor.qml +++ b/meshroom/ui/qml/GraphEditor/GraphEditor.qml @@ -383,7 +383,7 @@ Item { property var src: root._attributeToDelegate[edge.src] property var dst: root._attributeToDelegate[edge.dst] property bool isValidEdge: src !== undefined && dst !== undefined - visible: isValidEdge + visible: isValidEdge && src.visible && dst.visible property bool inFocus: containsMouse || (edgeMenu.opened && edgeMenu.currentEdge === edge) @@ -407,6 +407,30 @@ Item { } } } + onVisibleChanged: { + if (visible) { + // Enable the pins on both sides + src.updatePin(true, true) // isSrc = true, isVisible = true + dst.updatePin(false, true) // isSrc = false, isVisible = true + } else { + // One of the attributes is visible, we do not need to handle the case where both attributes are hidden + if (isValidEdge && (src.visible || dst.visible)) { + if (src.visible) { + src.updatePin(true, false) // isSrc = true, isVisible = false + } else { + dst.updatePin(false, false) // isSrc = false, isVisible = false + } + } + } + } + + Component.onDestruction: { + // Handles the case where the edge is destroyed while hidden because it is replaced: the pins should be re-enabled + if (src && src !== undefined) + src.updatePin(true, true) // isSrc = true, isVisible = true + if (dst && dst !== undefined) + dst.updatePin(false, true) // isSrc = false, isVisible = true + } } } diff --git a/meshroom/ui/qml/GraphEditor/Node.qml b/meshroom/ui/qml/GraphEditor/Node.qml index 2729a1d3..7fb54704 100755 --- a/meshroom/ui/qml/GraphEditor/Node.qml +++ b/meshroom/ui/qml/GraphEditor/Node.qml @@ -387,12 +387,14 @@ Item { id: outputs width: parent.width spacing: 3 + Repeater { model: node ? node.attributes : undefined delegate: Loader { id: outputLoader - active: object.isOutput && isFileAttributeBaseType(object) && object.desc.visible + active: object.isOutput && isFileAttributeBaseType(object) + visible: object.enabled anchors.right: parent.right width: outputs.width @@ -421,9 +423,11 @@ Item { Repeater { model: node ? node.attributes : undefined + delegate: Loader { id: inputLoader active: !object.isOutput && isFileAttributeBaseType(object) + visible: object.enabled width: inputs.width sourceComponent: AttributePin {