diff options
-rw-r--r-- | core/string-format.cpp | 86 | ||||
-rw-r--r-- | core/string-format.h | 8 | ||||
-rw-r--r-- | core/subsurface-qt/diveobjecthelper.cpp | 66 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.cpp | 81 | ||||
-rw-r--r-- | qt-models/divetripmodel.cpp | 12 |
5 files changed, 143 insertions, 110 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)), diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index db095081a..025c1c31d 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -10,7 +10,6 @@ #include "core/selection.h" #include "core/qthelper.h" #include "core/string-format.h" -#include "core/subsurface-qt/diveobjecthelper.h" #include "core/subsurface-qt/cylinderobjecthelper.h" // TODO: remove once grantlee supports Q_GADGET objects QList<QString> grantlee_templates, grantlee_statistics_templates; @@ -517,85 +516,83 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s } else if (list == "dives") { if (!state.currentDive) return QVariant(); - const DiveObjectHelper object(*state.currentDive); + const dive *d = *state.currentDive; if (property == "number") { - return object.number; + return d->number; } else if (property == "id") { - return object.id; + return d->id; } else if (property == "rating") { - return object.rating; + return d->rating; } else if (property == "visibility") { - return object.visibility; + return d->visibility; } else if (property == "wavesize") { - return object.wavesize; + return d->wavesize; } else if (property == "current") { - return object.current; + return d->current; } else if (property == "surge") { - return object.surge; + return d->surge; } else if (property == "chill") { - return object.chill; + return d->chill; } else if (property == "date") { - return object.date(); + return formatDiveDate(d); } else if (property == "time") { - return object.time(); + return formatDiveTime(d); } else if (property == "timestamp") { - return QVariant::fromValue(object.timestamp); + return QVariant::fromValue(d->when); } else if (property == "location") { - return object.location; + return get_dive_location(d); } else if (property == "gps") { - return object.gps; + return formatDiveGPS(d); } else if (property == "gps_decimal") { - return object.gps_decimal; - } else if (property == "dive_site") { - return object.dive_site; + return format_gps_decimal(d); } else if (property == "duration") { - return object.duration; + return formatDiveDuration(d); } else if (property == "noDive") { - return object.noDive; + return d->duration.seconds == 0 && d->dc.duration.seconds == 0; } else if (property == "depth") { - return object.depth; + return get_depth_string(d->dc.maxdepth.mm, true, true); } else if (property == "divemaster") { - return object.divemaster; + return d->divemaster; } else if (property == "buddy") { - return object.buddy; + return d->buddy; } else if (property == "airTemp") { - return object.airTemp; + return get_temperature_string(d->airtemp, true); } else if (property == "waterTemp") { - return object.waterTemp; + return get_temperature_string(d->watertemp, true); } else if (property == "notes") { - return object.notes; + return formatNotes(d); } else if (property == "tags") { - return object.tags; + return get_taglist_string(d->tag_list); } else if (property == "gas") { - return object.gas; + return formatGas(d); } else if (property == "sac") { - return object.sac; + return formatSac(d); } else if (property == "weightList") { - return object.weightList; + return formatWeightList(d); } else if (property == "weights") { - return object.weights; + return formatWeights(d); } else if (property == "singleWeight") { - return object.singleWeight; + return d->weightsystems.nr <= 1; } else if (property == "suit") { - return object.suit; + return d->suit; } else if (property == "cylinderList") { - return object.cylinderList(); + return formatFullCylinderList(); } else if (property == "cylinders") { - return object.cylinders; + return formatCylinders(d); } else if (property == "maxcns") { - return object.maxcns; + return d->maxcns; } else if (property == "otu") { - return object.otu; + return d->otu; } else if (property == "sumWeight") { - return object.sumWeight; + return formatSumWeight(d); } else if (property == "getCylinder") { - return object.getCylinder; + return formatGetCylinder(d); } else if (property == "startPressure") { - return object.startPressure; + return formatStartPressure(d); } else if (property == "endPressure") { - return object.endPressure; + return formatEndPressure(d); } else if (property == "firstGas") { - return object.firstGas; + return formatFirstGas(d); } } return QVariant(); diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 52ad937f5..6d9bd8de4 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -206,21 +206,21 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) case MobileListModel::NumberRole: return d->number; case MobileListModel::LocationRole: return get_dive_location(d); case MobileListModel::DepthRole: return get_depth_string(d->dc.maxdepth.mm, true, true); - case MobileListModel::DurationRole: return get_dive_duration_string(d->duration.seconds, gettextFromC::tr("h"), gettextFromC::tr("min")); + case MobileListModel::DurationRole: return formatDiveDuration(d); case MobileListModel::DepthDurationRole: return QStringLiteral("%1 / %2").arg(get_depth_string(d->dc.maxdepth.mm, true, true), - get_dive_duration_string(d->duration.seconds, gettextFromC::tr("h"), gettextFromC::tr("min"))); + formatDiveDuration(d)); case MobileListModel::RatingRole: return d->rating; case MobileListModel::VizRole: return d->visibility; case MobileListModel::SuitRole: return d->suit; case MobileListModel::AirTempRole: return get_temperature_string(d->airtemp, true); case MobileListModel::WaterTempRole: return get_temperature_string(d->watertemp, true); case MobileListModel::SacRole: return formatSac(d); - case MobileListModel::SumWeightRole: return get_weight_string(weight_t { total_weight(d) }, true); - case MobileListModel::DiveMasterRole: return d->divemaster ? d->divemaster : QString(); - case MobileListModel::BuddyRole: return d->buddy ? d->buddy : QString(); + case MobileListModel::SumWeightRole: return formatSumWeight(d); + case MobileListModel::DiveMasterRole: return d->divemaster; + case MobileListModel::BuddyRole: return d->buddy; case MobileListModel::TagsRole: return get_taglist_string(d->tag_list); case MobileListModel::NotesRole: return formatNotes(d); - case MobileListModel::GpsRole: return d->dive_site ? printGPSCoords(&d->dive_site->location) : QString(); + case MobileListModel::GpsRole: return formatDiveGPS(d); case MobileListModel::GpsDecimalRole: return format_gps_decimal(d); case MobileListModel::NoDiveRole: return d->duration.seconds == 0 && d->dc.duration.seconds == 0; case MobileListModel::DiveSiteRole: return QVariant::fromValue(d->dive_site); |