swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 1 | #include "Cell.h" |
| 2 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 3 | QHash<QUuid, Cell *> Cell::_cellUuids = QHash<QUuid, Cell*>(); |
| 4 | |
| 5 | Cell::~Cell() |
| 6 | { |
| 7 | _cellUuids.remove(_uuid); |
| 8 | } |
| 9 | |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 10 | Cell::Cell(QObject *parent) : QObject(parent) |
| 11 | { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 12 | _cellUuids[_uuid] = this; |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | Cell::Cell(const Cell ©, QObject *parent) |
| 16 | : Cell(parent) |
| 17 | { |
| 18 | *this = copy; |
| 19 | } |
| 20 | |
| 21 | Cell::Cell(QString code, QString result, QObject *parent) |
| 22 | : Cell(parent) |
| 23 | { |
| 24 | setCode(code); |
| 25 | setResult(result); |
| 26 | } |
| 27 | |
| 28 | Cell &Cell::operator =(const Cell ©) |
| 29 | { |
| 30 | setCode(copy.code()); |
| 31 | setResult(copy.result()); |
| 32 | |
| 33 | return *this; |
| 34 | } |
| 35 | |
| 36 | QString Cell::code() const |
| 37 | { |
| 38 | return _code; |
| 39 | } |
| 40 | |
| 41 | QString Cell::result() const |
| 42 | { |
| 43 | return _result; |
| 44 | } |
| 45 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 46 | QUuid Cell::uuid() const |
| 47 | { |
| 48 | return _uuid; |
| 49 | } |
| 50 | |
| 51 | int Cell::status() const |
| 52 | { |
| 53 | return _status; |
| 54 | } |
| 55 | |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 56 | int Cell::resultType() const |
| 57 | { |
| 58 | return _resultType; |
| 59 | } |
| 60 | |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 61 | void Cell::setCode(QString code) |
| 62 | { |
| 63 | _code = code; |
| 64 | emit codeChanged(code); |
| 65 | } |
| 66 | |
| 67 | void Cell::setResult(QString result) |
| 68 | { |
| 69 | _result = result; |
| 70 | emit resultChanged(result); |
| 71 | } |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 72 | |
| 73 | void Cell::setStatus(int status) |
| 74 | { |
| 75 | _status = status; |
| 76 | emit statusChanged(status); |
| 77 | } |
| 78 | |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 79 | void Cell::setResultType(int resultType) |
| 80 | { |
| 81 | _resultType = resultType; |
| 82 | emit resultTypeChanged(resultType); |
| 83 | } |
| 84 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 85 | Cell *Cell::cellFromUuid(QUuid uuid) |
| 86 | { |
| 87 | if (_cellUuids.contains(uuid)) |
| 88 | return _cellUuids[uuid]; |
| 89 | else |
| 90 | return nullptr; |
| 91 | } |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 92 | |
swissChili | d2af6ad | 2022-04-16 14:42:17 -0700 | [diff] [blame] | 93 | void Cell::fromJson(QJsonObject json) |
| 94 | { |
| 95 | setCode(json["code"].toString()); |
| 96 | setResult(json["result"].toString()); |
| 97 | setStatus(json["status"].toInt()); |
| 98 | setResultType(json["resultType"].toInt()); |
| 99 | } |
| 100 | |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 101 | QJsonObject Cell::toJson() const |
| 102 | { |
| 103 | QJsonObject object; |
| 104 | |
| 105 | object["code"] = code(); |
| 106 | object["result"] = result(); |
| 107 | object["status"] = status(); |
| 108 | object["resultType"] = resultType(); |
| 109 | |
| 110 | return object; |
| 111 | } |