58
58
// Becomes true after an user presses the "="
59
59
property bool isLastCalculate: false;
61
property int numberOfOpenedBrackets: 0;
64
property bool isAllowedToAddDot: true;
66
61
property var decimalPoint: Qt.locale().decimalPoint
70
65
* place the result in right vars
72
67
function deleteLastFormulaElement() {
73
if (longFormula[longFormula.length - 1] === ".") {
74
isAllowedToAddDot = true;
77
68
longFormula = Formula.deleteLastFormulaElement(isLastCalculate, longFormula);
78
69
shortFormula = longFormula;
79
70
displayedInputText = returnFormulaToDisplay(longFormula);
82
73
function validateStringForAddingToFormula(stringToAddToFormula) {
83
74
if (Formula.isOperator(stringToAddToFormula)) {
84
if ((longFormula === '') && (stringToAddToFormula !== '-')) {
85
// Do not add operator at beginning
89
if ((Formula.isOperator(previousVisual) && previousVisual !== ")")) {
90
// Not two operator one after otQt.locale().decimalPointher
95
if (isNaN(stringToAddToFormula)) {
96
if (stringToAddToFormula !== ".") {
97
isAllowedToAddDot = true
101
if (stringToAddToFormula[stringToAddToFormula.length - 1] === "(") {
102
numberOfOpenedBrackets = numberOfOpenedBrackets + 1
103
} else if (stringToAddToFormula === ")") {
104
// Do not allow closing brackets after opening bracket
105
// and do not allow adding too much closing brackets
106
if ((previousVisual === "(") || (numberOfOpenedBrackets < 1)) {
109
numberOfOpenedBrackets = numberOfOpenedBrackets - 1
110
} else if (stringToAddToFormula === ".") {
111
//Do not allow to have two decimal separators in the same number
112
if (isAllowedToAddDot === false) {
116
isAllowedToAddDot = false;
75
return Formula.couldAddOperator(stringToAddToFormula, longFormula);
78
if (stringToAddToFormula === ".") {
79
return Formula.couldAddDot(longFormula);
82
if (stringToAddToFormula === ")") {
83
return Formula.couldAddCloseBracket(longFormula);
197
165
calculationHistory.addCalculationToDatabase(longFormula, result);
198
166
longFormula = result;
199
167
shortFormula = result;
200
numberOfOpenedBrackets = 0;
201
if (result % 1 != 0) {
202
isAllowedToAddDot = false;
204
isAllowedToAddDot = true;
208
170
CalculationHistory {