From 718c07c1a864ae307306fc54d3a8ba38e30bf759 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 22 Aug 2019 19:40:42 +0200 Subject: Grantlee: split out grantlee-only property from DiveObjectHelper The cylindersObject list was only used by grantlee but not by the mobile code. Since it is quite heavy, split it out and thus don't generate it for every dive on mobile. Signed-off-by: Berthold Stoeger --- core/subsurface-qt/DiveObjectHelper.cpp | 11 ++++++++++- core/subsurface-qt/DiveObjectHelper.h | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'core') diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index ec62a9fec..9e4ff47bb 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -238,7 +238,6 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) : singleWeight(d->weightsystems.nr <= 1), suit(d->suit ? d->suit : QString()), cylinders(formatCylinders(d)), - cylinderObjects(makeCylinderObjects(d)), maxcns(d->maxcns), otu(d->otu), sumWeight(get_weight_string(weight_t { total_weight(d) }, true)), @@ -249,6 +248,16 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) : { } +DiveObjectHelperGrantlee::DiveObjectHelperGrantlee() +{ +} + +DiveObjectHelperGrantlee::DiveObjectHelperGrantlee(const struct dive *d) : + DiveObjectHelper(d), + cylinderObjects(makeCylinderObjects(d)) +{ +} + QString DiveObjectHelper::date() const { QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000 * timestamp, Qt::UTC); diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h index 5e6b0c7e1..639dae696 100644 --- a/core/subsurface-qt/DiveObjectHelper.h +++ b/core/subsurface-qt/DiveObjectHelper.h @@ -39,7 +39,6 @@ class DiveObjectHelper { Q_PROPERTY(QString suit MEMBER suit CONSTANT) Q_PROPERTY(QStringList cylinderList READ cylinderList CONSTANT) Q_PROPERTY(QStringList cylinders MEMBER cylinders CONSTANT) - Q_PROPERTY(QVector cylinderObjects MEMBER cylinderObjects CONSTANT) Q_PROPERTY(int maxcns MEMBER maxcns CONSTANT) Q_PROPERTY(int otu MEMBER otu CONSTANT) Q_PROPERTY(QString sumWeight MEMBER sumWeight CONSTANT) @@ -78,7 +77,6 @@ public: QString suit; QStringList cylinderList() const; QStringList cylinders; - QVector cylinderObjects; int maxcns; int otu; QString sumWeight; @@ -87,6 +85,21 @@ public: QStringList endPressure; QStringList firstGas; }; - Q_DECLARE_METATYPE(DiveObjectHelper) + +// This is an extended version of DiveObjectHelper that also keeps track of cylinder data. +// It is used by grantlee to display structured cylinder data. +// Note: this grantlee feature is undocumented. If there turns out to be no users, we might +// want to remove this class. +class DiveObjectHelperGrantlee : public DiveObjectHelper { + Q_GADGET + Q_PROPERTY(QVector cylinderObjects MEMBER cylinderObjects CONSTANT) +public: + DiveObjectHelperGrantlee(); + DiveObjectHelperGrantlee(const struct dive *dive); + QVector cylinderObjects; +}; + +Q_DECLARE_METATYPE(DiveObjectHelper) +Q_DECLARE_METATYPE(DiveObjectHelperGrantlee) #endif -- cgit v1.2.3-70-g09d2