summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/templatelayout.cpp3
-rw-r--r--desktop-widgets/templatelayout.h4
-rw-r--r--qt-mobile/qml/DiveList.qml43
-rw-r--r--qt-models/divelistmodel.cpp81
-rw-r--r--qt-models/divelistmodel.h27
-rw-r--r--subsurface-core/CMakeLists.txt3
-rw-r--r--subsurface-core/qthelper.cpp347
-rw-r--r--subsurface-core/qthelper.h104
-rw-r--r--subsurface-core/subsurface-qt/DiveObjectHelper.cpp263
-rw-r--r--subsurface-core/subsurface-qt/DiveObjectHelper.h92
10 files changed, 403 insertions, 564 deletions
diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp
index a376459a6..59768034e 100644
--- a/desktop-widgets/templatelayout.cpp
+++ b/desktop-widgets/templatelayout.cpp
@@ -69,7 +69,6 @@ QString TemplateLayout::generate()
m_templateLoader->setTemplateDirs(QStringList() << getPrintingTemplatePathUser());
m_engine->addTemplateLoader(m_templateLoader);
- Grantlee::registerMetaType<Dive>();
Grantlee::registerMetaType<template_options>();
Grantlee::registerMetaType<print_options>();
@@ -81,7 +80,7 @@ QString TemplateLayout::generate()
//TODO check for exporting selected dives only
if (!dive->selected && PrintOptions->print_selected)
continue;
- Dive d(dive);
+ DiveObjectHelper *d = new DiveObjectHelper(dive);
diveList.append(QVariant::fromValue(d));
progress++;
emit progressUpdated(progress * 100.0 / totalWork);
diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h
index 1ef9b5834..6f4478a08 100644
--- a/desktop-widgets/templatelayout.h
+++ b/desktop-widgets/templatelayout.h
@@ -7,6 +7,7 @@
#include "statistics.h"
#include "qthelper.h"
#include "helpers.h"
+#include "subsurface-core/subsurface-qt/DiveObjectHelper.h"
int getTotalWork(print_options *printOptions);
void find_all_templates();
@@ -44,7 +45,6 @@ public:
~YearInfo();
};
-Q_DECLARE_METATYPE(Dive)
Q_DECLARE_METATYPE(template_options)
Q_DECLARE_METATYPE(print_options)
Q_DECLARE_METATYPE(YearInfo)
@@ -59,7 +59,7 @@ Q_DECLARE_METATYPE(YearInfo)
#define _RETURN_DIVE_PROPERTY_IDX(prop, idx) \
if (property == _CONC_STR(prop, idx)) return object.prop(idx)
-GRANTLEE_BEGIN_LOOKUP(Dive)
+GRANTLEE_BEGIN_LOOKUP(DiveObjectHelper)
_RETURN_DIVE_PROPERTY(number);
else _RETURN_DIVE_PROPERTY(id);
else _RETURN_DIVE_PROPERTY(date);
diff --git a/qt-mobile/qml/DiveList.qml b/qt-mobile/qml/DiveList.qml
index 6d8f4924c..1a49db29b 100644
--- a/qt-mobile/qml/DiveList.qml
+++ b/qt-mobile/qml/DiveList.qml
@@ -14,7 +14,6 @@ MobileComponents.Page {
Component {
id: diveDelegate
MobileComponents.ListItem {
- id: dive
enabled: true
checked: diveListView.currentIndex == model.index
width: parent.width
@@ -27,22 +26,22 @@ MobileComponents.Page {
onClicked: {
diveListView.currentIndex = model.index
detailsWindow.width = parent.width
- detailsWindow.location = location
- detailsWindow.gps = gps
- detailsWindow.dive_id = id
- detailsWindow.diveNumber = diveNumber
- detailsWindow.duration = duration
- detailsWindow.depth = depth
- detailsWindow.rating = rating
- detailsWindow.buddy = buddy
- detailsWindow.suit = suit
- detailsWindow.airtemp = airtemp
- detailsWindow.watertemp = watertemp
- detailsWindow.divemaster = divemaster
- detailsWindow.notes = notes
- detailsWindow.number = diveNumber
- detailsWindow.date = date
- detailsWindow.weight = weight
+ detailsWindow.location = dive.location
+ detailsWindow.gps = dive.gps
+ detailsWindow.dive_id = dive.id
+ detailsWindow.diveNumber = dive.number
+ detailsWindow.duration = dive.duration
+ detailsWindow.depth = dive.depth
+ detailsWindow.rating = dive.rating
+ detailsWindow.buddy = dive.buddy
+ detailsWindow.suit = dive.suit
+ detailsWindow.airtemp = dive.airTemp
+ detailsWindow.watertemp = dive.waterTemp
+ detailsWindow.divemaster = dive.divemaster
+ detailsWindow.notes = dive.notes
+ detailsWindow.number = dive.number
+ detailsWindow.date = dive.date
+ // detailsWindow.weight = dive.weights
stackView.push(detailsWindow)
}
@@ -52,7 +51,7 @@ MobileComponents.Page {
MobileComponents.Label {
id: locationText
- text: location
+ text: dive.location
font.weight: Font.Light
elide: Text.ElideRight
maximumLineCount: 1 // needed for elide to work at all
@@ -65,7 +64,7 @@ MobileComponents.Page {
}
MobileComponents.Label {
id: dateLabel
- text: date
+ text: dive.date
opacity: 0.6
font.pointSize: subsurfaceTheme.smallPointSize
anchors {
@@ -87,7 +86,7 @@ MobileComponents.Page {
font.pointSize: subsurfaceTheme.smallPointSize
}
MobileComponents.Label {
- text: depth
+ text: dive.depth
width: Math.max(MobileComponents.Units.gridUnit * 3, paintedWidth) // helps vertical alignment throughout listview
font.pointSize: subsurfaceTheme.smallPointSize
}
@@ -97,13 +96,13 @@ MobileComponents.Page {
font.pointSize: subsurfaceTheme.smallPointSize
}
MobileComponents.Label {
- text: duration
+ text: dive.duration
font.pointSize: subsurfaceTheme.smallPointSize
}
}
MobileComponents.Label {
id: numberText
- text: "#" + diveNumber
+ text: "#" + dive.location
color: MobileComponents.Theme.textColor
font.pointSize: subsurfaceTheme.smallPointSize
opacity: 0.6
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index e812f3df7..e6514064f 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -12,15 +12,15 @@ DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent)
void DiveListModel::addDive(dive *d)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
- m_dives.append(Dive(d));
+ m_dives.append(new DiveObjectHelper(d));
endInsertRows();
}
void DiveListModel::updateDive(dive *d)
{
for (int i = 0; i < m_dives.count(); i++) {
- if (m_dives.at(i).id() == d->id) {
- Dive newDive(d);
+ if (m_dives.at(i)->id() == d->id) {
+ DiveObjectHelper *newDive = new DiveObjectHelper(d);
m_dives.replace(i, newDive);
break;
}
@@ -31,6 +31,7 @@ void DiveListModel::clear()
{
if (m_dives.count()) {
beginRemoveRows(QModelIndex(), 0, m_dives.count() - 1);
+ qDeleteAll(m_dives);
m_dives.clear();
endRemoveRows();
}
@@ -46,76 +47,20 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
if(index.row() < 0 || index.row() > m_dives.count())
return QVariant();
- const Dive &dive = m_dives[index.row()];
-
- if (role == DiveNumberRole)
- return dive.number();
- else if (role == DiveTripRole)
- return dive.trip();
- else if (role == DiveDateRole)
- return (qlonglong)dive.timestamp();
- else if (role == DiveDateStringRole)
- return dive.date() + " " + dive.time();
- else if (role == DiveRatingRole)
- return QString::number(dive.rating());
- else if (role == DiveDepthRole)
- return dive.depth();
- else if (role == DiveDurationRole)
- return dive.duration();
- else if (role == DiveAirTemperatureRole)
- return dive.airTemp();
- else if (role == DiveWaterTemperatureRole)
- return dive.waterTemp();
- else if (role == DiveWeightRole)
- return dive.weight(0);
- else if (role == DiveSuitRole)
- return dive.suit();
- else if (role == DiveCylinderRole)
- return dive.cylinder(0);
- else if (role == DiveGasRole)
- return dive.gas();
- else if (role == DiveSacRole)
- return dive.sac();
- else if (role == DiveLocationRole)
- return dive.location();
- else if (role == DiveGPSRole)
- return dive.gps();
- else if (role == DiveNotesRole)
- return dive.notes();
- else if (role == DiveBuddyRole)
- return dive.buddy();
- else if (role == DiveMasterRole)
- return dive.divemaster();
- else if (role == DiveIdRole)
- return QString::number(dive.id());
+ DiveObjectHelper *curr_dive = m_dives[index.row()];
+ switch(role) {
+ case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
+ case DiveDateRole: return (qlonglong)curr_dive->timestamp();
+ }
return QVariant();
-
}
QHash<int, QByteArray> DiveListModel::roleNames() const
{
QHash<int, QByteArray> roles;
- roles[DiveNumberRole] = "diveNumber";
- roles[DiveTripRole] = "trip";
- roles[DiveDateStringRole] = "date";
- roles[DiveRatingRole] = "rating";
- roles[DiveDepthRole] = "depth";
- roles[DiveDurationRole] = "duration";
- roles[DiveAirTemperatureRole] = "airtemp";
- roles[DiveWaterTemperatureRole] = "watertemp";
- roles[DiveWeightRole] = "weight";
- roles[DiveSuitRole] = "suit";
- roles[DiveCylinderRole] = "cylinder";
- roles[DiveGasRole] = "gas";
- roles[DiveSacRole] = "sac";
- roles[DiveLocationRole] = "location";
- roles[DiveGPSRole] = "gps";
- roles[DiveNotesRole] = "notes";
- roles[DiveBuddyRole] = "buddy";
- roles[DiveMasterRole] = "divemaster";
- roles[DiveIdRole] = "id";
-
+ roles[DiveRole] = "dive";
+ roles[DiveDateRole] = "date";
return roles;
}
@@ -140,3 +85,7 @@ DiveListModel *DiveListModel::instance()
{
return m_instance;
}
+
+DiveObjectHelper* DiveListModel::at(int i){
+ return m_dives.at(i);
+} \ No newline at end of file
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index f050faab3..5265cd1b0 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -2,8 +2,10 @@
#define DIVELISTMODEL_H
#include <QAbstractListModel>
+
#include "dive.h"
#include "helpers.h"
+#include "subsurface-qt/DiveObjectHelper.h"
class DiveListModel : public QAbstractListModel
{
@@ -11,26 +13,8 @@ class DiveListModel : public QAbstractListModel
public:
enum DiveListRoles {
- DiveNumberRole = Qt::UserRole + 1,
- DiveTripRole,
- DiveDateRole,
- DiveDateStringRole,
- DiveRatingRole,
- DiveDepthRole,
- DiveDurationRole,
- DiveWaterTemperatureRole,
- DiveAirTemperatureRole,
- DiveWeightRole,
- DiveSuitRole,
- DiveCylinderRole,
- DiveGasRole,
- DiveSacRole,
- DiveLocationRole,
- DiveGPSRole,
- DiveNotesRole,
- DiveBuddyRole,
- DiveMasterRole,
- DiveIdRole
+ DiveRole = Qt::UserRole + 1,
+ DiveDateRole
};
static DiveListModel *instance();
@@ -42,8 +26,9 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QHash<int, QByteArray> roleNames() const;
QString startAddDive();
+ Q_INVOKABLE DiveObjectHelper* at(int i);
private:
- QList<Dive> m_dives;
+ QList<DiveObjectHelper*> m_dives;
static DiveListModel *m_instance;
};
diff --git a/subsurface-core/CMakeLists.txt b/subsurface-core/CMakeLists.txt
index b8c3ed8a0..decc94d5f 100644
--- a/subsurface-core/CMakeLists.txt
+++ b/subsurface-core/CMakeLists.txt
@@ -81,6 +81,9 @@ set(SUBSURFACE_CORE_LIB_SRCS
imagedownloader.cpp
isocialnetworkintegration.cpp
gpslocation.cpp
+
+ #Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
+ subsurface-qt/DiveObjectHelper.cpp
${SERIAL_FTDI}
${PLATFORM_SRC}
${BT_CORE_SRC_FILES}
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;
diff --git a/subsurface-core/qthelper.h b/subsurface-core/qthelper.h
index 0049e9bbd..842e40c36 100644
--- a/subsurface-core/qthelper.h
+++ b/subsurface-core/qthelper.h
@@ -9,110 +9,6 @@
#include <QTranslator>
#include <QDir>
-class Dive {
-private:
- int m_number;
- int m_id;
- int m_rating;
- QString m_date;
- timestamp_t m_timestamp;
- QString m_time;
- QString m_location;
- QString m_gps;
- QString m_duration;
- QString m_depth;
- QString m_divemaster;
- QString m_buddy;
- QString m_airTemp;
- QString m_waterTemp;
- QString m_notes;
- QString m_tags;
- QString m_gas;
- QString m_sac;
- QStringList m_weights;
- QString m_suit;
- QStringList m_cylinders;
- QString m_trip;
- QString m_maxcns;
- QString m_otu;
- struct dive *dive;
- void put_date_time();
- void put_timestamp();
- void put_location();
- void put_gps();
- void put_duration();
- void put_depth();
- void put_divemaster();
- void put_buddy();
- void put_temp();
- void put_notes();
- void put_tags();
- void put_gas();
- void put_sac();
- void put_weight();
- void put_suit();
- void put_cylinder();
- void put_trip();
- void put_maxcns();
- void put_otu();
-
-public:
- Dive(struct dive *dive)
- : dive(dive)
- {
- m_number = dive->number;
- m_id = dive->id;
- m_rating = dive->rating;
- put_date_time();
- put_location();
- put_gps();
- put_duration();
- put_depth();
- put_divemaster();
- put_buddy();
- put_temp();
- put_notes();
- put_tags();
- put_gas();
- put_sac();
- put_timestamp();
- put_weight();
- put_suit();
- put_cylinder();
- put_trip();
- put_maxcns();
- put_otu();
- }
- Dive();
- ~Dive();
- int number() const;
- int id() const;
- int rating() const;
- QString date() const;
- timestamp_t timestamp() const;
- QString time() const;
- QString location() const;
- QString gps() const;
- QString duration() const;
- QString depth() const;
- QString divemaster() const;
- QString buddy() const;
- QString airTemp() const;
- QString waterTemp() const;
- QString notes() const;
- QString tags() const;
- QString gas() const;
- QString sac() const;
- QString weights() const;
- QString weight(int idx) const;
- QString suit() const;
- QString cylinders() const;
- QString cylinder(int idx) const;
- QString trip() const;
- QString maxcns() const;
- QString otu() const;
-};
-
// global pointers for our translation
extern QTranslator *qtTranslator, *ssrfTranslator;
diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
new file mode 100644
index 000000000..03e63786a
--- /dev/null
+++ b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
@@ -0,0 +1,263 @@
+#include "DiveObjectHelper.h"
+
+#include <QDateTime>
+#include <QTextDocument>
+
+#include "../qthelper.h"
+#include "../helpers.h"
+
+static QString EMPTY_DIVE_STRING = QStringLiteral("--");
+
+
+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;
+}
+
+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;
+}
+
+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),
+ 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;
+ return;
+ }
+ 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()
+{
+}
+
+int DiveObjectHelper::number() const
+{
+ return m_number;
+}
+
+int DiveObjectHelper::id() const
+{
+ return m_id;
+}
+
+QString DiveObjectHelper::date() const
+{
+ return m_date;
+}
+
+timestamp_t DiveObjectHelper::timestamp() const
+{
+ return m_timestamp;
+}
+
+QString DiveObjectHelper::time() const
+{
+ return m_time;
+}
+
+QString DiveObjectHelper::location() const
+{
+ return m_location;
+}
+
+QString DiveObjectHelper::gps() const
+{
+ return m_gps;
+}
+QString DiveObjectHelper::duration() const
+{
+ return m_duration;
+}
+
+QString DiveObjectHelper::depth() const
+{
+ return m_depth;
+}
+
+QString DiveObjectHelper::divemaster() const
+{
+ return m_divemaster;
+}
+
+QString DiveObjectHelper::buddy() const
+{
+ return m_buddy;
+}
+
+QString DiveObjectHelper::airTemp() const
+{
+ return m_airTemp;
+}
+
+QString DiveObjectHelper::waterTemp() const
+{
+ return m_waterTemp;
+}
+
+QString DiveObjectHelper::notes() const
+{
+ return m_notes;
+}
+
+QString DiveObjectHelper::tags() const
+{
+ return m_tags;
+}
+
+QString DiveObjectHelper::gas() const
+{
+ return m_gas;
+}
+
+QString DiveObjectHelper::sac() const
+{
+ return m_sac;
+}
+
+QStringList DiveObjectHelper::weights() const
+{
+return m_weights;
+}
+
+QString DiveObjectHelper::weight(int idx) const
+{
+ if (idx < 0 || idx > m_weights.size() - 1)
+ return QString(EMPTY_DIVE_STRING);
+ return m_weights.at(idx);
+}
+
+QString DiveObjectHelper::suit() const
+{
+ return m_suit;
+}
+
+QStringList DiveObjectHelper::cylinders() const
+{
+ return m_cylinders;
+}
+
+QString DiveObjectHelper::cylinder(int idx) const
+{
+ if (idx < 0 || idx > m_cylinders.size() - 1)
+ return QString(EMPTY_DIVE_STRING);
+ return m_cylinders.at(idx);
+}
+
+QString DiveObjectHelper::trip() const
+{
+ return m_trip;
+}
+
+QString DiveObjectHelper::maxcns() const
+{
+ return m_maxcns;
+}
+
+QString DiveObjectHelper::otu() const
+{
+ return m_otu;
+}
+
+int DiveObjectHelper::rating() const
+{
+ return m_rating;
+}
diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.h b/subsurface-core/subsurface-qt/DiveObjectHelper.h
new file mode 100644
index 000000000..5e7858b24
--- /dev/null
+++ b/subsurface-core/subsurface-qt/DiveObjectHelper.h
@@ -0,0 +1,92 @@
+#ifndef DIVE_QOBJECT_H
+#define DIVE_QOBJECT_H
+
+#include "../dive.h"
+#include <QObject>
+#include <QString>
+
+class DiveObjectHelper : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(int number READ number CONSTANT)
+ Q_PROPERTY(int id READ id CONSTANT)
+ Q_PROPERTY(int rating READ rating CONSTANT)
+ Q_PROPERTY(QString date READ date CONSTANT)
+ Q_PROPERTY(QString time READ time CONSTANT)
+ Q_PROPERTY(QString location READ location CONSTANT)
+ Q_PROPERTY(QString gps READ gps CONSTANT)
+ Q_PROPERTY(QString duration READ duration CONSTANT)
+ Q_PROPERTY(QString depth READ depth CONSTANT)
+ Q_PROPERTY(QString divemaster READ divemaster CONSTANT)
+ Q_PROPERTY(QString buddy READ buddy CONSTANT)
+ Q_PROPERTY(QString airTemp READ airTemp CONSTANT)
+ Q_PROPERTY(QString waterTemp READ waterTemp CONSTANT)
+ Q_PROPERTY(QString notes READ notes CONSTANT)
+ Q_PROPERTY(QString tags READ tags CONSTANT)
+ Q_PROPERTY(QString gas READ gas CONSTANT)
+ Q_PROPERTY(QString sac READ sac CONSTANT)
+ Q_PROPERTY(QStringList weights READ weights CONSTANT)
+ Q_PROPERTY(QString suit READ suit CONSTANT)
+ Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT)
+ Q_PROPERTY(QString trip READ trip CONSTANT)
+ Q_PROPERTY(QString maxcns READ maxcns CONSTANT)
+ Q_PROPERTY(QString otu READ otu CONSTANT)
+public:
+ DiveObjectHelper(struct dive *dive = NULL);
+ ~DiveObjectHelper();
+ int number() const;
+ int id() const;
+ int rating() const;
+ QString date() const;
+ timestamp_t timestamp() const;
+ QString time() const;
+ QString location() const;
+ QString gps() const;
+ QString duration() const;
+ QString depth() const;
+ QString divemaster() const;
+ QString buddy() const;
+ QString airTemp() const;
+ QString waterTemp() const;
+ QString notes() const;
+ QString tags() const;
+ QString gas() const;
+ QString sac() const;
+ QStringList weights() const;
+ QString weight(int idx) const;
+ QString suit() const;
+ QStringList cylinders() const;
+ QString cylinder(int idx) const;
+ QString trip() const;
+ QString maxcns() const;
+ QString otu() const;
+private:
+ int m_number;
+ int m_id;
+ int m_rating;
+ QString m_date;
+ timestamp_t m_timestamp;
+ QString m_time;
+ QString m_location;
+ QString m_gps;
+ QString m_duration;
+ QString m_depth;
+ QString m_divemaster;
+ QString m_buddy;
+ QString m_airTemp;
+ QString m_waterTemp;
+ QString m_notes;
+ QString m_tags;
+ QString m_gas;
+ QString m_sac;
+ QStringList m_weights;
+ QString m_suit;
+ QStringList m_cylinders;
+ QString m_trip;
+ QString m_maxcns;
+ QString m_otu;
+ struct dive *m_dive;
+
+};
+Q_DECLARE_METATYPE(DiveObjectHelper*)
+
+#endif \ No newline at end of file