aboutsummaryrefslogtreecommitdiffstats
path: root/subsurface-core/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2016-01-07 16:01:24 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-08 08:04:44 -0800
commit25aa80846b84c0b3cd3e0b0256a046e1e92fb1db (patch)
treec9934f39f2e039e5877af7ee0d3b0d96c5a1debf /subsurface-core/qthelper.cpp
parentc022f5c4f71f3e7670ed458d714d96fd6e88c55b (diff)
downloadsubsurface-25aa80846b84c0b3cd3e0b0256a046e1e92fb1db.tar.gz
Move Dive class from qthelper.h/cpp to it's own file
and rename it to DiveObjectHelper, since it should be an QObject based class to make it easier on the QML, grantlee and widgets side to display the dive's internal data. each Q_PROPERTY defined in the DiveObjectHelper.h file can be acessed directly via it's name. So, if you are on a model that returns a dive, acess it's name by dive.name Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core/qthelper.cpp')
-rw-r--r--subsurface-core/qthelper.cpp347
1 files changed, 0 insertions, 347 deletions
diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp
index b89fac4c3..4efe57bd4 100644
--- a/subsurface-core/qthelper.cpp
+++ b/subsurface-core/qthelper.cpp
@@ -38,353 +38,6 @@ static QLocale loc;
#define translate(_context, arg) trGettext(arg)
static const QString DEGREE_SIGNS("dD" UTF8_DEGREE);
-#define EMPTY_DIVE_STRING "--"
-
-Dive::Dive() :
- m_number(-1),
- dive(NULL)
-{
-}
-
-Dive::~Dive()
-{
-}
-
-int Dive::number() const
-{
- return m_number;
-}
-
-int Dive::id() const
-{
- return m_id;
-}
-
-QString Dive::date() const
-{
- return m_date;
-}
-
-timestamp_t Dive::timestamp() const
-{
- return m_timestamp;
-}
-
-QString Dive::time() const
-{
- return m_time;
-}
-
-QString Dive::location() const
-{
- return m_location;
-}
-
-QString Dive::gps() const
-{
- return m_gps;
-}
-QString Dive::duration() const
-{
- return m_duration;
-}
-
-QString Dive::depth() const
-{
- return m_depth;
-}
-
-QString Dive::divemaster() const
-{
- return m_divemaster;
-}
-
-QString Dive::buddy() const
-{
- return m_buddy;
-}
-
-QString Dive::airTemp() const
-{
- return m_airTemp;
-}
-
-QString Dive::waterTemp() const
-{
- return m_waterTemp;
-}
-
-QString Dive::notes() const
-{
- return m_notes;
-}
-
-QString Dive::tags() const
-{
- return m_tags;
-}
-
-QString Dive::gas() const
-{
- return m_gas;
-}
-
-QString Dive::sac() const
-{
- return m_sac;
-}
-
-QString Dive::weights() const
-{
- QString str = "";
- for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
- QString entry = m_weights.at(i);
- if (entry == EMPTY_DIVE_STRING)
- continue;
- str += QObject::tr("Weight %1: ").arg(i + 1) + entry + "; ";
- }
- return str;
-}
-
-QString Dive::weight(int idx) const
-{
- if (idx < 0 || idx > m_weights.size() - 1)
- return QString(EMPTY_DIVE_STRING);
- return m_weights.at(idx);
-}
-
-QString Dive::suit() const
-{
- return m_suit;
-}
-
-QString Dive::cylinders() const
-{
- QString str = "";
- for (int i = 0; i < MAX_CYLINDERS; i++) {
- QString entry = m_cylinders.at(i);
- if (entry == EMPTY_DIVE_STRING)
- continue;
- str += QObject::tr("Cylinder %1: ").arg(i + 1) + entry + "; ";
- }
- return str;
-}
-
-QString Dive::cylinder(int idx) const
-{
- if (idx < 0 || idx > m_cylinders.size() - 1)
- return QString(EMPTY_DIVE_STRING);
- return m_cylinders.at(idx);
-}
-
-QString Dive::trip() const
-{
- return m_trip;
-}
-
-QString Dive::maxcns() const
-{
- return m_maxcns;
-}
-
-QString Dive::otu() const
-{
- return m_otu;
-}
-
-int Dive::rating() const
-{
- return m_rating;
-}
-
-void Dive::put_divemaster()
-{
- if (!dive->divemaster)
- m_divemaster = EMPTY_DIVE_STRING;
- else
- m_divemaster = dive->divemaster;
-}
-
-void Dive::put_date_time()
-{
- QDateTime localTime = QDateTime::fromTime_t(dive->when - gettimezoneoffset(dive->when));
- localTime.setTimeSpec(Qt::UTC);
- m_date = localTime.date().toString(prefs.date_format);
- m_time = localTime.time().toString(prefs.time_format);
-}
-
-void Dive::put_timestamp()
-{
- m_timestamp = dive->when;
-}
-
-void Dive::put_location()
-{
- m_location = QString::fromUtf8(get_dive_location(dive));
- if (m_location.isEmpty()) {
- m_location = EMPTY_DIVE_STRING;
- }
-}
-
-void Dive::put_gps()
-{
- struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
- if (ds)
- m_gps = QString("%1,%2").arg(ds->latitude.udeg / 1000000.0).arg(ds->longitude.udeg / 1000000.0);
- else
- m_gps = QString();
-}
-
-void Dive::put_depth()
-{
- m_depth = get_depth_string(dive->dc.maxdepth.mm, true, true);
-}
-
-void Dive::put_duration()
-{
- m_duration = get_dive_duration_string(dive->duration.seconds, QObject::tr("h:"), QObject::tr("min"));
-}
-
-void Dive::put_buddy()
-{
- if (!dive->buddy)
- m_buddy = EMPTY_DIVE_STRING;
- else
- m_buddy = dive->buddy;
-}
-
-void Dive::put_temp()
-{
- m_airTemp = get_temperature_string(dive->airtemp, true);
- m_waterTemp = get_temperature_string(dive->watertemp, true);
- if (m_airTemp.isEmpty()) {
- m_airTemp = EMPTY_DIVE_STRING;
- }
- if (m_waterTemp.isEmpty()) {
- m_waterTemp = EMPTY_DIVE_STRING;
- }
-}
-
-void Dive::put_notes()
-{
- m_notes = QString::fromUtf8(dive->notes);
- if (m_notes.isEmpty()) {
- m_notes = EMPTY_DIVE_STRING;
- return;
- }
- if (same_string(dive->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>");
- }
-}
-
-void Dive::put_tags()
-{
- char buffer[256];
- taglist_get_tagstring(dive->tag_list, buffer, 256);
- m_tags = QString(buffer);
-}
-
-void Dive::put_gas()
-{
- int added = 0;
- QString gas, gases;
- for (int i = 0; i < MAX_CYLINDERS; i++) {
- if (!is_cylinder_used(dive, i))
- continue;
- gas = dive->cylinder[i].type.description;
- gas += QString(!gas.isEmpty() ? " " : "") + gasname(&dive->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;
-}
-
-void Dive::put_sac()
-{
- if (dive->sac) {
- const char *unit;
- int decimal;
- double value = get_volume_units(dive->sac, &decimal, &unit);
- m_sac = QString::number(value, 'f', decimal).append(unit);
- }
-}
-
-static QString getFormattedWeight(struct dive *dive, unsigned int idx)
-{
- weightsystem_t *weight = &dive->weightsystem[idx];
- if (!weight->description)
- return QString(EMPTY_DIVE_STRING);
- QString fmt = QString(weight->description);
- fmt += ", " + get_weight_string(weight->weight, true);
- return fmt;
-}
-
-void Dive::put_weight()
-{
- for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
- m_weights << getFormattedWeight(dive, i);
-}
-
-void Dive::put_suit()
-{
- m_suit = QString(dive->suit);
-}
-
-static QString getFormattedCylinder(struct dive *dive, unsigned int idx)
-{
- cylinder_t *cyl = &dive->cylinder[idx];
- const char *desc = cyl->type.description;
- if (!desc && idx > 0)
- return QString(EMPTY_DIVE_STRING);
- QString fmt = desc ? QString(desc) : QObject::tr("unknown");
- fmt += ", " + get_volume_string(cyl->type.size, true, 0);
- fmt += ", " + get_pressure_string(cyl->type.workingpressure, true);
- fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true);
- fmt += ", " + get_gas_string(cyl->gasmix);
- return fmt;
-}
-
-void Dive::put_cylinder()
-{
- for (int i = 0; i < MAX_CYLINDERS; i++)
- m_cylinders << getFormattedCylinder(dive, i);
-}
-
-void Dive::put_trip()
-{
- dive_trip *trip = dive->divetrip;
- if (trip) {
- m_trip = QString(trip->location);
- }
-}
-
-void Dive::put_maxcns()
-{
- m_maxcns = QString::number(dive->maxcns);
-}
-
-void Dive::put_otu()
-{
- m_otu = QString::number(dive->otu);
-}
-
QString weight_string(int weight_in_grams)
{
QString str;