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/DiveObjectHelper.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'core/subsurface-qt/DiveObjectHelper.cpp') diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index 6d625473e..ec4c8d65f 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -60,20 +60,13 @@ DiveObjectHelper::DiveObjectHelper(struct dive *d) : { if (!m_dive) qWarning("Creating DiveObjectHelper from NULL dive"); - m_cyls.clear(); for (int i = 0; i < MAX_CYLINDERS; i++) { //Don't add blank cylinders, only those that have been defined. if (m_dive->cylinder[i].type.description) - m_cyls.append(new CylinderObjectHelper(&m_dive->cylinder[i])); + m_cyls.append(CylinderObjectHelper(&m_dive->cylinder[i])); } } -DiveObjectHelper::~DiveObjectHelper() -{ -while (!m_cyls.isEmpty()) - delete m_cyls.takeFirst(); -} - int DiveObjectHelper::number() const { return m_dive->number; @@ -316,7 +309,7 @@ QString DiveObjectHelper::cylinder(int idx) const return getFormattedCylinder(m_dive, idx); } -QList DiveObjectHelper::cylinderObjects() const +QVector DiveObjectHelper::cylinderObjects() const { return m_cyls; } -- cgit v1.2.3-70-g09d2