diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-12-14 23:21:58 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-12-17 13:03:56 -0800 |
commit | d9942269a9b61bc35bd939b23858a7cb4a2515c3 (patch) | |
tree | 92a60687efdfbd89df1aa29d7a105487c3db16d3 /core | |
parent | bf8261c0014253634eaddf7c0a9cf79d3a8b4123 (diff) | |
download | subsurface-d9942269a9b61bc35bd939b23858a7cb4a2515c3.tar.gz |
printing: remove DiveObjectHelperGrantlee
This was a weird helper object, needed for grantlee. Instead
of storing this object, loop over cylinders and dives directly.
The actual accessor function is unchanged and now generates
a DiveObjectHelper or DiveCylinderHelper for every variable
access. Obviously, this is very inefficient. However, this
will be replaced in future commits by direct calls to formatting
functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/string-format.cpp | 21 | ||||
-rw-r--r-- | core/string-format.h | 1 | ||||
-rw-r--r-- | core/subsurface-qt/diveobjecthelper.cpp | 43 | ||||
-rw-r--r-- | core/subsurface-qt/diveobjecthelper.h | 14 |
4 files changed, 22 insertions, 57 deletions
diff --git a/core/string-format.cpp b/core/string-format.cpp index 331fb64ba..3f5d7d812 100644 --- a/core/string-format.cpp +++ b/core/string-format.cpp @@ -143,3 +143,24 @@ QStringList formatFullCylinderList() return cylinders; } +static QString formattedCylinder(const struct dive *dive, int idx) +{ + const cylinder_t *cyl = get_cylinder(dive, idx); + const char *desc = cyl->type.description; + QString fmt = desc ? QString(desc) : gettextFromC::tr("unknown"); + fmt += ", " + get_volume_string(cyl->type.size, true); + fmt += ", " + get_pressure_string(cyl->type.workingpressure, true); + fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true); + fmt += ", " + get_gas_string(cyl->gasmix); + return fmt; +} + +QStringList formatCylinders(const dive *d) +{ + QStringList cylinders; + for (int i = 0; i < d->cylinders.nr; i++) { + QString cyl = formattedCylinder(d, i); + cylinders << cyl; + } + return cylinders; +} diff --git a/core/string-format.h b/core/string-format.h index 96a9638e4..cbe6336db 100644 --- a/core/string-format.h +++ b/core/string-format.h @@ -15,5 +15,6 @@ QStringList formatStartPressure(const dive *d); QStringList formatEndPressure(const dive *d); QStringList formatFirstGas(const dive *d); QStringList formatFullCylinderList(); +QStringList formatCylinders(const dive *d); #endif diff --git a/core/subsurface-qt/diveobjecthelper.cpp b/core/subsurface-qt/diveobjecthelper.cpp index 8f081fa04..86dda1831 100644 --- a/core/subsurface-qt/diveobjecthelper.cpp +++ b/core/subsurface-qt/diveobjecthelper.cpp @@ -30,18 +30,6 @@ static QString getFormattedWeight(const struct dive *dive, int idx) return fmt; } -static QString getFormattedCylinder(const struct dive *dive, int idx) -{ - const cylinder_t *cyl = get_cylinder(dive, idx); - const char *desc = cyl->type.description; - QString fmt = desc ? QString(desc) : gettextFromC::tr("unknown"); - fmt += ", " + get_volume_string(cyl->type.size, true); - fmt += ", " + get_pressure_string(cyl->type.workingpressure, true); - fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true); - fmt += ", " + get_gas_string(cyl->gasmix); - return fmt; -} - static QString formatGas(const dive *d) { /*WARNING: here should be the gastlist, returned @@ -89,27 +77,6 @@ static QStringList formatWeights(const dive *d) return weights; } -QStringList formatCylinders(const dive *d) -{ - QStringList cylinders; - for (int i = 0; i < d->cylinders.nr; i++) { - QString cyl = getFormattedCylinder(d, i); - cylinders << cyl; - } - return cylinders; -} - -static QVector<CylinderObjectHelper> makeCylinderObjects(const dive *d) -{ - QVector<CylinderObjectHelper> res; - for (int i = 0; i < d->cylinders.nr; i++) { - //Don't add blank cylinders, only those that have been defined. - if (get_cylinder(d, i)->type.description) - res.append(CylinderObjectHelper(get_cylinder(d, i))); // no emplace for QVector. :( - } - return res; -} - QString formatDiveSalinity(const dive *d) { int salinity = get_dive_salinity(d); @@ -181,16 +148,6 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) : #endif /* defined(DEBUG_DOH) */ } -DiveObjectHelperGrantlee::DiveObjectHelperGrantlee() -{ -} - -DiveObjectHelperGrantlee::DiveObjectHelperGrantlee(const struct dive *d) : - DiveObjectHelper(d), - cylinderObjects(makeCylinderObjects(d)) -{ -} - QString DiveObjectHelper::date() const { QDateTime localTime = timestampToDateTime(timestamp); diff --git a/core/subsurface-qt/diveobjecthelper.h b/core/subsurface-qt/diveobjecthelper.h index a1fddd1c8..b76a9930f 100644 --- a/core/subsurface-qt/diveobjecthelper.h +++ b/core/subsurface-qt/diveobjecthelper.h @@ -96,20 +96,6 @@ public: QString waterType; }; -// 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<CylinderObjectHelper> cylinderObjects MEMBER cylinderObjects CONSTANT) -public: - DiveObjectHelperGrantlee(); - DiveObjectHelperGrantlee(const struct dive *dive); - QVector<CylinderObjectHelper> cylinderObjects; -}; - Q_DECLARE_METATYPE(DiveObjectHelper) -Q_DECLARE_METATYPE(DiveObjectHelperGrantlee) #endif |