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 <[email protected]>
---
 core/CMakeLists.txt                         |  1 +
 core/subsurface-qt/CylinderObjectHelper.cpp | 37 +++++++++++++++++++++++++++++
 core/subsurface-qt/CylinderObjectHelper.h   | 31 ++++++++++++++++++++++++
 core/subsurface-qt/DiveObjectHelper.cpp     | 13 ++++++++++
 core/subsurface-qt/DiveObjectHelper.h       |  4 ++++
 5 files changed, 86 insertions(+)
 create mode 100644 core/subsurface-qt/CylinderObjectHelper.cpp
 create mode 100644 core/subsurface-qt/CylinderObjectHelper.h

diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index d9b1d34..5c22e23 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 0000000..341d30b
--- /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 0000000..c523eee
--- /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 c246a12..7da5202 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
@@ -271,6 +279,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 ab42a59..c685690 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 *)
 
-- 
2.1.4

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to