[PATCH] Adds Cylinder helper class for cylinder info access in grantlee templates

Tim Wootton tim at tee-jay.org.uk
Sat Jul 30 15:25:30 PDT 2016


to allow grantlee to access individual fields of the cylinder_t struct
rather than a string representation of the whole cylinder info

Signed-off-by: Tim Wootton <tim at tee-jay.org.uk>
---
 core/CMakeLists.txt                     |  1 +
 core/subsurface-qt/DiveObjectHelper.cpp | 13 +++++++++++++
 core/subsurface-qt/DiveObjectHelper.h   |  4 ++++
 3 files changed, 18 insertions(+)

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/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



More information about the subsurface mailing list