diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 34e629328..6d04df791 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -110,6 +110,10 @@ qreal Calculator::EvalFormula(const QString &formula) result = Eval(); QMap tokens = this->GetTokens(); + + // Remove "-" from tokens list if exist. If don't do that unary minus operation will broken. + RemoveAll(tokens, "-"); + if (tokens.isEmpty()) { return result; @@ -243,3 +247,16 @@ void Calculator::SetSepForTr(bool fromUser) SetDecSep('.'); } } + +//--------------------------------------------------------------------------------------------------------------------- +void Calculator::RemoveAll(QMap &map, const QString &val) +{ + QList listKeys = map.keys(val); + if (listKeys.size() > 0) + { + for (int i = 0; i < listKeys.size(); ++i) + { + map.remove(listKeys.at(i)); + } + } +} diff --git a/src/app/container/calculator.h b/src/app/container/calculator.h index 4431edf3c..c71cae22b 100644 --- a/src/app/container/calculator.h +++ b/src/app/container/calculator.h @@ -68,6 +68,7 @@ private: static qreal* AddVariable(const QString &a_szName, void *a_pUserData); void SetSepForEval(); void SetSepForTr(bool fromUser); + void RemoveAll(QMap &map, const QString &val); }; #endif // CALCULATOR_H