Grantlee: generate vector of cylinder data on-demand

Instead of generating cylinder data in the form of
CylinderObjectHelper objects for every DiveObjectHelper,
generate it only if needed. DiveObjectHelper is used extensively
in the mobile interface, which doesn't use the cylinder data.
Let's not generate unnecessary CylinderObjectHelpers in this
case!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-08-12 18:43:21 +02:00 committed by Dirk Hohndel
parent f25fa2adc5
commit e6cd4f8ae5
2 changed files with 7 additions and 9 deletions

View file

@ -58,13 +58,6 @@ static QString getPressures(struct dive *dive, int i, enum returnPressureSelecto
DiveObjectHelper::DiveObjectHelper(struct dive *d) :
m_dive(d)
{
if (!m_dive)
qWarning("Creating DiveObjectHelper from NULL dive");
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(CylinderObjectHelper(&m_dive->cylinder[i]));
}
}
int DiveObjectHelper::number() const
@ -311,7 +304,13 @@ QString DiveObjectHelper::cylinder(int idx) const
QVector<CylinderObjectHelper> DiveObjectHelper::cylinderObjects() const
{
return m_cyls;
QVector<CylinderObjectHelper> res;
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)
res.append(CylinderObjectHelper(&m_dive->cylinder[i])); // no emplace for QVector. :(
}
return res;
}
QString DiveObjectHelper::tripId() const

View file

@ -99,7 +99,6 @@ public:
private:
struct dive *m_dive;
QVector<CylinderObjectHelper> m_cyls;
};
Q_DECLARE_METATYPE(DiveObjectHelper *)