File indexing completed on 2024-05-19 09:31:37

0001 /*
0002     SPDX-FileCopyrightText: 2010 Matteo Agostinelli <agostinelli@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QAtomicInt>
0010 #include <QObject>
0011 
0012 class KJob;
0013 
0014 class QalculateEngine : public QObject
0015 {
0016     Q_OBJECT
0017 public:
0018     explicit QalculateEngine(QObject *parent = nullptr);
0019     ~QalculateEngine() override;
0020 
0021     QString lastResult() const
0022     {
0023         return m_lastResult;
0024     }
0025 
0026     static bool findPrefix(QString basePrefix, int *base, QString *customBase);
0027 
0028     // This is not static, because the CALCULATOR needs to be initialized
0029     bool isKnownFunction(const QString &str);
0030 
0031 public Q_SLOTS:
0032     QString evaluate(const QString &expression, bool *isApproximate = nullptr, int base = 10, const QString &customBase = "");
0033     void updateExchangeRates();
0034 
0035 protected Q_SLOTS:
0036     void updateResult(KJob *);
0037 
0038 private:
0039     QString m_lastResult;
0040     static QAtomicInt s_counter;
0041 };