Skip to content

Commit 2ec560b

Browse files
committed
[qml] AttributeItemDelegate: Handle keyable attribute cases
- display value or default value at current viewId for keyable attribute. - allows to set/update current viewId value for keyable attribute. - new add/remove key button for keyable attribute.
1 parent 4348acd commit 2ec560b

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ RowLayout {
149149
}
150150
MenuItem {
151151
text: "Copy"
152-
enabled: attribute.value != ""
152+
enabled: !attribute.keyable && attribute.value != ""
153153
onTriggered: {
154154
Clipboard.clear()
155155
Clipboard.setText(attribute.value)
156156
}
157157
}
158158
MenuItem {
159159
text: "Paste"
160-
enabled: Clipboard.getText() != "" && root.editable
160+
enabled: Clipboard.getText() != "" && !attribute.keyable && root.editable
161161
onTriggered: {
162162
_reconstruction.setAttribute(attribute, Clipboard.getText())
163163
}
@@ -259,7 +259,10 @@ RowLayout {
259259
switch (attribute.type) {
260260
case "IntParam":
261261
case "FloatParam":
262-
_reconstruction.setAttribute(root.attribute, Number(value))
262+
if(attribute.keyable)
263+
_reconstruction.addAttributeKeyValue(root.attribute, _reconstruction.selectedViewId, Number(value))
264+
else
265+
_reconstruction.setAttribute(root.attribute, Number(value))
263266
updateAttributeLabel()
264267
break
265268
case "File":
@@ -273,11 +276,12 @@ RowLayout {
273276
}
274277

275278
Loader {
279+
id: attributeLoader
276280
Layout.fillWidth: true
277281

278282
sourceComponent: {
279283
// PushButtonParam always has value == undefined, so it needs to be excluded from this check
280-
if (attribute.type != "PushButtonParam" && attribute.value === undefined) {
284+
if (attribute.type != "PushButtonParam" && !attribute.keyable && attribute.value === undefined) {
281285
return notComputedComponent
282286
}
283287
switch (attribute.type) {
@@ -617,7 +621,9 @@ RowLayout {
617621
Layout.fillWidth: !slider.active
618622
enabled: root.editable
619623
// Cast value to string to avoid intrusive scientific notations on numbers
620-
property string displayValue: String(slider.active && slider.item.pressed ? slider.item.formattedValue : attribute.value)
624+
property string displayValue: String(slider.active && slider.item.pressed ? slider.item.formattedValue :
625+
attribute.keyable ? attribute.keyValues.getValueAtKeyOrDefault(_reconstruction.selectedViewId) :
626+
attribute.value)
621627
text: displayValue
622628
selectByMouse: true
623629
// Note: Use autoScroll as a workaround for alignment
@@ -652,15 +658,18 @@ RowLayout {
652658
readonly property int stepDecimalCount: stepSize < 1 ? String(stepSize).split(".").pop().length : 0
653659
readonly property real formattedValue: value.toFixed(stepDecimalCount)
654660
enabled: root.editable
655-
value: attribute.value
661+
value: attribute.keyable ? attribute.keyValues.getValueAtKeyOrDefault(_reconstruction.selectedViewId) : attribute.value
656662
from: attribute.desc.range[0]
657663
to: attribute.desc.range[1]
658664
stepSize: attribute.desc.range[2]
659665
snapMode: Slider.SnapAlways
660666

661667
onPressedChanged: {
662668
if (!pressed) {
663-
_reconstruction.setAttribute(attribute, formattedValue)
669+
if(attribute.keyable)
670+
_reconstruction.addAttributeKeyValue(attribute, _reconstruction.selectedViewId, formattedValue)
671+
else
672+
_reconstruction.setAttribute(attribute, formattedValue)
664673
updateAttributeLabel()
665674
}
666675
}
@@ -674,8 +683,18 @@ RowLayout {
674683
Row {
675684
CheckBox {
676685
enabled: root.editable
677-
checked: attribute.value
678-
onToggled: _reconstruction.setAttribute(attribute, !attribute.value)
686+
checked: attribute.keyable ? attribute.keyValues.getValueAtKeyOrDefault(_reconstruction.selectedViewId) : attribute.value
687+
onToggled: {
688+
if(attribute.keyable)
689+
{
690+
const value = attribute.keyValues.getValueAtKeyOrDefault(_reconstruction.selectedViewId)
691+
_reconstruction.addAttributeKeyValue(attribute, _reconstruction.selectedViewId, !value)
692+
}
693+
else
694+
{
695+
_reconstruction.setAttribute(attribute, !attribute.value)
696+
}
697+
}
679698
}
680699
}
681700
}
@@ -831,4 +850,23 @@ RowLayout {
831850
}
832851
}
833852
}
853+
854+
// Add or remove key button for keyable attribute
855+
Loader {
856+
active: attribute.keyable
857+
sourceComponent: MaterialToolButton {
858+
font.pointSize: 5
859+
padding: 6
860+
text: MaterialIcons.circle
861+
checkable: true
862+
checked: attribute.keyable && attribute.keyValues.hasKey(_reconstruction.selectedViewId)
863+
enabled: root.editable
864+
onClicked: {
865+
if (attribute.keyValues.hasKey(_reconstruction.selectedViewId))
866+
_reconstruction.removeAttributeKey(attribute, _reconstruction.selectedViewId)
867+
else
868+
_reconstruction.addAttributeKeyDefaultValue(attribute, _reconstruction.selectedViewId)
869+
}
870+
}
871+
}
834872
}

0 commit comments

Comments
 (0)