@@ -6,12 +6,11 @@ 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
9+ property bool exprTextChanged : false
1010 property real evaluatedValue: 0
1111
1212 property bool hasExprError: false
1313 property bool isInt: false
14- property int decimals: 2
1514
1615 // Overlay for error state (red border on top of default background)
1716 Rectangle {
@@ -36,8 +35,6 @@ TextField {
3635 if (_err == false ) {
3736 if (isInt)
3837 _res = Math .round (_res)
39- else
40- _res = _res .toFixed (decimals)
4138 return _res
4239 } else {
4340 console .error (" Error: Expression" , _text, " is invalid" )
@@ -63,7 +60,7 @@ TextField {
6360 evaluatedValue = previousEvaluatedValue
6461 raiseError ()
6562 }
66- textChanged = false
63+ exprTextChanged = false
6764 }
6865
6966 // onAccepted and onEditingFinished will break the bindings to text
@@ -72,42 +69,42 @@ TextField {
7269 // No need to restore the binding if the expression has an error because we don't break it
7370
7471 onAccepted: {
75- if (textChanged )
72+ if (exprTextChanged )
7673 {
7774 updateExpression ()
7875 if (! hasExprError && ! isNaN (evaluatedValue)) {
7976 // Commit the result value to the text field
8077 if (isInt)
8178 root .text = Number (evaluatedValue).toFixed (0 )
8279 else
83- root .text = Number (evaluatedValue). toFixed (decimals)
80+ root .text = Number (evaluatedValue)
8481 }
8582 }
8683 }
8784
8885 onEditingFinished: {
89- if (textChanged )
86+ if (exprTextChanged )
9087 {
9188 updateExpression ()
9289 if (! hasExprError && ! isNaN (evaluatedValue)) {
9390 if (isInt)
9491 root .text = Number (evaluatedValue).toFixed (0 )
9592 else
96- root .text = Number (evaluatedValue). toFixed (decimals)
93+ root .text = Number (evaluatedValue)
9794 }
9895 }
9996 }
10097
10198 onTextChanged: {
102- if (! activeFocus) {
99+ if (! activeFocus && exprTextChanged ) {
103100 refreshStatus ()
104101 } else {
105- textChanged = true
102+ exprTextChanged = true
106103 }
107104 }
108105
109106 Component .onDestruction : {
110- if (textChanged ) {
107+ if (exprTextChanged ) {
111108 root .accepted ()
112109 }
113110 }
0 commit comments