From 9342dedb265ed314e1657e82aef407176f7d1e04 Mon Sep 17 00:00:00 2001 From: Joakim Bygdell Date: Wed, 27 Jan 2016 18:34:34 +0100 Subject: Move helper function to DiveObjectsHelper As per Tomaz recomendation the helper functions from 19588ce and e072596 are moved from qmlmanager to DiveObjectsHelper. [Dirk Hohndel: merged with the latest code] Signed-off-by: Joakim Bygdell Signed-off-by: Dirk Hohndel --- subsurface-core/subsurface-qt/DiveObjectHelper.cpp | 28 ++++++++++++++++++++++ subsurface-core/subsurface-qt/DiveObjectHelper.h | 4 ++++ 2 files changed, 32 insertions(+) (limited to 'subsurface-core/subsurface-qt') diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp index e29bd3802..b4460b4de 100644 --- a/subsurface-core/subsurface-qt/DiveObjectHelper.cpp +++ b/subsurface-core/subsurface-qt/DiveObjectHelper.cpp @@ -243,3 +243,31 @@ int DiveObjectHelper::rating() const { return m_dive->rating; } + +QString DiveObjectHelper::sumWeight() const +{ + int sum = 0; + QString sumWeight; + for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++){ + sum += m_dive->weightsystem[i].weight.grams; + } + if (informational_prefs.unit_system == IMPERIAL){ + sumWeight = QString::number(grams_to_lbs(sum), 'f', 1) + " lbs"; + } + else { + sumWeight = QString::number(sum / 1000, 'f', 1) + " kg"; + } + return sumWeight; +} + +QString DiveObjectHelper::getCylinder() const +{ + QString getCylinder; + if (m_dive->cylinder[1].type.description != NULL){ + getCylinder = QObject::tr("Multiple"); + } + else { + getCylinder = m_dive->cylinder[0].type.description; + } + return getCylinder; +} diff --git a/subsurface-core/subsurface-qt/DiveObjectHelper.h b/subsurface-core/subsurface-qt/DiveObjectHelper.h index 84c93465e..f44971fcd 100644 --- a/subsurface-core/subsurface-qt/DiveObjectHelper.h +++ b/subsurface-core/subsurface-qt/DiveObjectHelper.h @@ -32,6 +32,8 @@ class DiveObjectHelper : public QObject { Q_PROPERTY(QString tripMeta READ tripMeta CONSTANT) Q_PROPERTY(QString maxcns READ maxcns CONSTANT) Q_PROPERTY(QString otu READ otu CONSTANT) + Q_PROPERTY(QString sumWeight READ sumWeight CONSTANT) + Q_PROPERTY(QString getCylinder READ getCylinder CONSTANT) public: DiveObjectHelper(struct dive *dive = NULL); ~DiveObjectHelper(); @@ -62,6 +64,8 @@ public: QString tripMeta() const; QString maxcns() const; QString otu() const; + QString sumWeight() const; + QString getCylinder() const; private: struct dive *m_dive; -- cgit v1.2.3-70-g09d2