aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-12-15 15:33:39 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-12-17 13:03:56 -0800
commitae182c386b0b1b58ab25fc1fbc18c3618062e57f (patch)
tree87c5d94a0f795b969233750b83fb22320ff53389 /core
parentd9942269a9b61bc35bd939b23858a7cb4a2515c3 (diff)
downloadsubsurface-ae182c386b0b1b58ab25fc1fbc18c3618062e57f.tar.gz
printing: remove DiveObjectHelper from printing code
At this point (post grantlee), DiveObjectHelper is just pointless glue code. Let's remove it from the printing code and call the formatting functions directly. If necessary, move these functions to core/string-format.cpp. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/string-format.cpp86
-rw-r--r--core/string-format.h8
-rw-r--r--core/subsurface-qt/diveobjecthelper.cpp66
3 files changed, 98 insertions, 62 deletions
diff --git a/core/string-format.cpp b/core/string-format.cpp
index 3f5d7d812..9de145b7a 100644
--- a/core/string-format.cpp
+++ b/core/string-format.cpp
@@ -3,6 +3,7 @@
#include "divesite.h"
#include "qthelper.h"
#include "subsurface-string.h"
+#include <QDateTime>
#include <QTextDocument>
enum returnPressureSelector { START_PRESSURE, END_PRESSURE };
@@ -164,3 +165,88 @@ QStringList formatCylinders(const dive *d)
}
return cylinders;
}
+
+QString formatGas(const dive *d)
+{
+ /*WARNING: here should be the gastlist, returned
+ * from the get_gas_string function or this is correct?
+ */
+ QString gas, gases;
+ for (int i = 0; i < d->cylinders.nr; i++) {
+ if (!is_cylinder_used(d, i))
+ continue;
+ gas = get_cylinder(d, i)->type.description;
+ if (!gas.isEmpty())
+ gas += QChar(' ');
+ gas += gasname(get_cylinder(d, i)->gasmix);
+ // if has a description and if such gas is not already present
+ if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
+ if (!gases.isEmpty())
+ gases += QString(" / ");
+ gases += gas;
+ }
+ }
+ return gases;
+}
+
+QString formatSumWeight(const dive *d)
+{
+ return get_weight_string(weight_t { total_weight(d) }, true);
+}
+
+static QString getFormattedWeight(const struct dive *dive, int idx)
+{
+ const weightsystem_t *weight = &dive->weightsystems.weightsystems[idx];
+ if (!weight->description)
+ return QString();
+ QString fmt = QString(weight->description);
+ fmt += ", " + get_weight_string(weight->weight, true);
+ return fmt;
+}
+
+QString formatWeightList(const dive *d)
+{
+ QString weights;
+ for (int i = 0; i < d->weightsystems.nr; i++) {
+ QString w = getFormattedWeight(d, i);
+ if (w.isEmpty())
+ continue;
+ weights += w + "; ";
+ }
+ return weights;
+}
+
+QStringList formatWeights(const dive *d)
+{
+ QStringList weights;
+ for (int i = 0; i < d->weightsystems.nr; i++) {
+ QString w = getFormattedWeight(d, i);
+ if (w.isEmpty())
+ continue;
+ weights << w;
+ }
+ return weights;
+}
+
+QString formatDiveDuration(const dive *d)
+{
+ return get_dive_duration_string(d->duration.seconds,
+ gettextFromC::tr("h"), gettextFromC::tr("min"));
+}
+
+QString formatDiveGPS(const dive *d)
+{
+ return d->dive_site ? printGPSCoords(&d->dive_site->location) : QString();
+}
+
+QString formatDiveDate(const dive *d)
+{
+ QDateTime localTime = timestampToDateTime(d->when);
+ return localTime.date().toString(prefs.date_format_short);
+}
+
+QString formatDiveTime(const dive *d)
+{
+ QDateTime localTime = timestampToDateTime(d->when);
+ return localTime.time().toString(prefs.time_format);
+}
diff --git a/core/string-format.h b/core/string-format.h
index cbe6336db..12f36bd11 100644
--- a/core/string-format.h
+++ b/core/string-format.h
@@ -14,7 +14,15 @@ QStringList formatGetCylinder(const dive *d);
QStringList formatStartPressure(const dive *d);
QStringList formatEndPressure(const dive *d);
QStringList formatFirstGas(const dive *d);
+QString formatGas(const dive *d);
QStringList formatFullCylinderList();
QStringList formatCylinders(const dive *d);
+QString formatSumWeight(const dive *d);
+QString formatWeightList(const dive *d);
+QStringList formatWeights(const dive *d);
+QString formatDiveDuration(const dive *d);
+QString formatDiveGPS(const dive *d);
+QString formatDiveDate(const dive *d);
+QString formatDiveTime(const dive *d);
#endif
diff --git a/core/subsurface-qt/diveobjecthelper.cpp b/core/subsurface-qt/diveobjecthelper.cpp
index 86dda1831..aa60355b2 100644
--- a/core/subsurface-qt/diveobjecthelper.cpp
+++ b/core/subsurface-qt/diveobjecthelper.cpp
@@ -19,64 +19,6 @@
static int callCounter = 0;
#endif /* defined(DEBUG_DOH) */
-
-static QString getFormattedWeight(const struct dive *dive, int idx)
-{
- const weightsystem_t *weight = &dive->weightsystems.weightsystems[idx];
- if (!weight->description)
- return QString();
- QString fmt = QString(weight->description);
- fmt += ", " + get_weight_string(weight->weight, true);
- return fmt;
-}
-
-static QString formatGas(const dive *d)
-{
- /*WARNING: here should be the gastlist, returned
- * from the get_gas_string function or this is correct?
- */
- QString gas, gases;
- for (int i = 0; i < d->cylinders.nr; i++) {
- if (!is_cylinder_used(d, i))
- continue;
- gas = get_cylinder(d, i)->type.description;
- if (!gas.isEmpty())
- gas += QChar(' ');
- gas += gasname(get_cylinder(d, i)->gasmix);
- // if has a description and if such gas is not already present
- if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
- if (!gases.isEmpty())
- gases += QString(" / ");
- gases += gas;
- }
- }
- return gases;
-}
-
-static QString formatWeightList(const dive *d)
-{
- QString weights;
- for (int i = 0; i < d->weightsystems.nr; i++) {
- QString w = getFormattedWeight(d, i);
- if (w.isEmpty())
- continue;
- weights += w + "; ";
- }
- return weights;
-}
-
-static QStringList formatWeights(const dive *d)
-{
- QStringList weights;
- for (int i = 0; i < d->weightsystems.nr; i++) {
- QString w = getFormattedWeight(d, i);
- if (w.isEmpty())
- continue;
- weights << w;
- }
- return weights;
-}
-
QString formatDiveSalinity(const dive *d)
{
int salinity = get_dive_salinity(d);
@@ -105,11 +47,11 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) :
surge(d->surge),
chill(d->chill),
timestamp(d->when),
- location(get_dive_location(d) ? QString::fromUtf8(get_dive_location(d)) : QString()),
- gps(d->dive_site ? printGPSCoords(&d->dive_site->location) : QString()),
+ location(get_dive_location(d)),
+ gps(formatDiveGPS(d)),
gps_decimal(format_gps_decimal(d)),
dive_site(QVariant::fromValue(d->dive_site)),
- duration(get_dive_duration_string(d->duration.seconds, gettextFromC::tr("h"), gettextFromC::tr("min"))),
+ duration(formatDiveDuration(d)),
noDive(d->duration.seconds == 0 && d->dc.duration.seconds == 0),
depth(get_depth_string(d->dc.maxdepth.mm, true, true)),
divemaster(d->divemaster ? d->divemaster : QString()),
@@ -127,7 +69,7 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) :
cylinders(formatCylinders(d)),
maxcns(d->maxcns),
otu(d->otu),
- sumWeight(get_weight_string(weight_t { total_weight(d) }, true)),
+ sumWeight(formatSumWeight(d)),
getCylinder(formatGetCylinder(d)),
startPressure(formatStartPressure(d)),
endPressure(formatEndPressure(d)),