aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Tim Wootton <tim@tee-jay.org.uk>2016-07-31 22:27:07 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-08-10 15:00:33 -0700
commitbd40ef7f424604013e1fe1b5feea648ab6304b72 (patch)
treeba57a9d6c9a3ea710bd75d1efd71c73e22da14cb /core
parent430f5b77c583e5c29a5299740763ddfc9a098570 (diff)
downloadsubsurface-bd40ef7f424604013e1fe1b5feea648ab6304b72.tar.gz
Adds Cylinder helper class for cylinder info access in grantlee templates
to allow grantlee to access individual fields of the cylinder_t struct rather than a string representation of the whole cylinder info using a grantlee structure like this one: <table class="table_class"> <tr> <td>Cylinder</td> <td>Start press.</td> <td>End press.</td> <td>Gas mix</td> </tr> {% for cylinderObject in dive.cylinderObjects %} <tr> <td>{{ cylinderObject.description }}</td> <td>{{ cylinderObject.startPressure }}</td> <td>{{ cylinderObject.endPressure }}</td> <td>{{ cylinderObject.gasMix }}</td> </tr> {% endfor %} </table> Signed-off-by: Tim Wootton <tim@tee-jay.org.uk> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/CMakeLists.txt1
-rw-r--r--core/subsurface-qt/CylinderObjectHelper.cpp37
-rw-r--r--core/subsurface-qt/CylinderObjectHelper.h31
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp13
-rw-r--r--core/subsurface-qt/DiveObjectHelper.h4
5 files changed, 86 insertions, 0 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index d9b1d3421..5c22e2306 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -86,6 +86,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
subsurface-qt/DiveObjectHelper.cpp
+ subsurface-qt/CylinderObjectHelper.cpp
subsurface-qt/SettingsObjectWrapper.cpp
${SERIAL_FTDI}
${PLATFORM_SRC}
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 *)