diff options
Diffstat (limited to 'core/subsurface-qt')
-rw-r--r-- | core/subsurface-qt/CylinderObjectHelper.cpp | 37 | ||||
-rw-r--r-- | core/subsurface-qt/CylinderObjectHelper.h | 31 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 13 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.h | 4 |
4 files changed, 85 insertions, 0 deletions
diff --git a/core/subsurface-qt/CylinderObjectHelper.cpp b/core/subsurface-qt/CylinderObjectHelper.cpp new file mode 100644 index 000000000..341d30b12 --- /dev/null +++ b/core/subsurface-qt/CylinderObjectHelper.cpp @@ -0,0 +1,37 @@ +#include "CylinderObjectHelper.h" +#include "../helpers.h" + +static QString EMPTY_CYLINDER_STRING = QStringLiteral(""); +CylinderObjectHelper::CylinderObjectHelper(cylinder_t *cylinder) : + m_cyl(cylinder) { +} + +CylinderObjectHelper::~CylinderObjectHelper() { +} + +QString CylinderObjectHelper::description() const { + if (!m_cyl->type.description) + return QString(EMPTY_CYLINDER_STRING); + else + return QString(m_cyl->type.description); +} + +QString CylinderObjectHelper::size() const { + return get_volume_string(m_cyl->type.size, true); +} + +QString CylinderObjectHelper::workingPressure() const { + return get_pressure_string(m_cyl->type.workingpressure, true); +} + +QString CylinderObjectHelper::startPressure() const { + return get_pressure_string(m_cyl->start, true); +} + +QString CylinderObjectHelper::endPressure() const { + return get_pressure_string(m_cyl->end, true); +} + +QString CylinderObjectHelper::gasMix() const { + return get_gas_string(m_cyl->gasmix); +} diff --git a/core/subsurface-qt/CylinderObjectHelper.h b/core/subsurface-qt/CylinderObjectHelper.h new file mode 100644 index 000000000..c523eee20 --- /dev/null +++ b/core/subsurface-qt/CylinderObjectHelper.h @@ -0,0 +1,31 @@ +#ifndef CYLINDER_QOBJECT_H +#define CYLINDER_QOBJECT_H + +#include "../dive.h" +#include <QObject> +#include <QString> + +class CylinderObjectHelper : public QObject { + Q_OBJECT + Q_PROPERTY(QString description READ description CONSTANT) + Q_PROPERTY(QString size READ size CONSTANT) + Q_PROPERTY(QString workingPressure READ workingPressure CONSTANT) + Q_PROPERTY(QString startPressure READ startPressure CONSTANT) + Q_PROPERTY(QString endPressure READ endPressure CONSTANT) + Q_PROPERTY(QString gasMix READ gasMix CONSTANT) +public: + CylinderObjectHelper(cylinder_t *cylinder = NULL); + ~CylinderObjectHelper(); + QString description() const; + QString size() const; + QString workingPressure() const; + QString startPressure() const; + QString endPressure() const; + QString gasMix() const; + +private: + cylinder_t *m_cyl; +}; + + Q_DECLARE_METATYPE(CylinderObjectHelper *) +#endif
\ No newline at end of file diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index 69bd7999f..768d4a860 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -55,10 +55,18 @@ static QString getPressures(struct dive *dive, enum returnPressureSelector ret) DiveObjectHelper::DiveObjectHelper(struct dive *d) : m_dive(d) { + m_cyls.clear(); + for (int i = 0; i < MAX_CYLINDERS; i++) { + //Don't add blank cylinders, only those that have been defined. + if (m_dive->cylinder[i].type.description) + m_cyls.append(new CylinderObjectHelper(&m_dive->cylinder[i])); + } } DiveObjectHelper::~DiveObjectHelper() { +while (!m_cyls.isEmpty()) + delete m_cyls.takeFirst(); } int DiveObjectHelper::number() const @@ -275,6 +283,11 @@ QString DiveObjectHelper::cylinder(int idx) const return getFormattedCylinder(m_dive, idx); } +QList<CylinderObjectHelper*> DiveObjectHelper::cylinderObjects() const +{ + return m_cyls; +} + QString DiveObjectHelper::trip() const { return m_dive->divetrip ? m_dive->divetrip->location : EMPTY_DIVE_STRING; diff --git a/core/subsurface-qt/DiveObjectHelper.h b/core/subsurface-qt/DiveObjectHelper.h index ab42a59b3..c685690cf 100644 --- a/core/subsurface-qt/DiveObjectHelper.h +++ b/core/subsurface-qt/DiveObjectHelper.h @@ -2,6 +2,7 @@ #define DIVE_QOBJECT_H #include "../dive.h" +#include "CylinderObjectHelper.h" #include <QObject> #include <QString> #include <QStringList> @@ -34,6 +35,7 @@ class DiveObjectHelper : public QObject { Q_PROPERTY(QString suit READ suit CONSTANT) Q_PROPERTY(QString cylinderList READ cylinderList CONSTANT) Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT) + Q_PROPERTY(QList<CylinderObjectHelper*> cylinderObjects READ cylinderObjects CONSTANT) Q_PROPERTY(QString trip READ trip CONSTANT) Q_PROPERTY(QString tripMeta READ tripMeta CONSTANT) Q_PROPERTY(int maxcns READ maxcns CONSTANT) @@ -77,6 +79,7 @@ public: QString cylinderList() const; QStringList cylinders() const; QString cylinder(int idx) const; + QList<CylinderObjectHelper*> cylinderObjects() const; QString trip() const; QString tripMeta() const; int maxcns() const; @@ -92,6 +95,7 @@ public: private: struct dive *m_dive; + QList<CylinderObjectHelper*> m_cyls; }; Q_DECLARE_METATYPE(DiveObjectHelper *) |