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 | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame^] | 41 | Q_INVOKABLE QJsonObject toJson() const; |
| 42 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 43 | enum Status |
| 44 | { |
| 45 | RUNNING, |
| 46 | IDLE, |
| 47 | WAITING, |
| 48 | }; |
| 49 | |
| 50 | Q_ENUM(Status); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 51 | |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 52 | enum ResultType |
| 53 | { |
| 54 | EXPRESSION, |
| 55 | DIAGNOSTIC |
| 56 | }; |
| 57 | |
| 58 | Q_ENUM(ResultType) |
| 59 | |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 60 | signals: |
| 61 | void codeChanged(QString code); |
| 62 | void resultChanged(QString result); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 63 | void uuidChanged(QUuid uuid); |
| 64 | void statusChanged(int status); |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 65 | void resultTypeChanged(int resultType); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 66 | |
| 67 | private: |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 68 | int _status = IDLE, _resultType = EXPRESSION; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 69 | QString _code, _result; |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 70 | QUuid _uuid = QUuid::createUuid(); |
| 71 | |
| 72 | static QHash<QUuid, Cell *> _cellUuids; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | Q_DECLARE_METATYPE(Cell) |