blob: 350874c44dfd6db15ce82ac443c93ef053846165 [file] [log] [blame]
swissChili4b3105a2022-02-22 16:34:39 -08001#pragma once
2
3#include <QObject>
4#include <qqml.h>
swissChilid85daa92022-02-24 15:29:02 -08005#include <QUuid>
6#include <QHash>
swissChili505de412022-03-24 12:35:08 -07007#include <QJsonObject>
swissChili4b3105a2022-02-22 16:34:39 -08008
9class 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)
swissChilid85daa92022-02-24 15:29:02 -080016 Q_PROPERTY(QUuid uuid READ uuid NOTIFY uuidChanged)
17 Q_PROPERTY(int status READ status WRITE setStatus NOTIFY statusChanged)
swissChiliece1ac82022-02-25 11:20:42 -080018 Q_PROPERTY(int resultType READ resultType WRITE setResultType NOTIFY resultTypeChanged)
swissChili4b3105a2022-02-22 16:34:39 -080019
20public:
swissChilid85daa92022-02-24 15:29:02 -080021 ~Cell();
swissChili4b3105a2022-02-22 16:34:39 -080022 explicit Cell(QObject *parent = nullptr);
23 Cell(const Cell &copy, QObject *parent = nullptr);
24 Cell(QString code, QString result, QObject *parent = nullptr);
25
26 Cell &operator =(const Cell &copy);
27
28 QString code() const;
29 QString result() const;
swissChilid85daa92022-02-24 15:29:02 -080030 QUuid uuid() const;
31 int status() const;
swissChiliece1ac82022-02-25 11:20:42 -080032 int resultType() const;
swissChili4b3105a2022-02-22 16:34:39 -080033
34 void setCode(QString code);
35 void setResult(QString result);
swissChilid85daa92022-02-24 15:29:02 -080036 void setStatus(int status);
swissChiliece1ac82022-02-25 11:20:42 -080037 void setResultType(int resultType);
swissChilid85daa92022-02-24 15:29:02 -080038
39 Q_INVOKABLE static Cell *cellFromUuid(QUuid uuid);
40
swissChilid2af6ad2022-04-16 14:42:17 -070041 Q_INVOKABLE void fromJson(QJsonObject json);
swissChili505de412022-03-24 12:35:08 -070042 Q_INVOKABLE QJsonObject toJson() const;
43
swissChilid85daa92022-02-24 15:29:02 -080044 enum Status
45 {
46 RUNNING,
47 IDLE,
48 WAITING,
49 };
50
51 Q_ENUM(Status);
swissChili4b3105a2022-02-22 16:34:39 -080052
swissChiliece1ac82022-02-25 11:20:42 -080053 enum ResultType
54 {
55 EXPRESSION,
56 DIAGNOSTIC
57 };
58
59 Q_ENUM(ResultType)
60
swissChili4b3105a2022-02-22 16:34:39 -080061signals:
62 void codeChanged(QString code);
63 void resultChanged(QString result);
swissChilid85daa92022-02-24 15:29:02 -080064 void uuidChanged(QUuid uuid);
65 void statusChanged(int status);
swissChiliece1ac82022-02-25 11:20:42 -080066 void resultTypeChanged(int resultType);
swissChili4b3105a2022-02-22 16:34:39 -080067
68private:
swissChiliece1ac82022-02-25 11:20:42 -080069 int _status = IDLE, _resultType = EXPRESSION;
swissChili4b3105a2022-02-22 16:34:39 -080070 QString _code, _result;
swissChilid85daa92022-02-24 15:29:02 -080071 QUuid _uuid = QUuid::createUuid();
72
73 static QHash<QUuid, Cell *> _cellUuids;
swissChili4b3105a2022-02-22 16:34:39 -080074};
75
76Q_DECLARE_METATYPE(Cell)