From 2cec69949d19fa0848abef6f52ced655fac80c0b Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 9 Nov 2014 16:01:25 +0200 Subject: [PATCH] Fix for unary minus operation. --HG-- branch : develop --- src/app/container/calculator.cpp | 17 +++++++++++++++++ src/app/container/calculator.h | 1 + 2 files changed, 18 insertions(+) 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