diff options
Diffstat (limited to 'plugin/src/Caelestia/qalculator.cpp')
| -rw-r--r-- | plugin/src/Caelestia/qalculator.cpp | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/plugin/src/Caelestia/qalculator.cpp b/plugin/src/Caelestia/qalculator.cpp deleted file mode 100644 index 44e8d21..0000000 --- a/plugin/src/Caelestia/qalculator.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "qalculator.hpp" - -#include <libqalculate/qalculate.h> - -namespace caelestia { - -Qalculator::Qalculator(QObject* parent) - : QObject(parent) { - if (!CALCULATOR) { - new Calculator(); - CALCULATOR->loadExchangeRates(); - CALCULATOR->loadGlobalDefinitions(); - CALCULATOR->loadLocalDefinitions(); - } -} - -QString Qalculator::eval(const QString& expr, bool printExpr) const { - if (expr.isEmpty()) { - return QString(); - } - - EvaluationOptions eo; - PrintOptions po; - - std::string parsed; - std::string result = CALCULATOR->calculateAndPrint( - CALCULATOR->unlocalizeExpression(expr.toStdString(), eo.parse_options), 100, eo, po, &parsed); - - std::string error; - while (CALCULATOR->message()) { - if (!CALCULATOR->message()->message().empty()) { - if (CALCULATOR->message()->type() == MESSAGE_ERROR) { - error += "error: "; - } else if (CALCULATOR->message()->type() == MESSAGE_WARNING) { - error += "warning: "; - } - error += CALCULATOR->message()->message(); - } - CALCULATOR->nextMessage(); - } - if (!error.empty()) { - return QString::fromStdString(error); - } - - if (printExpr) { - return QString("%1 = %2").arg(parsed).arg(result); - } - - return QString::fromStdString(result); -} - -} // namespace caelestia |