Skip to content

Commit 9e85f17

Browse files
committed
[ui] ExpressionTextField : fix binding issues on hdrtoolbar and attributedelegate
1 parent ea944d0 commit 9e85f17

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,18 @@ RowLayout {
622622
isInt: attribute.type === "FloatParam" ? false : true
623623

624624
onEditingFinished: {
625-
if (!hasExprError)
625+
if (!hasExprError) {
626626
setTextFieldAttribute(expressionTextField.evaluatedValue)
627+
// Restore binding
628+
expressionTextField.text = Qt.binding(function() { return String(expressionTextField.displayValue); })
629+
}
627630
}
628631
onAccepted: {
629-
if (!hasExprError)
632+
if (!hasExprError) {
630633
setTextFieldAttribute(expressionTextField.evaluatedValue)
634+
// Restore binding
635+
expressionTextField.text = Qt.binding(function() { return String(expressionTextField.displayValue); })
636+
}
631637
// When the text is too long, display the left part
632638
// (with the most important values and cut the floating point details)
633639
ensureVisible(0)
@@ -664,7 +670,7 @@ RowLayout {
664670
if (!pressed) {
665671
_reconstruction.setAttribute(attribute, formattedValue)
666672
updateAttributeLabel()
667-
}
673+
}
668674
}
669675
}
670676
}

meshroom/ui/qml/Utils/ExpressionTextField.qml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ TextField {
3030
hasExprError = false
3131
}
3232

33-
function reset(_value) {
34-
clearError()
35-
evaluatedValue = _value
36-
if (isInt) {
37-
root.text = _value.toFixed(0)
38-
} else {
39-
root.text = _value.toFixed(decimals)
40-
}
41-
}
42-
4333
function getEvalExpression(_text) {
4434
var [_res, _err] = _reconstruction.evaluateMathExpression(_text)
4535
if (_err == false) {
@@ -49,7 +39,7 @@ TextField {
4939
_res = _res.toFixed(decimals)
5040
return _res
5141
} else {
52-
console.error("Error evaluating expression (", _text, "):", _err)
42+
console.error("Error : Expression", _text, "is invalid")
5343
return NaN
5444
}
5545
}
@@ -65,27 +55,39 @@ TextField {
6555
function updateExpression() {
6656
var previousEvaluatedValue = evaluatedValue
6757
var result = getEvalExpression(root.text)
68-
console.log("[ExpressionTextField] updateExpression", root.text, "->", result)
6958
if (!isNaN(result)) {
7059
evaluatedValue = result
7160
clearError()
72-
// return result
7361
} else {
7462
evaluatedValue = previousEvaluatedValue
7563
raiseError()
76-
// return NaN
7764
}
7865
}
7966

80-
// When user commits input, evaluate but do NOT overwrite text
67+
// onAccepted and onEditingFinished will break the bindings to text
68+
// so if used on fields that needs to be driven by sliders or other qml element,
69+
// the binding needs to be restored
70+
// No need to restore the binding if the expression has an error because we don't break it
71+
8172
onAccepted: {
82-
console.log("[ExpressionTextField] onAccepted", root.text)
8373
updateExpression()
74+
if (!hasExprError && !isNaN(evaluatedValue)) {
75+
// Commit the result value to the text field
76+
if (isInt)
77+
root.text = Number(evaluatedValue).toFixed(0)
78+
else
79+
root.text = Number(evaluatedValue).toFixed(decimals)
80+
}
8481
}
8582

8683
onEditingFinished: {
87-
console.log("[ExpressionTextField] onEditingFinished", root.text)
8884
updateExpression()
85+
if (!hasExprError && !isNaN(evaluatedValue)) {
86+
if (isInt)
87+
root.text = Number(evaluatedValue).toFixed(0)
88+
else
89+
root.text = Number(evaluatedValue).toFixed(decimals)
90+
}
8991
}
9092

9193
onTextChanged: {
@@ -95,7 +97,6 @@ TextField {
9597
}
9698

9799
Component.onCompleted: {
98-
console.log("[ExpressionTextField] onCompleted", root.text)
99100
refreshStatus()
100101
}
101102
}

meshroom/ui/qml/Viewer/HdrImageToolbar.qml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ FloatingPane {
112112
ToolTip.text: "Reset Gain"
113113

114114
onClicked: {
115-
gainCtrl.value = gainDefaultValue
116-
gainLabel.reset(gainValue)
115+
gainLabel.text = gainDefaultValue
116+
gainCtrl.value = gainLabel.text
117117
}
118118
}
119119
ExpressionTextField {
@@ -130,14 +130,11 @@ FloatingPane {
130130
onAccepted: {
131131
if (!gainLabel.hasExprError) {
132132
if (gainLabel.text <= 0) {
133-
gainLabel.text = 0
134-
gainCtrl.value = gainLabel.text
133+
gainLabel.evaluatedValue = 0
134+
gainCtrl.value = gainLabel.evaluatedValue
135135
} else {
136-
gainCtrl.value = Math.pow(Number(gainLabel.text), 1.0 / slidersPowerValue)
136+
gainCtrl.value = Math.pow(Number(gainLabel.evaluatedValue), 1.0 / slidersPowerValue)
137137
}
138-
} else {
139-
// gainLabel.text = 0
140-
// gainCtrl.value = gainLabel.text
141138
}
142139
}
143140
}
@@ -148,7 +145,9 @@ FloatingPane {
148145
to: 2
149146
value: gainDefaultValue
150147
stepSize: 0.01
151-
onMoved: gainLabel.reset(Math.pow(value, slidersPowerValue))
148+
onMoved: {
149+
gainLabel.text = Math.pow(value, slidersPowerValue).toFixed(2)
150+
}
152151
}
153152
}
154153

@@ -164,8 +163,8 @@ FloatingPane {
164163
ToolTip.text: "Reset Gamma"
165164

166165
onClicked: {
167-
gammaCtrl.value = gammaDefaultValue;
168-
gammaLabel.reset(gammaValue)
166+
gammaLabel.text = gammaDefaultValue
167+
gammaCtrl.value = gammaLabel.text;
169168
}
170169
}
171170
ExpressionTextField {
@@ -180,17 +179,13 @@ FloatingPane {
180179
Layout.preferredWidth: textMetrics_gainValue.width
181180
selectByMouse: true
182181
onAccepted: {
183-
console.log("[GammaTextField] onAccepted")
184182
if (!gammaLabel.hasExprError) {
185183
if (gammaLabel.evaluatedValue <= 0) {
186184
gammaLabel.evaluatedValue = 0
187185
gammaCtrl.value = gammaLabel.evaluatedValue
188186
} else {
189187
gammaCtrl.value = Math.pow(Number(gammaLabel.evaluatedValue), 1.0 / slidersPowerValue)
190188
}
191-
} else {
192-
// gammaLabel.evaluatedValue = 0
193-
// gammaCtrl.value = gainLabel.evaluatedValue
194189
}
195190
}
196191
}
@@ -201,7 +196,9 @@ FloatingPane {
201196
to: 2
202197
value: gammaDefaultValue
203198
stepSize: 0.01
204-
onMoved: gammaLabel.reset(Math.pow(value, slidersPowerValue))
199+
onMoved: {
200+
gammaLabel.text = Math.pow(value, slidersPowerValue).toFixed(2)
201+
}
205202
}
206203
}
207204

meshroom/ui/reconstruction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ def evaluateMathExpression(self, expr):
11791179
res = mev.evaluate(expr)
11801180
return [res, False]
11811181
except Exception as err:
1182-
return [None, err]
1182+
return [None, True]
11831183

11841184
selectedViewIdChanged = Signal()
11851185
selectedViewId = Property(str, lambda self: self._selectedViewId, setSelectedViewId, notify=selectedViewIdChanged)

0 commit comments

Comments
 (0)