diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-12 18:26:42 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-08-22 10:13:40 -0700 |
commit | f25fa2adc5dd37aca17335d8278fd00e39e9b733 (patch) | |
tree | 29e7dd254c9ce065871ef9ebbf44b2615a215028 /core/subsurface-qt/CylinderObjectHelper.h | |
parent | 0d045f8c1470e011e0beff0ff0b0ec85975272e6 (diff) | |
download | subsurface-f25fa2adc5dd37aca17335d8278fd00e39e9b733.tar.gz |
Cleanup: turn CylinderObjectHelper into value type
CylinderObjectHelper is used for structured formatting of cylinder
values in grantlee types. Instead of keeping a reference to a
cylinder, turn it into a value type containing the formatted strings.
This should be distinctly safer, as we don't risk having stale
references flying around. Moreover, we don't have to use pointers
but can use containers containing plain CylinderObjectHelper. Thus,
no explicit memory management is needed, making the code distinctly
easier to understand.
Sadly, currently grantlee does not support Q_GADGET based Q_PROPERTY.
Therefore a GRANTLEE_*_LOOKUP block has to be added. This can be
removed in due course, as a patch to remedy this issue is in current
grantlee master.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/subsurface-qt/CylinderObjectHelper.h')
-rw-r--r-- | core/subsurface-qt/CylinderObjectHelper.h | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/core/subsurface-qt/CylinderObjectHelper.h b/core/subsurface-qt/CylinderObjectHelper.h index 8453bac01..f7df7f746 100644 --- a/core/subsurface-qt/CylinderObjectHelper.h +++ b/core/subsurface-qt/CylinderObjectHelper.h @@ -6,27 +6,24 @@ #include <QObject> #include <QString> -class CylinderObjectHelper : public QObject { - Q_OBJECT - Q_PROPERTY(QString description READ description CONSTANT) - Q_PROPERTY(QString size READ size CONSTANT) - Q_PROPERTY(QString workingPressure READ workingPressure CONSTANT) - Q_PROPERTY(QString startPressure READ startPressure CONSTANT) - Q_PROPERTY(QString endPressure READ endPressure CONSTANT) - Q_PROPERTY(QString gasMix READ gasMix CONSTANT) +class CylinderObjectHelper { + Q_GADGET + Q_PROPERTY(QString description MEMBER description CONSTANT) + Q_PROPERTY(QString size MEMBER size CONSTANT) + Q_PROPERTY(QString workingPressure MEMBER workingPressure CONSTANT) + Q_PROPERTY(QString startPressure MEMBER startPressure CONSTANT) + Q_PROPERTY(QString endPressure MEMBER endPressure CONSTANT) + Q_PROPERTY(QString gasMix MEMBER gasMix CONSTANT) public: CylinderObjectHelper(cylinder_t *cylinder = NULL); - ~CylinderObjectHelper(); - QString description() const; - QString size() const; - QString workingPressure() const; - QString startPressure() const; - QString endPressure() const; - QString gasMix() const; - -private: - cylinder_t *m_cyl; + QString description; + QString size; + QString workingPressure; + QString startPressure; + QString endPressure; + QString gasMix; }; - Q_DECLARE_METATYPE(CylinderObjectHelper *) +Q_DECLARE_METATYPE(CylinderObjectHelper) + #endif |