From f25fa2adc5dd37aca17335d8278fd00e39e9b733 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 12 Aug 2019 18:26:42 +0200 Subject: 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 --- core/subsurface-qt/CylinderObjectHelper.cpp | 44 ++++++++--------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'core/subsurface-qt/CylinderObjectHelper.cpp') diff --git a/core/subsurface-qt/CylinderObjectHelper.cpp b/core/subsurface-qt/CylinderObjectHelper.cpp index f2216af6f..f8386c402 100644 --- a/core/subsurface-qt/CylinderObjectHelper.cpp +++ b/core/subsurface-qt/CylinderObjectHelper.cpp @@ -3,36 +3,16 @@ #include "../qthelper.h" static QString EMPTY_CYLINDER_STRING = QStringLiteral(""); -CylinderObjectHelper::CylinderObjectHelper(cylinder_t *cylinder) : - m_cyl(cylinder) { -} - -CylinderObjectHelper::~CylinderObjectHelper() { -} - -QString CylinderObjectHelper::description() const { - if (!m_cyl->type.description) - return QString(EMPTY_CYLINDER_STRING); - else - return QString(m_cyl->type.description); -} - -QString CylinderObjectHelper::size() const { - return get_volume_string(m_cyl->type.size, true); -} - -QString CylinderObjectHelper::workingPressure() const { - return get_pressure_string(m_cyl->type.workingpressure, true); -} - -QString CylinderObjectHelper::startPressure() const { - return get_pressure_string(m_cyl->start, true); -} - -QString CylinderObjectHelper::endPressure() const { - return get_pressure_string(m_cyl->end, true); -} - -QString CylinderObjectHelper::gasMix() const { - return get_gas_string(m_cyl->gasmix); +CylinderObjectHelper::CylinderObjectHelper(cylinder_t *cylinder) +{ + if (!cylinder) + return; + + description = cylinder->type.description ? cylinder->type.description: + EMPTY_CYLINDER_STRING; + size = get_volume_string(cylinder->type.size, true); + workingPressure = get_pressure_string(cylinder->type.workingpressure, true); + startPressure = get_pressure_string(cylinder->start, true); + endPressure = get_pressure_string(cylinder->end, true); + gasMix = get_gas_string(cylinder->gasmix); } -- cgit v1.2.3-70-g09d2