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>
This commit is contained in:
Lubomir I. Ivanov 2015-11-17 00:29:18 +02:00 committed by Dirk Hohndel
parent a34dfe8284
commit dd944ab33f
2 changed files with 65 additions and 11 deletions

View file

@ -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()

View file

@ -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;
};