diff options
Diffstat (limited to 'core/subsurface-qt/diveobjecthelper.cpp')
-rw-r--r-- | core/subsurface-qt/diveobjecthelper.cpp | 147 |
1 files changed, 5 insertions, 142 deletions
diff --git a/core/subsurface-qt/diveobjecthelper.cpp b/core/subsurface-qt/diveobjecthelper.cpp index 1fa91a301..8f081fa04 100644 --- a/core/subsurface-qt/diveobjecthelper.cpp +++ b/core/subsurface-qt/diveobjecthelper.cpp @@ -9,6 +9,7 @@ #include "core/divesite.h" #include "core/trip.h" #include "core/subsurface-string.h" +#include "core/string-format.h" #include "qt-models/tankinfomodel.h" #if defined(DEBUG_DOH) @@ -19,8 +20,6 @@ static int callCounter = 0; #endif /* defined(DEBUG_DOH) */ -enum returnPressureSelector {START_PRESSURE, END_PRESSURE}; - static QString getFormattedWeight(const struct dive *dive, int idx) { const weightsystem_t *weight = &dive->weightsystems.weightsystems[idx]; @@ -43,57 +42,6 @@ static QString getFormattedCylinder(const struct dive *dive, int idx) return fmt; } -static QString getPressures(const struct dive *dive, int i, enum returnPressureSelector ret) -{ - const cylinder_t *cyl = get_cylinder(dive, i); - QString fmt; - if (ret == START_PRESSURE) { - if (cyl->start.mbar) - fmt = get_pressure_string(cyl->start, true); - else if (cyl->sample_start.mbar) - fmt = get_pressure_string(cyl->sample_start, true); - } - if (ret == END_PRESSURE) { - if (cyl->end.mbar) - fmt = get_pressure_string(cyl->end, true); - else if(cyl->sample_end.mbar) - fmt = get_pressure_string(cyl->sample_end, true); - } - return fmt; -} - -QString format_gps_decimal(const dive *d) -{ - bool savep = prefs.coordinates_traditional; - - prefs.coordinates_traditional = false; - QString val = d->dive_site ? printGPSCoords(&d->dive_site->location) : QString(); - prefs.coordinates_traditional = savep; - return val; -} - -QString formatNotes(const dive *d) -{ - QString tmp = d->notes ? QString::fromUtf8(d->notes) : QString(); - if (is_dc_planner(&d->dc)) { - QTextDocument notes; - #define _NOTES_BR "\n" - tmp.replace("<thead>", "<thead>" _NOTES_BR) - .replace("<br>", "<br>" _NOTES_BR) - .replace("<br/>", "<br/>" _NOTES_BR) - .replace("<br />", "<br />" _NOTES_BR) - .replace("<tr>", "<tr>" _NOTES_BR) - .replace("</tr>", "</tr>" _NOTES_BR); - notes.setHtml(tmp); - tmp = notes.toPlainText(); - tmp.replace(_NOTES_BR, "<br/>"); - #undef _NOTES_BR - } else { - tmp.replace("\n", "<br/>"); - } - return tmp; -} - static QString formatGas(const dive *d) { /*WARNING: here should be the gastlist, returned @@ -117,16 +65,6 @@ static QString formatGas(const dive *d) return gases; } -QString formatSac(const dive *d) -{ - if (!d->sac) - return QString(); - const char *unit; - int decimal; - double value = get_volume_units(d->sac, &decimal, &unit); - return QString::number(value, 'f', decimal).append(unit); -} - static QString formatWeightList(const dive *d) { QString weights; @@ -172,81 +110,6 @@ static QVector<CylinderObjectHelper> makeCylinderObjects(const dive *d) return res; } -QStringList formatGetCylinder(const dive *d) -{ - QStringList getCylinder; - for (int i = 0; i < d->cylinders.nr; i++) { - if (is_cylinder_used(d, i)) - getCylinder << get_cylinder(d, i)->type.description; - } - return getCylinder; -} - -QStringList getStartPressure(const dive *d) -{ - QStringList startPressure; - for (int i = 0; i < d->cylinders.nr; i++) { - if (is_cylinder_used(d, i)) - startPressure << getPressures(d, i, START_PRESSURE); - } - return startPressure; -} - -QStringList getEndPressure(const dive *d) -{ - QStringList endPressure; - for (int i = 0; i < d->cylinders.nr; i++) { - if (is_cylinder_used(d, i)) - endPressure << getPressures(d, i, END_PRESSURE); - } - return endPressure; -} - -QStringList getFirstGas(const dive *d) -{ - QStringList gas; - for (int i = 0; i < d->cylinders.nr; i++) { - if (is_cylinder_used(d, i)) - gas << get_gas_string(get_cylinder(d, i)->gasmix); - } - return gas; -} - -// Add string to sorted QStringList, if it doesn't already exist and -// it isn't the empty string. -static void addStringToSortedList(QStringList &l, const char *s) -{ - if (empty_string(s)) - return; - - // Do a binary search for the string. lower_bound() returns an iterator - // to either the searched-for element or the next higher element if it - // doesn't exist. - QString qs(s); - auto it = std::lower_bound(l.begin(), l.end(), qs); // TODO: use locale-aware sorting - if (it != l.end() && *it == s) - return; - - // Add new string at sorted position - l.insert(it, s); -} - -QStringList getFullCylinderList() -{ - QStringList cylinders; - struct dive *d; - int i = 0; - for_each_dive (i, d) { - for (int j = 0; j < d->cylinders.nr; j++) - addStringToSortedList(cylinders, get_cylinder(d, j)->type.description); - } - - for (int ti = 0; ti < tank_info_table.nr; ti++) - addStringToSortedList(cylinders, tank_info_table.infos[ti].name); - - return cylinders; -} - QString formatDiveSalinity(const dive *d) { int salinity = get_dive_salinity(d); @@ -299,9 +162,9 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) : otu(d->otu), sumWeight(get_weight_string(weight_t { total_weight(d) }, true)), getCylinder(formatGetCylinder(d)), - startPressure(getStartPressure(d)), - endPressure(getEndPressure(d)), - firstGas(getFirstGas(d)), + startPressure(formatStartPressure(d)), + endPressure(formatEndPressure(d)), + firstGas(formatFirstGas(d)), salinity(formatDiveSalinity(d)), waterType(formatDiveWaterType(d)) { @@ -342,5 +205,5 @@ QString DiveObjectHelper::time() const QStringList DiveObjectHelper::cylinderList() const { - return getFullCylinderList(); + return formatFullCylinderList(); } |