mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Grantlee: split out grantlee-only property from DiveObjectHelper
The cylindersObject list was only used by grantlee but not by the mobile code. Since it is quite heavy, split it out and thus don't generate it for every dive on mobile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
6a9df3bba3
commit
718c07c1a8
4 changed files with 32 additions and 10 deletions
|
@ -238,7 +238,6 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) :
|
|||
singleWeight(d->weightsystems.nr <= 1),
|
||||
suit(d->suit ? d->suit : QString()),
|
||||
cylinders(formatCylinders(d)),
|
||||
cylinderObjects(makeCylinderObjects(d)),
|
||||
maxcns(d->maxcns),
|
||||
otu(d->otu),
|
||||
sumWeight(get_weight_string(weight_t { total_weight(d) }, true)),
|
||||
|
@ -249,6 +248,16 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) :
|
|||
{
|
||||
}
|
||||
|
||||
DiveObjectHelperGrantlee::DiveObjectHelperGrantlee()
|
||||
{
|
||||
}
|
||||
|
||||
DiveObjectHelperGrantlee::DiveObjectHelperGrantlee(const struct dive *d) :
|
||||
DiveObjectHelper(d),
|
||||
cylinderObjects(makeCylinderObjects(d))
|
||||
{
|
||||
}
|
||||
|
||||
QString DiveObjectHelper::date() const
|
||||
{
|
||||
QDateTime localTime = QDateTime::fromMSecsSinceEpoch(1000 * timestamp, Qt::UTC);
|
||||
|
|
|
@ -39,7 +39,6 @@ class DiveObjectHelper {
|
|||
Q_PROPERTY(QString suit MEMBER suit CONSTANT)
|
||||
Q_PROPERTY(QStringList cylinderList READ cylinderList CONSTANT)
|
||||
Q_PROPERTY(QStringList cylinders MEMBER cylinders CONSTANT)
|
||||
Q_PROPERTY(QVector<CylinderObjectHelper> cylinderObjects MEMBER cylinderObjects CONSTANT)
|
||||
Q_PROPERTY(int maxcns MEMBER maxcns CONSTANT)
|
||||
Q_PROPERTY(int otu MEMBER otu CONSTANT)
|
||||
Q_PROPERTY(QString sumWeight MEMBER sumWeight CONSTANT)
|
||||
|
@ -78,7 +77,6 @@ public:
|
|||
QString suit;
|
||||
QStringList cylinderList() const;
|
||||
QStringList cylinders;
|
||||
QVector<CylinderObjectHelper> cylinderObjects;
|
||||
int maxcns;
|
||||
int otu;
|
||||
QString sumWeight;
|
||||
|
@ -87,6 +85,21 @@ public:
|
|||
QStringList endPressure;
|
||||
QStringList firstGas;
|
||||
};
|
||||
Q_DECLARE_METATYPE(DiveObjectHelper)
|
||||
|
||||
// This is an extended version of DiveObjectHelper that also keeps track of cylinder data.
|
||||
// It is used by grantlee to display structured cylinder data.
|
||||
// Note: this grantlee feature is undocumented. If there turns out to be no users, we might
|
||||
// want to remove this class.
|
||||
class DiveObjectHelperGrantlee : public DiveObjectHelper {
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QVector<CylinderObjectHelper> cylinderObjects MEMBER cylinderObjects CONSTANT)
|
||||
public:
|
||||
DiveObjectHelperGrantlee();
|
||||
DiveObjectHelperGrantlee(const struct dive *dive);
|
||||
QVector<CylinderObjectHelper> cylinderObjects;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(DiveObjectHelper)
|
||||
Q_DECLARE_METATYPE(DiveObjectHelperGrantlee)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -100,7 +100,7 @@ TemplateLayout::TemplateLayout(print_options *printOptions, template_options *te
|
|||
}
|
||||
|
||||
/* a HTML pre-processor stage. acts like a compatibility layer
|
||||
* between some Grantlee variables and DiveObjectHelper Q_PROPERTIES:
|
||||
* between some Grantlee variables and DiveObjectHelperGrantlee Q_PROPERTIES:
|
||||
* dive.weights -> dive.weightList
|
||||
* dive.weight# -> dive.weights.#
|
||||
* dive.cylinders -> dive.cylinderList
|
||||
|
@ -134,13 +134,13 @@ QString TemplateLayout::generate()
|
|||
Grantlee::registerMetaType<template_options>();
|
||||
Grantlee::registerMetaType<print_options>();
|
||||
Grantlee::registerMetaType<CylinderObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET
|
||||
Grantlee::registerMetaType<DiveObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET
|
||||
Grantlee::registerMetaType<DiveObjectHelperGrantlee>(); // TODO: Remove when grantlee supports Q_GADGET
|
||||
|
||||
QVariantList diveList;
|
||||
|
||||
struct dive *dive;
|
||||
if (in_planner()) {
|
||||
diveList.append(QVariant::fromValue(DiveObjectHelper(&displayed_dive)));
|
||||
diveList.append(QVariant::fromValue(DiveObjectHelperGrantlee(&displayed_dive)));
|
||||
emit progressUpdated(100.0);
|
||||
} else {
|
||||
int i;
|
||||
|
@ -148,7 +148,7 @@ QString TemplateLayout::generate()
|
|||
//TODO check for exporting selected dives only
|
||||
if (!dive->selected && printOptions->print_selected)
|
||||
continue;
|
||||
diveList.append(QVariant::fromValue(DiveObjectHelper(dive)));
|
||||
diveList.append(QVariant::fromValue(DiveObjectHelperGrantlee(dive)));
|
||||
progress++;
|
||||
emit progressUpdated(lrint(progress * 100.0 / totalWork));
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ QString TemplateLayout::generateStatistics()
|
|||
Grantlee::registerMetaType<template_options>();
|
||||
Grantlee::registerMetaType<print_options>();
|
||||
Grantlee::registerMetaType<CylinderObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET
|
||||
Grantlee::registerMetaType<DiveObjectHelper>(); // TODO: Remove when grantlee supports Q_GADGET
|
||||
Grantlee::registerMetaType<DiveObjectHelperGrantlee>(); // TODO: Remove when grantlee supports Q_GADGET
|
||||
|
||||
QVariantList years;
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ GRANTLEE_END_LOOKUP
|
|||
// TODO: This is currently needed because our grantlee version
|
||||
// doesn't support Q_GADGET based classes. A patch to fix this
|
||||
// exists. Remove in due course.
|
||||
GRANTLEE_BEGIN_LOOKUP(DiveObjectHelper)
|
||||
GRANTLEE_BEGIN_LOOKUP(DiveObjectHelperGrantlee)
|
||||
if (property == "number") {
|
||||
return object.number;
|
||||
} else if (property == "id") {
|
||||
|
|
Loading…
Reference in a new issue