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 | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 7 | |
| 8 | class Cell : public QObject |
| 9 | { |
| 10 | Q_OBJECT |
| 11 | QML_ELEMENT |
| 12 | |
| 13 | Q_PROPERTY(QString code READ code WRITE setCode NOTIFY codeChanged) |
| 14 | Q_PROPERTY(QString result READ result WRITE setResult NOTIFY resultChanged) |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 15 | Q_PROPERTY(QUuid uuid READ uuid NOTIFY uuidChanged) |
| 16 | Q_PROPERTY(int status READ status WRITE setStatus NOTIFY statusChanged) |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 17 | |
| 18 | public: |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 19 | ~Cell(); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 20 | explicit Cell(QObject *parent = nullptr); |
| 21 | Cell(const Cell ©, QObject *parent = nullptr); |
| 22 | Cell(QString code, QString result, QObject *parent = nullptr); |
| 23 | |
| 24 | Cell &operator =(const Cell ©); |
| 25 | |
| 26 | QString code() const; |
| 27 | QString result() const; |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 28 | QUuid uuid() const; |
| 29 | int status() const; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 30 | |
| 31 | void setCode(QString code); |
| 32 | void setResult(QString result); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 33 | void setStatus(int status); |
| 34 | |
| 35 | Q_INVOKABLE static Cell *cellFromUuid(QUuid uuid); |
| 36 | |
| 37 | enum Status |
| 38 | { |
| 39 | RUNNING, |
| 40 | IDLE, |
| 41 | WAITING, |
| 42 | }; |
| 43 | |
| 44 | Q_ENUM(Status); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 45 | |
| 46 | signals: |
| 47 | void codeChanged(QString code); |
| 48 | void resultChanged(QString result); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 49 | void uuidChanged(QUuid uuid); |
| 50 | void statusChanged(int status); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 51 | |
| 52 | private: |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 53 | int _status = IDLE; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 54 | QString _code, _result; |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 55 | QUuid _uuid = QUuid::createUuid(); |
| 56 | |
| 57 | static QHash<QUuid, Cell *> _cellUuids; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | Q_DECLARE_METATYPE(Cell) |