[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.
This commit is contained in:
Candice Bentéjac 2023-03-08 16:45:28 +01:00
parent de39143e83
commit 6f1ac9a06e
3 changed files with 46 additions and 4 deletions

View file

@ -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
}
}
}