aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-models/divelistmodel.cpp261
-rw-r--r--qt-models/divelistmodel.h94
-rw-r--r--qthelper.cpp243
-rw-r--r--qthelper.h90
-rw-r--r--templatelayout.cpp189
-rw-r--r--templatelayout.h71
6 files changed, 345 insertions, 603 deletions
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 7b7102f7b..1cec4bd20 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -1,249 +1,6 @@
#include "divelistmodel.h"
#include "helpers.h"
-MobileDive::MobileDive(dive *d)
-{
- m_thisDive = d;
- setDiveNumber(QString::number(d->number));
- setDiveId(QString::number(d->id));
-
- dive_trip *trip = d->divetrip;
-
- if(trip) {
- //trip is valid
- setTrip(trip->location);
- }
- setDate(d->when);
- setDateString(get_dive_date_string(d->when));
- setDepth(get_depth_string(d->maxdepth));
- setDuration(get_dive_duration_string(d->duration.seconds, "h:","min"));
-
- setupDiveTempDetails();
-
- weight_t tw = { total_weight(d) };
- setWeight(weight_string(tw.grams));
-
- setSuit(QString(d->suit));
- setCylinder(QString(d->cylinder[0].type.description));
- setSac(QString::number(d->sac));
- setLocation(get_dive_location(d));
- setNotes(d->notes);
- setBuddy(d->buddy);
- setDivemaster(d->divemaster);
-}
-
-QString MobileDive::dateString() const
-{
- return m_dateString;
-}
-
-void MobileDive::setDateString(const QString &date)
-{
- m_dateString = date;
-}
-
-timestamp_t MobileDive::date() const
-{
- return m_date;
-}
-
-void MobileDive::setDate(timestamp_t when)
-{
- m_date = when;
-}
-
-QString MobileDive::location() const
-{
- return m_location;
-}
-
-void MobileDive::setLocation(const QString &location)
-{
- m_location = location;
-}
-
-QString MobileDive::sac() const
-{
- return m_sac;
-}
-
-void MobileDive::setSac(const QString &sac)
-{
- m_sac = sac;
-}
-
-QString MobileDive::gas() const
-{
- return m_gas;
-}
-
-void MobileDive::setGas(const QString &gas)
-{
- m_gas = gas;
-}
-
-QString MobileDive::cylinder() const
-{
- return m_cylinder;
-}
-
-void MobileDive::setCylinder(const QString &cylinder)
-{
- m_cylinder = cylinder;
-}
-
-QString MobileDive::suit() const
-{
- return m_suit;
-}
-
-void MobileDive::setSuit(const QString &suit)
-{
- m_suit = suit;
-}
-
-QString MobileDive::weight() const
-{
- return m_weight;
-}
-
-void MobileDive::setWeight(const QString &weight)
-{
- m_weight = weight;
-}
-
-QString MobileDive::airtemp() const
-{
- return m_airtemp;
-}
-
-void MobileDive::setAirTemp(const QString &airtemp)
-{
- m_airtemp = airtemp;
-}
-
-QString MobileDive::duration() const
-{
- return m_duration;
-}
-
-void MobileDive::setDuration(const QString &duration)
-{
- m_duration = duration;
-}
-
-QString MobileDive::depth() const
-{
- return m_depth;
-}
-
-void MobileDive::setDepth(const QString &depth)
-{
- m_depth = depth;
-}
-
-QString MobileDive::rating() const
-{
- return m_rating;
-}
-
-void MobileDive::setRating(const QString &rating)
-{
- m_rating = rating;
-}
-
-dive *MobileDive::thisDive() const
-{
- return m_thisDive;
-}
-
-void MobileDive::setThisDive(dive *thisDive)
-{
- m_thisDive = thisDive;
-}
-
-QString MobileDive::diveNumber() const
-{
- return m_diveNumber;
-}
-
-void MobileDive::setDiveNumber(const QString &diveNumber)
-{
- m_diveNumber = diveNumber;
-}
-
-QString MobileDive::notes() const
-{
- return m_notes;
-}
-
-void MobileDive::setNotes(const QString &notes)
-{
- m_notes = notes;
-}
-
-QString MobileDive::trip() const
-{
- return m_trip;
-}
-
-void MobileDive::setTrip(const QString &trip)
-{
- m_trip = trip;
-}
-
-QString MobileDive::buddy() const
-{
- return m_buddy;
-}
-
-void MobileDive::setBuddy(const QString &buddy)
-{
- m_buddy = buddy;
-}
-
-QString MobileDive::divemaster() const
-{
- return m_divemaster;
-}
-
-void MobileDive::setDivemaster(const QString &divemaster)
-{
- m_divemaster = divemaster;
-}
-
-QString MobileDive::watertemp() const
-{
- return m_watertemp;
-}
-
-void MobileDive::setWatertemp(const QString &watertemp)
-{
- m_watertemp = watertemp;
-}
-
-void MobileDive::setupDiveTempDetails()
-{
- setWatertemp(get_temperature_string(m_thisDive->watertemp, true));
- setAirTemp(get_temperature_string(m_thisDive->airtemp, true));
-}
-QString MobileDive::diveId() const
-{
- return m_diveId;
-}
-
-void MobileDive::setDiveId(const QString &diveId)
-{
- m_diveId = diveId;
-}
-
-
-
-
-
-
-
-
DiveListModel *DiveListModel::m_instance = NULL;
DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent)
@@ -254,7 +11,7 @@ DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent)
void DiveListModel::addDive(dive *d)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
- m_dives.append(MobileDive(d));
+ m_dives.append(Dive(d));
endInsertRows();
}
@@ -268,26 +25,26 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
if(index.row() < 0 || index.row() > m_dives.count())
return QVariant();
- const MobileDive &dive = m_dives[index.row()];
+ const Dive &dive = m_dives[index.row()];
if (role == DiveNumberRole)
- return dive.diveNumber();
+ return dive.number();
else if (role == DiveTripRole)
return dive.trip();
else if (role == DiveDateRole)
- return (qlonglong)dive.date();
+ return (qlonglong)dive.timestamp();
else if (role == DiveDateStringRole)
- return dive.dateString();
+ return dive.date() + " " + dive.time();
else if (role == DiveRatingRole)
- return dive.rating();
+ 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();
+ return dive.airTemp();
else if (role == DiveWaterTemperatureRole)
- return dive.watertemp();
+ return dive.waterTemp();
else if (role == DiveWeightRole)
return dive.weight();
else if (role == DiveSuitRole)
@@ -307,7 +64,7 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
else if (role == DiveMasterRole)
return dive.divemaster();
else if (role == DiveIdRole)
- return dive.diveId();
+ return QString::number(dive.id());
return QVariant();
diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h
index 68022812c..958a783e9 100644
--- a/qt-models/divelistmodel.h
+++ b/qt-models/divelistmodel.h
@@ -3,97 +3,7 @@
#include <QAbstractListModel>
#include "dive.h"
-
-class MobileDive {
-public:
- MobileDive(dive* d);
-
- QString dateString() const;
- void setDateString(const QString &date);
-
- timestamp_t date() const;
- void setDate(const timestamp_t when);
-
- QString location() const;
- void setLocation(const QString &location);
-
- QString sac() const;
- void setSac(const QString &sac);
-
- QString gas() const;
- void setGas(const QString &gas);
-
- QString cylinder() const;
- void setCylinder(const QString &cylinder);
-
- QString suit() const;
- void setSuit(const QString &suit);
-
- QString weight() const;
- void setWeight(const QString &weight);
-
- QString airtemp() const;
- void setAirTemp(const QString &airtemp);
-
- QString duration() const;
- void setDuration(const QString &duration);
-
- QString depth() const;
- void setDepth(const QString &depth);
-
- QString rating() const;
- void setRating(const QString &rating);
-
- dive *thisDive() const;
- void setThisDive(dive *thisDive);
-
- QString diveNumber() const;
- void setDiveNumber(const QString &diveNumber);
-
- QString notes() const;
- void setNotes(const QString &notes);
-
- QString trip() const;
- void setTrip(const QString &trip);
-
- QString buddy() const;
- void setBuddy(const QString &buddy);
-
- QString divemaster() const;
- void setDivemaster(const QString &divemaster);
-
- QString watertemp() const;
- void setWatertemp(const QString &watertemp);
-
- QString diveId() const;
- void setDiveId(const QString &diveId);
-
-private:
- void setupDiveTempDetails();
-
- QString m_diveNumber;
- QString m_trip;
- timestamp_t m_date;
- QString m_dateString;
- QString m_rating;
- QString m_depth;
- QString m_duration;
- QString m_airtemp;
- QString m_watertemp;
- QString m_weight;
- QString m_suit;
- QString m_cylinder;
- QString m_gas;
- QString m_sac;
- QString m_location;
- QString m_notes;
- QString m_buddy;
- QString m_divemaster;
- QString m_diveId;
-
-
- dive *m_thisDive;
-};
+#include "helpers.h"
class DiveListModel : public QAbstractListModel
{
@@ -130,7 +40,7 @@ public:
QHash<int, QByteArray> roleNames() const;
void startAddDive();
private:
- QList<MobileDive> m_dives;
+ QList<Dive> m_dives;
static DiveListModel *m_instance;
};
diff --git a/qthelper.cpp b/qthelper.cpp
index ebae97df7..51a817296 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -40,6 +40,249 @@ static QLocale loc;
#define translate(_context, arg) trGettext(arg)
static const QString DEGREE_SIGNS("dD" UTF8_DEGREE);
+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::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::weight() const
+{
+ return m_weight;
+}
+
+QString Dive::suit() const
+{
+ return m_suit;
+}
+
+QString Dive::cylinder() const
+{
+ return m_cylinder;
+}
+
+QString Dive::trip() const
+{
+ return m_trip;
+}
+
+int Dive::rating() const
+{
+ return m_rating;
+}
+
+void Dive::put_divemaster()
+{
+ if (!dive->divemaster)
+ m_divemaster = "--";
+ else
+ m_divemaster = dive->divemaster;
+}
+
+void Dive::put_date_time()
+{
+ QDateTime localTime = QDateTime::fromTime_t(dive->when - gettimezoneoffset(displayed_dive.when));
+ localTime.setTimeSpec(Qt::UTC);
+ m_date = localTime.date().toString(QString::fromUtf8("MMM dd, yyyy"));
+ m_time = localTime.time().toString(QString::fromUtf8("hh:mm a"));
+}
+
+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 = "--";
+ }
+}
+
+void Dive::put_depth()
+{
+ m_depth = get_depth_string(dive->dc.maxdepth.mm, true, true);
+}
+
+void Dive::put_duration()
+{
+ m_duration = QString::number(((dive->duration.seconds) / 60)) + QString::fromUtf8(" min");
+}
+
+void Dive::put_buddy()
+{
+ if (!dive->buddy)
+ m_buddy = "--";
+ 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 = "--";
+ }
+ if (m_waterTemp.isEmpty()) {
+ m_waterTemp = "--";
+ }
+}
+
+void Dive::put_notes()
+{
+ m_notes = QString::fromUtf8(dive->notes);
+ if (m_notes.isEmpty()) {
+ m_notes = "--";
+ }
+}
+
+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);
+ }
+}
+
+void Dive::put_weight()
+{
+ weight_t tw = { total_weight(dive) };
+ m_weight = weight_string(tw.grams);
+}
+
+void Dive::put_suit()
+{
+ m_suit = QString(dive->suit);
+}
+
+void Dive::put_cylinder()
+{
+ m_cylinder = QString(dive->cylinder[0].type.description);
+}
+
+void Dive::put_trip()
+{
+ dive_trip *trip = dive->divetrip;
+ if (trip) {
+ m_trip = QString(trip->location);
+ }
+}
+
QString weight_string(int weight_in_grams)
{
QString str;
diff --git a/qthelper.h b/qthelper.h
index 073010d9f..f6c1cdb2b 100644
--- a/qthelper.h
+++ b/qthelper.h
@@ -9,6 +9,96 @@
#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_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;
+ QString m_weight;
+ QString m_suit;
+ QString m_cylinder;
+ QString m_trip;
+ struct dive *dive;
+ void put_date_time();
+ void put_timestamp();
+ void put_location();
+ 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();
+
+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_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();
+ }
+ 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 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 weight() const;
+ QString suit() const;
+ QString cylinder() const;
+ QString trip() const;
+};
+
// global pointers for our translation
extern QTranslator *qtTranslator, *ssrfTranslator;
diff --git a/templatelayout.cpp b/templatelayout.cpp
index 57cc4c5e8..161200d62 100644
--- a/templatelayout.cpp
+++ b/templatelayout.cpp
@@ -171,195 +171,6 @@ void TemplateLayout::writeTemplate(QString template_name, QString grantlee_templ
}
}
-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;
-}
-
-QString Dive::time() const
-{
- return m_time;
-}
-
-QString Dive::location() const
-{
- return m_location;
-}
-
-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;
-}
-
-int Dive::rating() const
-{
- return m_rating;
-}
-
-void Dive::put_divemaster()
-{
- if (!dive->divemaster)
- m_divemaster = "--";
- else
- m_divemaster = dive->divemaster;
-}
-
-void Dive::put_date_time()
-{
- QDateTime localTime = QDateTime::fromTime_t(dive->when - gettimezoneoffset(displayed_dive.when));
- localTime.setTimeSpec(Qt::UTC);
- m_date = localTime.date().toString(QString::fromUtf8("MMM dd, yyyy"));
- m_time = localTime.time().toString(QString::fromUtf8("hh:mm a"));
-}
-
-void Dive::put_location()
-{
- m_location = QString::fromUtf8(get_dive_location(dive));
- if (m_location.isEmpty()) {
- m_location = "--";
- }
-}
-
-void Dive::put_depth()
-{
- m_depth = get_depth_string(dive->dc.maxdepth.mm, true, true);
-}
-
-void Dive::put_duration()
-{
- m_duration = QString::number(((dive->duration.seconds) / 60)) + QString::fromUtf8(" min");
-}
-
-void Dive::put_buddy()
-{
- if (!dive->buddy)
- m_buddy = "--";
- 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 = "--";
- }
- if (m_waterTemp.isEmpty()) {
- m_waterTemp = "--";
- }
-}
-
-void Dive::put_notes()
-{
- m_notes = QString::fromUtf8(dive->notes);
- if (m_notes.isEmpty()) {
- m_notes = "--";
- }
-}
-
-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);
- }
-}
-
YearInfo::YearInfo()
{
diff --git a/templatelayout.h b/templatelayout.h
index d9fa29295..a2868e7ff 100644
--- a/templatelayout.h
+++ b/templatelayout.h
@@ -5,6 +5,7 @@
#include "mainwindow.h"
#include "printoptions.h"
#include "statistics.h"
+#include "qthelper.h"
#include "helpers.h"
int getTotalWork(print_options *printOptions);
@@ -31,76 +32,6 @@ signals:
void progressUpdated(int value);
};
-class Dive {
-private:
- int m_number;
- int m_id;
- int m_rating;
- QString m_date;
- QString m_time;
- QString m_location;
- 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;
- struct dive *dive;
- void put_date_time();
- void put_location();
- 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();
-
-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_duration();
- put_depth();
- put_divemaster();
- put_buddy();
- put_temp();
- put_notes();
- put_tags();
- put_gas();
- put_sac();
- }
- Dive();
- ~Dive();
- int number() const;
- int id() const;
- int rating() const;
- QString date() const;
- QString time() const;
- QString location() 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;
-};
-
class YearInfo {
public:
stats_t *year;