swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <QObject> |
| 4 | #include <qqml.h> |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 5 | #include <QUuid> |
| 6 | #include <QHash> |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 7 | #include <QJsonObject> |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 8 | |
| 9 | class Cell : public QObject |
| 10 | { |
| 11 | Q_OBJECT |
| 12 | QML_ELEMENT |
| 13 | |
| 14 | Q_PROPERTY(QString code READ code WRITE setCode NOTIFY codeChanged) |
| 15 | Q_PROPERTY(QString result READ result WRITE setResult NOTIFY resultChanged) |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 16 | Q_PROPERTY(QUuid uuid READ uuid NOTIFY uuidChanged) |
| 17 | Q_PROPERTY(int status READ status WRITE setStatus NOTIFY statusChanged) |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 18 | Q_PROPERTY(int resultType READ resultType WRITE setResultType NOTIFY resultTypeChanged) |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 19 | |
| 20 | public: |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 21 | ~Cell(); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 22 | explicit Cell(QObject *parent = nullptr); |
| 23 | Cell(const Cell ©, QObject *parent = nullptr); |
| 24 | Cell(QString code, QString result, QObject *parent = nullptr); |
| 25 | |
| 26 | Cell &operator =(const Cell ©); |
| 27 | |
| 28 | QString code() const; |
| 29 | QString result() const; |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 30 | QUuid uuid() const; |
| 31 | int status() const; |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 32 | int resultType() const; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 33 | |
| 34 | void setCode(QString code); |
| 35 | void setResult(QString result); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 36 | void setStatus(int status); |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 37 | void setResultType(int resultType); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 38 | |
| 39 | Q_INVOKABLE static Cell *cellFromUuid(QUuid uuid); |
| 40 | |
swissChili | d2af6ad | 2022-04-16 14:42:17 -0700 | [diff] [blame] | 41 | Q_INVOKABLE void fromJson(QJsonObject json); |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 42 | Q_INVOKABLE QJsonObject toJson() const; |
| 43 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 44 | enum Status |
| 45 | { |
| 46 | RUNNING, |
| 47 | IDLE, |
| 48 | WAITING, |
| 49 | }; |
| 50 | |
| 51 | Q_ENUM(Status); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 52 | |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 53 | enum ResultType |
| 54 | { |
| 55 | EXPRESSION, |
| 56 | DIAGNOSTIC |
| 57 | }; |
| 58 | |
| 59 | Q_ENUM(ResultType) |
| 60 | |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 61 | signals: |
| 62 | void codeChanged(QString code); |
| 63 | void resultChanged(QString result); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 64 | void uuidChanged(QUuid uuid); |
| 65 | void statusChanged(int status); |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 66 | void resultTypeChanged(int resultType); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 67 | |
| 68 | private: |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 69 | int _status = IDLE, _resultType = EXPRESSION; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 70 | QString _code, _result; |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 71 | QUuid _uuid = QUuid::createUuid(); |
| 72 | |
| 73 | static QHash<QUuid, Cell *> _cellUuids; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | Q_DECLARE_METATYPE(Cell) |