summaryrefslogtreecommitdiffstats
path: root/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'subsurface-core/subsurface-qt/DiveObjectHelper.cpp')
-rw-r--r--subsurface-core/subsurface-qt/DiveObjectHelper.cpp201
1 files changed, 88 insertions, 113 deletions
diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
index 7db882da2..51831efd8 100644
--- a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
+++ b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
@@ -33,93 +33,9 @@ static QString getFormattedCylinder(struct dive *dive, unsigned int idx)
return fmt;
}
-DiveObjectHelper::DiveObjectHelper(struct dive *d) : m_number(d->number),
- m_id(d->id),
- m_rating(d->rating),
- m_timestamp(d->when),
- m_location(get_dive_location(d) ? QString::fromUtf8(get_dive_location(d)) : EMPTY_DIVE_STRING),
- m_duration(get_dive_duration_string(d->duration.seconds, QObject::tr("h:"), QObject::tr("min"))),
- m_depth(get_depth_string(d->dc.maxdepth.mm, true, true)),
- m_divemaster(d->divemaster ? d->divemaster : EMPTY_DIVE_STRING),
- m_buddy(d->buddy ? d->buddy : EMPTY_DIVE_STRING),
- m_airTemp(get_temperature_string(d->airtemp, true)),
- m_waterTemp(get_temperature_string(d->watertemp, true)),
- m_suit(d->suit ? d->suit : EMPTY_DIVE_STRING),
- m_trip(d->divetrip ? d->divetrip->location : EMPTY_DIVE_STRING),
- m_maxcns(d->maxcns),
- m_otu(d->otu),
+DiveObjectHelper::DiveObjectHelper(struct dive *d) :
m_dive(d)
{
- struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
- if (ds)
- m_gps = QString("%1,%2").arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0);
-
- if (m_airTemp.isEmpty()) {
- m_airTemp = EMPTY_DIVE_STRING;
- }
- if (m_waterTemp.isEmpty()) {
- m_waterTemp = EMPTY_DIVE_STRING;
- }
-
- m_notes = QString::fromUtf8(d->notes);
- if (m_notes.isEmpty())
- m_notes = EMPTY_DIVE_STRING;
- if (same_string(d->dc.model, "planned dive")) {
- QTextDocument notes;
- QString notesFormatted = m_notes;
-#define _NOTES_BR "&#92n"
- notesFormatted = notesFormatted.replace("<thead>", "<thead>" _NOTES_BR);
- notesFormatted = notesFormatted.replace("<br>", "<br>" _NOTES_BR);
- notesFormatted = notesFormatted.replace("<tr>", "<tr>" _NOTES_BR);
- notesFormatted = notesFormatted.replace("</tr>", "</tr>" _NOTES_BR);
- notes.setHtml(notesFormatted);
- m_notes = notes.toPlainText();
- m_notes.replace(_NOTES_BR, "<br>");
-#undef _NOTES_BR
- } else {
- m_notes.replace("\n", "<br>");
- }
-
-
- char buffer[256];
- taglist_get_tagstring(d->tag_list, buffer, 256);
- m_tags = QString(buffer);
-
-
- int added = 0;
- QString gas, gases;
- for (int i = 0; i < MAX_CYLINDERS; i++) {
- if (!is_cylinder_used(d, i))
- continue;
- gas = d->cylinder[i].type.description;
- gas += QString(!gas.isEmpty() ? " " : "") + gasname(&d->cylinder[i].gasmix);
- // if has a description and if such gas is not already present
- if (!gas.isEmpty() && gases.indexOf(gas) == -1) {
- if (added > 0)
- gases += QString(" / ");
- gases += gas;
- added++;
- }
- }
- m_gas = gases;
-
- if (d->sac) {
- const char *unit;
- int decimal;
- double value = get_volume_units(d->sac, &decimal, &unit);
- m_sac = QString::number(value, 'f', decimal).append(unit);
- }
-
- for (int i = 0; i < MAX_CYLINDERS; i++)
- m_cylinders << getFormattedCylinder(d, i);
-
- for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
- m_weights << getFormattedWeight(d, i);
-
- QDateTime localTime = QDateTime::fromTime_t(d->when - gettimezoneoffset(d->when));
- localTime.setTimeSpec(Qt::UTC);
- m_date = localTime.date().toString(prefs.date_format);
- m_time = localTime.time().toString(prefs.time_format);
}
DiveObjectHelper::~DiveObjectHelper()
@@ -128,133 +44,192 @@ DiveObjectHelper::~DiveObjectHelper()
int DiveObjectHelper::number() const
{
- return m_number;
+ return m_dive->number;
}
int DiveObjectHelper::id() const
{
- return m_id;
+ return m_dive->id;
}
QString DiveObjectHelper::date() const
{
- return m_date;
+ QDateTime localTime = QDateTime::fromTime_t(m_dive->when - gettimezoneoffset(m_dive->when));
+ localTime.setTimeSpec(Qt::UTC);
+ return localTime.date().toString(prefs.date_format);
}
timestamp_t DiveObjectHelper::timestamp() const
{
- return m_timestamp;
+ return m_dive->when;
}
QString DiveObjectHelper::time() const
{
- return m_time;
+ QDateTime localTime = QDateTime::fromTime_t(m_dive->when - gettimezoneoffset(m_dive->when));
+ localTime.setTimeSpec(Qt::UTC);
+ return localTime.time().toString(prefs.time_format);
}
QString DiveObjectHelper::location() const
{
- return m_location;
+ return get_dive_location(m_dive) ? QString::fromUtf8(get_dive_location(m_dive)) : EMPTY_DIVE_STRING;
}
QString DiveObjectHelper::gps() const
{
- return m_gps;
+ struct dive_site *ds = get_dive_site_by_uuid(m_dive->dive_site_uuid);
+ return ds ? QString(printGPSCoords(ds->latitude.udeg, ds->longitude.udeg)) : QString();
}
QString DiveObjectHelper::duration() const
{
- return m_duration;
+ return get_dive_duration_string(m_dive->duration.seconds, QObject::tr("h:"), QObject::tr("min"));
}
QString DiveObjectHelper::depth() const
{
- return m_depth;
+ return get_depth_string(m_dive->dc.maxdepth.mm, true, true);
}
QString DiveObjectHelper::divemaster() const
{
- return m_divemaster;
+ return m_dive->divemaster ? m_dive->divemaster : EMPTY_DIVE_STRING;
}
QString DiveObjectHelper::buddy() const
{
- return m_buddy;
+ return m_dive->buddy ? m_dive->buddy : EMPTY_DIVE_STRING;
}
QString DiveObjectHelper::airTemp() const
{
- return m_airTemp;
+ QString temp = get_temperature_string(m_dive->airtemp, true);
+ if (temp.isEmpty()) {
+ temp = EMPTY_DIVE_STRING;
+ }
+ return temp;
}
QString DiveObjectHelper::waterTemp() const
{
- return m_waterTemp;
+ QString temp = get_temperature_string(m_dive->watertemp, true);
+ if (temp.isEmpty()) {
+ temp = EMPTY_DIVE_STRING;
+ }
+ return temp;
}
QString DiveObjectHelper::notes() const
{
- return m_notes;
+ QString tmp = m_dive->notes ? QString::fromUtf8(m_dive->notes) : EMPTY_DIVE_STRING;
+ if (same_string(m_dive->dc.model, "planned dive")) {
+ QTextDocument notes;
+ #define _NOTES_BR "&#92n"
+ tmp.replace("<thead>", "<thead>" _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;
}
QString DiveObjectHelper::tags() const
{
- return m_tags;
+ static char buffer[256];
+ taglist_get_tagstring(m_dive->tag_list, buffer, 256);
+ return QString(buffer);
}
QString DiveObjectHelper::gas() const
{
- return m_gas;
+ /*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 < MAX_CYLINDERS; i++) {
+ if (!is_cylinder_used(m_dive, i))
+ continue;
+ gas = m_dive->cylinder[i].type.description;
+ if (!gas.isEmpty())
+ gas += QChar(' ');
+ gas += gasname(&m_dive->cylinder[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 DiveObjectHelper::sac() const
{
- return m_sac;
+ if (!m_dive->sac)
+ return QString();
+ const char *unit;
+ int decimal;
+ double value = get_volume_units(m_dive->sac, &decimal, &unit);
+ QString::number(value, 'f', decimal).append(unit);
}
QStringList DiveObjectHelper::weights() const
{
- return m_weights;
+ QStringList weights;
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
+ weights << getFormattedWeight(m_dive, i);
+ return weights;
}
QString DiveObjectHelper::weight(int idx) const
{
- if (idx < 0 || idx > m_weights.size() - 1)
+ if ( (idx < 0) || idx > MAX_WEIGHTSYSTEMS )
return QString(EMPTY_DIVE_STRING);
- return m_weights.at(idx);
+ return getFormattedWeight(m_dive, idx);
}
QString DiveObjectHelper::suit() const
{
- return m_suit;
+ return m_dive->suit ? m_dive->suit : EMPTY_DIVE_STRING;
}
QStringList DiveObjectHelper::cylinders() const
{
- return m_cylinders;
+ QStringList cylinders;
+ for (int i = 0; i < MAX_CYLINDERS; i++)
+ cylinders << getFormattedCylinder(m_dive, i);
+ return cylinders;
}
QString DiveObjectHelper::cylinder(int idx) const
{
- if (idx < 0 || idx > m_cylinders.size() - 1)
+ if ( (idx < 0) || idx > MAX_CYLINDERS)
return QString(EMPTY_DIVE_STRING);
- return m_cylinders.at(idx);
+ return getFormattedCylinder(m_dive, idx);
}
QString DiveObjectHelper::trip() const
{
- return m_trip;
+ return m_dive->divetrip ? m_dive->divetrip->location : EMPTY_DIVE_STRING;
}
QString DiveObjectHelper::maxcns() const
{
- return m_maxcns;
+ return QString(m_dive->maxcns);
}
QString DiveObjectHelper::otu() const
{
- return m_otu;
+ return QString(m_dive->otu);
}
int DiveObjectHelper::rating() const
{
- return m_rating;
+ return m_dive->rating;
}