aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-11-17 00:29:18 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-11-16 15:03:50 -0800
commitdd944ab33f8f2984c9cc7f1d94a5aa632e3ad1f4 (patch)
treef7823600c06c7054b62c0f8b4f6d0badb8f83b99
parenta34dfe82847dce2db083f4b37554279df0b26307 (diff)
downloadsubsurface-dd944ab33f8f2984c9cc7f1d94a5aa632e3ad1f4.tar.gz
qthelper: add means to retreive weight and cylinder info in Dive
The Dive helper class only picks the first cylinder and the total weight. This patch adds the option to dump the cylinders and weights as formatted lists (via cylinders() and weights()) or to retrieve a specific cylinder or weight via (cylinder(index) and weight(index)). Each cylinder and weight string contains detailed information: cylinder: - desc. - pressure (+start/end) - gasmix - etc... weight: - desc. - weight (in units e.g. kg) If no description is found for a cylinder or weight the contents for this particular unit is filled with EMPTY_DIVE_STRING ("--"). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--subsurface-core/qthelper.cpp66
-rw-r--r--subsurface-core/qthelper.h10
2 files changed, 65 insertions, 11 deletions
diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp
index 3da904ed3..049ebf6fc 100644
--- a/subsurface-core/qthelper.cpp
+++ b/subsurface-core/qthelper.cpp
@@ -130,9 +130,23 @@ QString Dive::sac() const
return m_sac;
}
-QString Dive::weight() const
+QString Dive::weights() const
{
- return m_weight;
+ QString str = "";
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
+ QString entry = m_weights.at(i);
+ if (entry == EMPTY_DIVE_STRING)
+ continue;
+ str += QObject::tr("Weight %1: ").arg(i + 1) + entry + "; ";
+ }
+ return str;
+}
+
+QString Dive::weight(int idx) const
+{
+ if (idx < 0 || idx > m_weights.size() - 1)
+ return QString(EMPTY_DIVE_STRING);
+ return m_weights.at(idx);
}
QString Dive::suit() const
@@ -140,9 +154,23 @@ QString Dive::suit() const
return m_suit;
}
-QString Dive::cylinder() const
+QString Dive::cylinders() const
{
- return m_cylinder;
+ QString str = "";
+ for (int i = 0; i < MAX_CYLINDERS; i++) {
+ QString entry = m_cylinders.at(i);
+ if (entry == EMPTY_DIVE_STRING)
+ continue;
+ str += QObject::tr("Cylinder %1: ").arg(i + 1) + entry + "; ";
+ }
+ return str;
+}
+
+QString Dive::cylinder(int idx) const
+{
+ if (idx < 0 || idx > m_cylinders.size() - 1)
+ return QString(EMPTY_DIVE_STRING);
+ return m_cylinders.at(idx);
}
QString Dive::trip() const
@@ -275,10 +303,20 @@ void Dive::put_sac()
}
}
+static QString getFormattedWeight(struct dive *dive, unsigned int idx)
+{
+ weightsystem_t *weight = &dive->weightsystem[idx];
+ if (!weight->description)
+ return QString(EMPTY_DIVE_STRING);
+ QString fmt = QString(weight->description);
+ fmt += ", " + get_weight_string(weight->weight, true);
+ return fmt;
+}
+
void Dive::put_weight()
{
- weight_t tw = { total_weight(dive) };
- m_weight = weight_string(tw.grams);
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
+ m_weights << getFormattedWeight(dive, i);
}
void Dive::put_suit()
@@ -286,9 +324,23 @@ void Dive::put_suit()
m_suit = QString(dive->suit);
}
+static QString getFormattedCylinder(struct dive *dive, unsigned int idx)
+{
+ cylinder_t *cyl = &dive->cylinder[idx];
+ if (!cyl->type.description)
+ return QString(EMPTY_DIVE_STRING);
+ QString fmt = QString(cyl->type.description);
+ fmt += ", " + get_volume_string(cyl->type.size, true, 0);
+ fmt += ", " + get_pressure_string(cyl->type.workingpressure, true);
+ fmt += ", " + get_pressure_string(cyl->start, false) + " - " + get_pressure_string(cyl->end, true);
+ fmt += ", " + get_gas_string(cyl->gasmix);
+ return fmt;
+}
+
void Dive::put_cylinder()
{
- m_cylinder = QString(dive->cylinder[0].type.description);
+ for (int i = 0; i < MAX_CYLINDERS; i++)
+ m_cylinders << getFormattedCylinder(dive, i);
}
void Dive::put_trip()
diff --git a/subsurface-core/qthelper.h b/subsurface-core/qthelper.h
index 5fbc6dbe4..86be073f8 100644
--- a/subsurface-core/qthelper.h
+++ b/subsurface-core/qthelper.h
@@ -28,9 +28,9 @@ private:
QString m_tags;
QString m_gas;
QString m_sac;
- QString m_weight;
+ QStringList m_weights;
QString m_suit;
- QString m_cylinder;
+ QStringList m_cylinders;
QString m_trip;
struct dive *dive;
void put_date_time();
@@ -93,9 +93,11 @@ public:
QString tags() const;
QString gas() const;
QString sac() const;
- QString weight() const;
+ QString weights() const;
+ QString weight(int idx) const;
QString suit() const;
- QString cylinder() const;
+ QString cylinders() const;
+ QString cylinder(int idx) const;
QString trip() const;
};