Fix for unary minus operation.
--HG-- branch : develop
This commit is contained in:
parent
33a235e8a3
commit
2cec69949d
|
@ -110,6 +110,10 @@ qreal Calculator::EvalFormula(const QString &formula)
|
||||||
result = Eval();
|
result = Eval();
|
||||||
|
|
||||||
QMap<int, QString> tokens = this->GetTokens();
|
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())
|
if (tokens.isEmpty())
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
|
@ -243,3 +247,16 @@ void Calculator::SetSepForTr(bool fromUser)
|
||||||
SetDecSep('.');
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ private:
|
||||||
static qreal* AddVariable(const QString &a_szName, void *a_pUserData);
|
static qreal* AddVariable(const QString &a_szName, void *a_pUserData);
|
||||||
void SetSepForEval();
|
void SetSepForEval();
|
||||||
void SetSepForTr(bool fromUser);
|
void SetSepForTr(bool fromUser);
|
||||||
|
void RemoveAll(QMap<int, QString> &map, const QString &val);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CALCULATOR_H
|
#endif // CALCULATOR_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user