Skip to content

Commit b5317b1

Browse files
committed
[ui] ExpressionTextField: remove mathEvaluator on js and avoid double evaluation
1 parent 9e85f17 commit b5317b1

File tree

4 files changed

+25
-77
lines changed

4 files changed

+25
-77
lines changed

meshroom/ui/qml/GraphEditor/AttributeItemDelegate.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ RowLayout {
670670
if (!pressed) {
671671
_reconstruction.setAttribute(attribute, formattedValue)
672672
updateAttributeLabel()
673-
}
673+
}
674674
}
675675
}
676676
}

meshroom/ui/qml/Utils/ExpressionTextField.qml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ TextField {
66

77
// evaluated numeric value (NaN if invalid)
88
// It helps keeping the connection that text has so that we don't loose ability to undo/reset
9+
property bool textChanged: false
910
property real evaluatedValue: 0
1011

1112
property bool hasExprError: false
@@ -39,7 +40,7 @@ TextField {
3940
_res = _res.toFixed(decimals)
4041
return _res
4142
} else {
42-
console.error("Error : Expression", _text, "is invalid")
43+
console.error("Error: Expression", _text, "is invalid")
4344
return NaN
4445
}
4546
}
@@ -62,6 +63,7 @@ TextField {
6263
evaluatedValue = previousEvaluatedValue
6364
raiseError()
6465
}
66+
textChanged = false
6567
}
6668

6769
// onAccepted and onEditingFinished will break the bindings to text
@@ -70,29 +72,37 @@ TextField {
7072
// No need to restore the binding if the expression has an error because we don't break it
7173

7274
onAccepted: {
73-
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)
75+
if (textChanged)
76+
{
77+
updateExpression()
78+
if (!hasExprError && !isNaN(evaluatedValue)) {
79+
// Commit the result value to the text field
80+
if (isInt)
81+
root.text = Number(evaluatedValue).toFixed(0)
82+
else
83+
root.text = Number(evaluatedValue).toFixed(decimals)
84+
}
8085
}
8186
}
8287

8388
onEditingFinished: {
84-
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)
89+
if (textChanged)
90+
{
91+
updateExpression()
92+
if (!hasExprError && !isNaN(evaluatedValue)) {
93+
if (isInt)
94+
root.text = Number(evaluatedValue).toFixed(0)
95+
else
96+
root.text = Number(evaluatedValue).toFixed(decimals)
97+
}
9098
}
9199
}
92100

93101
onTextChanged: {
94102
if (!activeFocus) {
95103
refreshStatus()
104+
} else {
105+
textChanged = true
96106
}
97107
}
98108

meshroom/ui/qml/Utils/mathEvaluator.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

meshroom/ui/qml/Utils/qmldir

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ singleton ExifOrientation 1.0 ExifOrientation.qml
1111
# singleton Filepath 1.0 Filepath.qml
1212
# singleton Scene3DHelper 1.0 Scene3DHelper.qml
1313
# singleton Transformations3DHelper 1.0 Transformations3DHelper.qml
14-
MathEvaluator 1.0 mathEvaluator.js
1514
ExpressionTextField 1.0 ExpressionTextField.qml

0 commit comments

Comments
 (0)