Fix for unary minus operation.

--HG--
branch : develop
This commit is contained in:
dismine 2014-11-09 16:01:25 +02:00
parent 33a235e8a3
commit 2cec69949d
2 changed files with 18 additions and 0 deletions

View File

@ -110,6 +110,10 @@ qreal Calculator::EvalFormula(const QString &formula)
result = Eval();
QMap<int, QString> 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<int, QString> &map, const QString &val)
{
QList<int> listKeys = map.keys(val);
if (listKeys.size() > 0)
{
for (int i = 0; i < listKeys.size(); ++i)
{
map.remove(listKeys.at(i));
}
}
}

View File

@ -68,6 +68,7 @@ private:
static qreal* AddVariable(const QString &a_szName, void *a_pUserData);
void SetSepForEval();
void SetSepForTr(bool fromUser);
void RemoveAll(QMap<int, QString> &map, const QString &val);
};
#endif // CALCULATOR_H