Remove connected edge when Pin is hidden

Change-Id: I327a49846dce161cc1968428f497d56809c81050
Reviewed-by: Karol Herda <khe@spyro-soft.com>
This commit is contained in:
Karol Herda
2024-12-31 10:19:07 +01:00
parent ed965a55bf
commit 2fafba7f8f
3 changed files with 30 additions and 8 deletions

View File

@@ -123,12 +123,12 @@ StudioControls.Menu {
delegate: StudioControls.CheckBox {
actionIndicator.visible: false
checkState: (modelData.enabled === undefined || modelData.enabled === true) ? Qt.Checked : Qt.UnChecked
checked: (modelData.enabled === undefined || modelData.enabled === true)
text: "pin: " + modelData.name
width: implicitWidth + StudioTheme.Values.toolbarHorizontalMargin
onToggled: {
contextMenu.node.item.switchPin(modelData.id);
contextMenu.node.item.switchPin(modelData.id, checked);
contextMenu.node.item.updatePinVisibility(modelData.id);
}
}

View File

@@ -27,27 +27,49 @@ Qan.NodeItem {
property string type
property string uuid: NodeGraphEditorBackend.widget.generateUUID()
function switchPin(pin_id) {
function switchPin(pin_id, value) {
root.portsMetaData.pin.forEach(data => {
if (data.id == pin_id) {
if (data.enabled === false)
data.enabled = true;
else
data.enabled = false;
data.enabled = value;
}
});
}
function updatePinVisibility(pin_id) {
var edgeToDelete = null;
internal.createdPorts.forEach(data => {
if (data.dataId === pin_id) {
root.portsMetaData.pin.forEach(data2 => {
if (data2.id === pin_id) {
// Hide/show Pin
data.visible = data2.enabled;
// Find edge for hidden Pin, for removal
if (!data2.enabled) {
for (var i = 0; i < graphView.graph.edges.length; i++) {
var edge = graphView.graph.edges.at(i);
var destItem = edge.item.destinationItem;
if (destItem === data) {
edgeToDelete = edge;
break;
}
}
}
}
});
}
});
if (edgeToDelete) {
// Remove from ports first
if (edgeToDelete.item.sourceItem) {
edgeToDelete.item.sourceItem.onEdgeItemDestroyed(edgeToDelete.item);
}
if (edgeToDelete.item.destinationItem) {
edgeToDelete.item.destinationItem.onEdgeItemDestroyed(edgeToDelete.item);
}
// Remove edge
graphView.graph.removeEdge(edgeToDelete);
}
}
Layout.preferredHeight: 60

View File

@@ -160,7 +160,7 @@ protected:
EdgeItems _outEdgeItems;
//! Used internally to automatically monitor in/out edges items destruction.
void onEdgeItemDestroyed(QObject* obj);
Q_INVOKABLE void onEdgeItemDestroyed(QObject* obj);
public:
//! Force input/output edge update.