[PATCH 2/3] DiveHelperObject: add the weightList and cylinderList properties

Lubomir I. Ivanov neolit123 at gmail.com
Mon Feb 29 06:42:07 PST 2016


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

"weights" and "cylinders" are QStringList Q_PROPERTIES, and Grantlee
should be able to render them, but it doesn't.

To be able to print the whole list of weights and cylinders we
introduce two new QString properties "weightList" and "cylinderList".

The variable replacement in the previous patch deals with the
conversation of the user side HTML, e.g.:

USER                  ->   INTERNAL
"{{ dive.weights }}   ->   {{ dive.weightList }}"
"{{ dive.cylinders }} ->   {{ dive.cylinderList }}"

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---

Tomaz said at least a couple of times that QStringList should work,
but it doesn't for me, thus this patch.
---
 subsurface-core/subsurface-qt/DiveObjectHelper.cpp | 24 ++++++++++++++++++++++
 subsurface-core/subsurface-qt/DiveObjectHelper.h   |  4 ++++
 2 files changed, 28 insertions(+)

diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
index bea9556..4a43f6f 100644
--- a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
+++ b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp
@@ -201,6 +201,18 @@ QString DiveObjectHelper::sac() const
 	return QString::number(value, 'f', decimal).append(unit);
 }
 
+QString DiveObjectHelper::weightList() const
+{
+	QString weights;
+	for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
+		QString w = getFormattedWeight(m_dive, i);
+		if (w == EMPTY_DIVE_STRING)
+			continue;
+		weights += w + "; ";
+	}
+	return weights;
+}
+
 QStringList DiveObjectHelper::weights() const
 {
 	QStringList weights;
@@ -226,6 +238,18 @@ QString DiveObjectHelper::suit() const
 	return m_dive->suit ? m_dive->suit : EMPTY_DIVE_STRING;
 }
 
+QString DiveObjectHelper::cylinderList() const
+{
+	QString cylinders;
+	for (int i = 0; i < MAX_CYLINDERS; i++) {
+		QString cyl = getFormattedCylinder(m_dive, i);
+		if (cyl == EMPTY_DIVE_STRING)
+			continue;
+		cylinders += cyl + "; ";
+	}
+	return cylinders;
+}
+
 QStringList DiveObjectHelper::cylinders() const
 {
 	QStringList cylinders;
diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.h b/subsurface-core/subsurface-qt/DiveObjectHelper.h
index 0584f88..602775e 100644
--- a/subsurface-core/subsurface-qt/DiveObjectHelper.h
+++ b/subsurface-core/subsurface-qt/DiveObjectHelper.h
@@ -26,9 +26,11 @@ class DiveObjectHelper : public QObject {
 	Q_PROPERTY(QString tags READ tags CONSTANT)
 	Q_PROPERTY(QString gas READ gas CONSTANT)
 	Q_PROPERTY(QString sac READ sac CONSTANT)
+	Q_PROPERTY(QString weightList READ weightList CONSTANT)
 	Q_PROPERTY(QStringList weights READ weights CONSTANT)
 	Q_PROPERTY(bool singleWeight READ singleWeight CONSTANT)
 	Q_PROPERTY(QString suit READ suit CONSTANT)
+	Q_PROPERTY(QString cylinderList READ cylinderList CONSTANT)
 	Q_PROPERTY(QStringList cylinders READ cylinders CONSTANT)
 	Q_PROPERTY(QString trip READ trip CONSTANT)
 	Q_PROPERTY(QString tripMeta READ tripMeta CONSTANT)
@@ -61,10 +63,12 @@ public:
 	QString tags() const;
 	QString gas() const;
 	QString sac() const;
+	QString weightList() const;
 	QStringList weights() const;
 	QString weight(int idx) const;
 	bool singleWeight() const;
 	QString suit() const;
+	QString cylinderList() const;
 	QStringList cylinders() const;
 	QString cylinder(int idx) const;
 	QString trip() const;
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list