Skip to content

Commit 139c62a

Browse files
committed
[GraphEditor] Allow to display and connect attributes within GroupAttribute
1 parent 026feed commit 139c62a

File tree

2 files changed

+180
-21
lines changed

2 files changed

+180
-21
lines changed

meshroom/ui/qml/GraphEditor/AttributePin.qml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ RowLayout {
1313

1414
property var nodeItem
1515
property var attribute
16+
property bool expanded: false
1617
property bool readOnly: false
1718
/// Whether to display an output pin for input attribute
1819
property bool displayOutputPinForInput: true
@@ -25,13 +26,17 @@ RowLayout {
2526
outputAnchor.y + outputAnchor.height / 2)
2627

2728
readonly property bool isList: attribute && attribute.type === "ListAttribute"
29+
readonly property bool isGroup: attribute && attribute.type === "GroupAttribute"
30+
readonly property bool isChild: attribute && attribute.root
2831

2932
signal childPinCreated(var childAttribute, var pin)
3033
signal childPinDeleted(var childAttribute, var pin)
3134

3235
signal pressed(var mouse)
3336
signal edgeAboutToBeRemoved(var input)
3437

38+
signal clicked()
39+
3540
objectName: attribute ? attribute.name + "." : ""
3641
layoutDirection: Qt.LeftToRight
3742
spacing: 3
@@ -52,6 +57,24 @@ RowLayout {
5257
}
5358
}
5459

60+
function updateLabel() {
61+
var label = ""
62+
var expandedGroup = expanded ? "-" : "+"
63+
if (attribute && attribute.label !== undefined) {
64+
label = attribute.label
65+
if (isGroup && attribute.isOutput) {
66+
label = label + " " + expandedGroup
67+
} else if (isGroup && !attribute.isOutput) {
68+
label = expandedGroup + " " + label
69+
}
70+
}
71+
return label
72+
}
73+
74+
onExpandedChanged: {
75+
nameLabel.text = updateLabel()
76+
}
77+
5578
// Instantiate empty Items for each child attribute
5679
Repeater {
5780
id: childrenRepeater
@@ -171,7 +194,8 @@ RowLayout {
171194
onReleased: {
172195
inputDragTarget.Drag.drop()
173196
}
174-
hoverEnabled: true
197+
onClicked: root.clicked()
198+
hoverEnabled: root.visible
175199
}
176200

177201
Edge {
@@ -197,18 +221,22 @@ RowLayout {
197221
id: nameLabel
198222

199223
enabled: !root.readOnly
224+
visible: true
200225
property bool hovered: (inputConnectMA.containsMouse || inputConnectMA.drag.active || inputDropArea.containsDrag || outputConnectMA.containsMouse || outputConnectMA.drag.active || outputDropArea.containsDrag)
201-
text: (attribute && attribute.label) !== undefined ? attribute.label : ""
226+
text: root.updateLabel()
202227
elide: hovered ? Text.ElideNone : Text.ElideMiddle
203228
width: hovered ? contentWidth : parent.width
204229
font.pointSize: 7
230+
font.italic: isChild ? true : false
205231
horizontalAlignment: attribute && attribute.isOutput ? Text.AlignRight : Text.AlignLeft
206232
anchors.right: attribute && attribute.isOutput ? parent.right : undefined
207233
rightPadding: 0
208234
color: {
209235
if ((object.hasOutputConnections || object.isLink) && !object.enabled)
210236
return Colors.lightgrey
211-
return hovered ? palette.highlight : palette.text
237+
else if (hovered)
238+
return palette.highlight
239+
return palette.text
212240
}
213241
}
214242
}
@@ -234,8 +262,8 @@ RowLayout {
234262
anchors.fill: parent
235263
anchors.margins: 2
236264
color: {
237-
if (object.enabled && (outputConnectMA.containsMouse || outputConnectMA.drag.active ||
238-
(outputDropArea.containsDrag && outputDropArea.acceptableDrop)))
265+
if (modelData.enabled && (outputConnectMA.containsMouse || outputConnectMA.drag.active ||
266+
(outputDropArea.containsDrag && outputDropArea.acceptableDrop)))
239267
return Colors.sysPalette.highlight
240268
return Colors.sysPalette.text
241269
}
@@ -314,8 +342,9 @@ RowLayout {
314342

315343
onPressed: function(mouse) { root.pressed(mouse) }
316344
onReleased: outputDragTarget.Drag.drop()
345+
onClicked: root.clicked()
317346

318-
hoverEnabled: true
347+
hoverEnabled: root.visible
319348
}
320349

321350
Edge {

meshroom/ui/qml/GraphEditor/Node.qml

Lines changed: 145 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,54 @@ Item {
115115
return str
116116
}
117117

118+
function updateChildPin(attribute, parentPins, pin) {
119+
/*
120+
* Update the pin of a child attribute: if the attribute is enabled and its parent is a GroupAttribute,
121+
* the visibility is determined based on the parent pin's "expanded" state, using the "parentPins" map to
122+
* access the status.
123+
* If the current pin is also a GroupAttribute and is expanded while its newly "visible" state is false,
124+
* it is reset.
125+
*/
126+
if (Boolean(attribute.enabled)) {
127+
// If the parent's a GroupAttribute, use status of the parent's pin to determine visibility
128+
if (attribute.root && attribute.root.type === "GroupAttribute") {
129+
var visible = Boolean(parentPins.get(attribute.root.name))
130+
if (!visible && parentPins.has(attribute.name) && parentPins.get(attribute.name) === true) {
131+
parentPins.set(attribute.name, false)
132+
pin.expanded = false
133+
}
134+
return visible
135+
}
136+
return true
137+
}
138+
return false
139+
}
140+
141+
function generateAttributesModel(isOutput, parentPins) {
142+
if (!node)
143+
return undefined
144+
145+
const attributes = []
146+
for (let i = 0; i < node.attributes.count; ++i) {
147+
let attr = node.attributes.at(i)
148+
if (attr.isOutput == isOutput) {
149+
attributes.push(attr)
150+
if (attr.type === "GroupAttribute") {
151+
parentPins.set(attr.name, false)
152+
}
153+
154+
for (let j = 0; j < attr.flattenedChildren.count; ++j) {
155+
attributes.push(attr.flattenedChildren.at(j))
156+
if (attr.flattenedChildren.at(j).type === "GroupAttribute") {
157+
parentPins.set(attr.flattenedChildren.at(j).name, false)
158+
}
159+
}
160+
}
161+
}
162+
163+
return attributes
164+
}
165+
118166
// Main Layout
119167
MouseArea {
120168
id: mouseArea
@@ -394,26 +442,53 @@ Item {
394442
width: parent.width
395443
spacing: 3
396444

445+
property var parentPins: new Map()
446+
signal parentPinsUpdated()
447+
397448
Repeater {
398-
model: node ? node.attributes : undefined
449+
model: generateAttributesModel(true, outputs.parentPins) // isOutput = true
399450

400451
delegate: Loader {
401452
id: outputLoader
402-
active: Boolean(object.isOutput && object.desc.visible)
403-
visible: Boolean(object.enabled || object.hasOutputConnections)
453+
active: Boolean(modelData.isOutput && modelData.desc.visible)
454+
455+
visible: {
456+
if (Boolean(modelData.enabled || modelData.hasOutputConnections)) {
457+
if (modelData.root && modelData.root.type === "GroupAttribute") {
458+
return Boolean(outputs.parentPins.get(modelData.root.name))
459+
}
460+
return true
461+
}
462+
return false
463+
}
404464
anchors.right: parent.right
405465
width: outputs.width
406466

467+
Connections {
468+
target: outputs
469+
470+
function onParentPinsUpdated() {
471+
visible = updateChildPin(modelData, outputs.parentPins, outputLoader.item)
472+
}
473+
}
474+
407475
sourceComponent: AttributePin {
408476
id: outPin
409477
nodeItem: root
410-
attribute: object
478+
attribute: modelData
411479

412480
property real globalX: root.x + nodeAttributes.x + outputs.x + outputLoader.x + outPin.x
413481
property real globalY: root.y + nodeAttributes.y + outputs.y + outputLoader.y + outPin.y
414482

415483
onPressed: function(mouse) { root.pressed(mouse) }
416484
onEdgeAboutToBeRemoved: function(input) { root.edgeAboutToBeRemoved(input) }
485+
onClicked: {
486+
expanded = !expanded
487+
if (outputs.parentPins.has(modelData.name)) {
488+
outputs.parentPins.set(modelData.name, expanded)
489+
outputs.parentPinsUpdated()
490+
}
491+
}
417492

418493
Component.onCompleted: attributePinCreated(attribute, outPin)
419494
onChildPinCreated: attributePinCreated(childAttribute, outPin)
@@ -429,19 +504,38 @@ Item {
429504
width: parent.width
430505
spacing: 3
431506

507+
property var parentPins: new Map()
508+
signal parentPinsUpdated()
509+
432510
Repeater {
433-
model: node ? node.attributes : undefined
511+
model: generateAttributesModel(false, inputs.parentPins) // isOutput = false
434512

435513
delegate: Loader {
436514
id: inputLoader
437-
active: !object.isOutput && object.exposed && object.desc.visible
438-
visible: Boolean(object.enabled)
515+
active: !modelData.isOutput && modelData.exposed && modelData.desc.visible
516+
visible: {
517+
if (Boolean(modelData.enabled)) {
518+
if (modelData.root && modelData.root.type === "GroupAttribute") {
519+
return Boolean(inputs.parentPins.get(modelData.root.name))
520+
}
521+
return true
522+
}
523+
return false
524+
}
439525
width: inputs.width
440526

527+
Connections {
528+
target: inputs
529+
530+
function onParentPinsUpdated() {
531+
visible = updateChildPin(modelData, inputs.parentPins, inputLoader.item)
532+
}
533+
}
534+
441535
sourceComponent: AttributePin {
442536
id: inPin
443537
nodeItem: root
444-
attribute: object
538+
attribute: modelData
445539

446540
property real globalX: root.x + nodeAttributes.x + inputs.x + inputLoader.x + inPin.x
447541
property real globalY: root.y + nodeAttributes.y + inputs.y + inputLoader.y + inPin.y
@@ -450,6 +544,13 @@ Item {
450544
Component.onCompleted: attributePinCreated(attribute, inPin)
451545
Component.onDestruction: attributePinDeleted(attribute, inPin)
452546
onPressed: function(mouse) { root.pressed(mouse) }
547+
onClicked: {
548+
expanded = !expanded
549+
if (inputs.parentPins.has(modelData.name)) {
550+
inputs.parentPins.set(modelData.name, expanded)
551+
inputs.parentPinsUpdated()
552+
}
553+
}
453554
onEdgeAboutToBeRemoved: function(input) { root.edgeAboutToBeRemoved(input) }
454555
onChildPinCreated: function(childAttribute, inPin) { attributePinCreated(childAttribute, inPin) }
455556
onChildPinDeleted: function(childAttribute, inPin) { attributePinDeleted(childAttribute, inPin) }
@@ -489,30 +590,59 @@ Item {
489590
id: inputParams
490591
width: parent.width
491592
spacing: 3
593+
594+
property var parentPins: new Map()
595+
signal parentPinsUpdated()
596+
492597
Repeater {
493-
id: inputParamsRepeater
494-
model: node ? node.attributes : undefined
598+
model: generateAttributesModel(false, inputParams.parentPins) // isOutput = false
599+
495600
delegate: Loader {
496601
id: paramLoader
497-
active: !object.isOutput && !object.exposed && object.desc.visible
498-
visible: Boolean(object.enabled || object.isLinkNested || object.hasOutputConnections)
499-
property bool isFullyActive: Boolean(m.displayParams || object.isLinkNested || object.hasOutputConnections)
602+
active: !modelData.isOutput && !modelData.exposed && modelData.desc.visible
603+
visible: {
604+
if (Boolean(modelData.enabled || modelData.isLinkNested || modelData.hasOutputConnections)) {
605+
if (modelData.root && modelData.root.type === "GroupAttribute") {
606+
return Boolean(inputParams.parentPins.get(modelData.root.name))
607+
}
608+
return true
609+
}
610+
return false
611+
}
612+
property bool isFullyActive: Boolean(m.displayParams || modelData.isLinkNested || modelData.hasOutputConnections)
500613
width: parent.width
501614

615+
Connections {
616+
target: inputParams
617+
618+
function onParentPinsUpdated() {
619+
visible = updateChildPin(modelData, inputParams.parentPins, paramLoader.item)
620+
}
621+
}
622+
502623
sourceComponent: AttributePin {
503624
id: inParamsPin
504625
nodeItem: root
626+
attribute: modelData
627+
505628
property real globalX: root.x + nodeAttributes.x + inputParamsRect.x + paramLoader.x + inParamsPin.x
506629
property real globalY: root.y + nodeAttributes.y + inputParamsRect.y + paramLoader.y + inParamsPin.y
507630

508631
height: isFullyActive ? childrenRect.height : 0
509632
Behavior on height { PropertyAnimation {easing.type: Easing.Linear} }
510633
visible: (height == childrenRect.height)
511-
attribute: object
512-
readOnly: Boolean(root.readOnly || object.isReadOnly)
634+
635+
readOnly: Boolean(root.readOnly || modelData.isReadOnly)
513636
Component.onCompleted: attributePinCreated(attribute, inParamsPin)
514637
Component.onDestruction: attributePinDeleted(attribute, inParamsPin)
515638
onPressed: function(mouse) { root.pressed(mouse) }
639+
onClicked: {
640+
expanded = !expanded
641+
if (inputParams.parentPins.has(modelData.name)) {
642+
inputParams.parentPins.set(modelData.name, expanded)
643+
inputParams.parentPinsUpdated()
644+
}
645+
}
516646
onEdgeAboutToBeRemoved: function(input) { root.edgeAboutToBeRemoved(input) }
517647
onChildPinCreated: function(childAttribute, inParamsPin) { attributePinCreated(childAttribute, inParamsPin) }
518648
onChildPinDeleted: function(childAttribute, inParamsPin) { attributePinDeleted(childAttribute, inParamsPin) }

0 commit comments

Comments
 (0)