mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
d9942269a9
commit
ae182c386b
5 changed files with 143 additions and 110 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)),
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue