mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 20:36:15 +00:00
printing: remove DiveObjectHelperGrantlee
This was a weird helper object, needed for grantlee. Instead of storing this object, loop over cylinders and dives directly. The actual accessor function is unchanged and now generates a DiveObjectHelper or DiveCylinderHelper for every variable access. Obviously, this is very inefficient. However, this will be replaced in future commits by direct calls to formatting functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
bf8261c001
commit
d9942269a9
6 changed files with 42 additions and 69 deletions
|
@ -143,3 +143,24 @@ QStringList formatFullCylinderList()
|
||||||
return cylinders;
|
return cylinders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString formattedCylinder(const struct dive *dive, int idx)
|
||||||
|
{
|
||||||
|
const cylinder_t *cyl = get_cylinder(dive, idx);
|
||||||
|
const char *desc = cyl->type.description;
|
||||||
|
QString fmt = desc ? QString(desc) : gettextFromC::tr("unknown");
|
||||||
|
fmt += ", " + get_volume_string(cyl->type.size, true);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList formatCylinders(const dive *d)
|
||||||
|
{
|
||||||
|
QStringList cylinders;
|
||||||
|
for (int i = 0; i < d->cylinders.nr; i++) {
|
||||||
|
QString cyl = formattedCylinder(d, i);
|
||||||
|
cylinders << cyl;
|
||||||
|
}
|
||||||
|
return cylinders;
|
||||||
|
}
|
||||||
|
|
|
@ -15,5 +15,6 @@ QStringList formatStartPressure(const dive *d);
|
||||||
QStringList formatEndPressure(const dive *d);
|
QStringList formatEndPressure(const dive *d);
|
||||||
QStringList formatFirstGas(const dive *d);
|
QStringList formatFirstGas(const dive *d);
|
||||||
QStringList formatFullCylinderList();
|
QStringList formatFullCylinderList();
|
||||||
|
QStringList formatCylinders(const dive *d);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,18 +30,6 @@ static QString getFormattedWeight(const struct dive *dive, int idx)
|
||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString getFormattedCylinder(const struct dive *dive, int idx)
|
|
||||||
{
|
|
||||||
const cylinder_t *cyl = get_cylinder(dive, idx);
|
|
||||||
const char *desc = cyl->type.description;
|
|
||||||
QString fmt = desc ? QString(desc) : gettextFromC::tr("unknown");
|
|
||||||
fmt += ", " + get_volume_string(cyl->type.size, true);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString formatGas(const dive *d)
|
static QString formatGas(const dive *d)
|
||||||
{
|
{
|
||||||
/*WARNING: here should be the gastlist, returned
|
/*WARNING: here should be the gastlist, returned
|
||||||
|
@ -89,27 +77,6 @@ static QStringList formatWeights(const dive *d)
|
||||||
return weights;
|
return weights;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList formatCylinders(const dive *d)
|
|
||||||
{
|
|
||||||
QStringList cylinders;
|
|
||||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
|
||||||
QString cyl = getFormattedCylinder(d, i);
|
|
||||||
cylinders << cyl;
|
|
||||||
}
|
|
||||||
return cylinders;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QVector<CylinderObjectHelper> makeCylinderObjects(const dive *d)
|
|
||||||
{
|
|
||||||
QVector<CylinderObjectHelper> res;
|
|
||||||
for (int i = 0; i < d->cylinders.nr; i++) {
|
|
||||||
//Don't add blank cylinders, only those that have been defined.
|
|
||||||
if (get_cylinder(d, i)->type.description)
|
|
||||||
res.append(CylinderObjectHelper(get_cylinder(d, i))); // no emplace for QVector. :(
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString formatDiveSalinity(const dive *d)
|
QString formatDiveSalinity(const dive *d)
|
||||||
{
|
{
|
||||||
int salinity = get_dive_salinity(d);
|
int salinity = get_dive_salinity(d);
|
||||||
|
@ -181,16 +148,6 @@ DiveObjectHelper::DiveObjectHelper(const struct dive *d) :
|
||||||
#endif /* defined(DEBUG_DOH) */
|
#endif /* defined(DEBUG_DOH) */
|
||||||
}
|
}
|
||||||
|
|
||||||
DiveObjectHelperGrantlee::DiveObjectHelperGrantlee()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DiveObjectHelperGrantlee::DiveObjectHelperGrantlee(const struct dive *d) :
|
|
||||||
DiveObjectHelper(d),
|
|
||||||
cylinderObjects(makeCylinderObjects(d))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DiveObjectHelper::date() const
|
QString DiveObjectHelper::date() const
|
||||||
{
|
{
|
||||||
QDateTime localTime = timestampToDateTime(timestamp);
|
QDateTime localTime = timestampToDateTime(timestamp);
|
||||||
|
|
|
@ -96,20 +96,6 @@ public:
|
||||||
QString waterType;
|
QString waterType;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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(DiveObjectHelper)
|
||||||
Q_DECLARE_METATYPE(DiveObjectHelperGrantlee)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "core/divelist.h"
|
#include "core/divelist.h"
|
||||||
#include "core/selection.h"
|
#include "core/selection.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
|
#include "core/string-format.h"
|
||||||
#include "core/subsurface-qt/diveobjecthelper.h"
|
#include "core/subsurface-qt/diveobjecthelper.h"
|
||||||
#include "core/subsurface-qt/cylinderobjecthelper.h" // TODO: remove once grantlee supports Q_GADGET objects
|
#include "core/subsurface-qt/cylinderobjecthelper.h" // TODO: remove once grantlee supports Q_GADGET objects
|
||||||
|
|
||||||
|
@ -115,7 +116,7 @@ QString TemplateLayout::generate()
|
||||||
|
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
if (in_planner()) {
|
if (in_planner()) {
|
||||||
state.dives.append(DiveObjectHelperGrantlee(&displayed_dive));
|
state.dives.append(&displayed_dive);
|
||||||
emit progressUpdated(100.0);
|
emit progressUpdated(100.0);
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
|
@ -123,7 +124,7 @@ QString TemplateLayout::generate()
|
||||||
//TODO check for exporting selected dives only
|
//TODO check for exporting selected dives only
|
||||||
if (!dive->selected && printOptions.print_selected)
|
if (!dive->selected && printOptions.print_selected)
|
||||||
continue;
|
continue;
|
||||||
state.dives.append(DiveObjectHelperGrantlee(dive));
|
state.dives.append(dive);
|
||||||
progress++;
|
progress++;
|
||||||
emit progressUpdated(lrint(progress * 100.0 / totalWork));
|
emit progressUpdated(lrint(progress * 100.0 / totalWork));
|
||||||
}
|
}
|
||||||
|
@ -320,6 +321,15 @@ static int findEnd(const QList<token> &tokenList, int from, int to, token_t star
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<const cylinder_t *> cylinderList(const dive *d)
|
||||||
|
{
|
||||||
|
std::vector<const cylinder_t *> res;
|
||||||
|
res.reserve(d->cylinders.nr);
|
||||||
|
for (int i = 0; i < d->cylinders.nr; ++i)
|
||||||
|
res.push_back(&d->cylinders.cylinders[i]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
void TemplateLayout::parser(QList<token> tokenList, int from, int to, QTextStream &out, State &state)
|
void TemplateLayout::parser(QList<token> tokenList, int from, int to, QTextStream &out, State &state)
|
||||||
{
|
{
|
||||||
for (int pos = from; pos < to; ++pos) {
|
for (int pos = from; pos < to; ++pos) {
|
||||||
|
@ -352,12 +362,12 @@ void TemplateLayout::parser(QList<token> tokenList, int from, int to, QTextStrea
|
||||||
parser_for(tokenList, pos, loop_end, capture, state, state.dives, state.currentDive);
|
parser_for(tokenList, pos, loop_end, capture, state, state.dives, state.currentDive);
|
||||||
} else if (listname == "cylinders") {
|
} else if (listname == "cylinders") {
|
||||||
if (state.currentDive)
|
if (state.currentDive)
|
||||||
parser_for(tokenList, pos, loop_end, capture, state, state.currentDive->cylinders, state.currentCylinder);
|
parser_for(tokenList, pos, loop_end, capture, state, formatCylinders(*state.currentDive), state.currentCylinder);
|
||||||
else
|
else
|
||||||
qWarning("cylinders loop outside of dive");
|
qWarning("cylinders loop outside of dive");
|
||||||
} else if (listname == "cylinderObjects") {
|
} else if (listname == "cylinderObjects") {
|
||||||
if (state.currentDive)
|
if (state.currentDive)
|
||||||
parser_for(tokenList, pos, loop_end, capture, state, state.currentDive->cylinderObjects, state.currentCylinderObject);
|
parser_for(tokenList, pos, loop_end, capture, state, cylinderList(*state.currentDive), state.currentCylinderObject);
|
||||||
else
|
else
|
||||||
qWarning("cylinderObjects loop outside of dive");
|
qWarning("cylinderObjects loop outside of dive");
|
||||||
} else {
|
} else {
|
||||||
|
@ -490,7 +500,7 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
|
||||||
} else if (list == "cylinderObjects") {
|
} else if (list == "cylinderObjects") {
|
||||||
if (!state.currentCylinderObject)
|
if (!state.currentCylinderObject)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
const CylinderObjectHelper &object = *state.currentCylinderObject;
|
const CylinderObjectHelper object(*state.currentCylinderObject);
|
||||||
if (property == "description") {
|
if (property == "description") {
|
||||||
return object.description;
|
return object.description;
|
||||||
} else if (property == "size") {
|
} else if (property == "size") {
|
||||||
|
@ -507,7 +517,7 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
|
||||||
} else if (list == "dives") {
|
} else if (list == "dives") {
|
||||||
if (!state.currentDive)
|
if (!state.currentDive)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
const DiveObjectHelperGrantlee &object = *state.currentDive;
|
const DiveObjectHelper object(*state.currentDive);
|
||||||
if (property == "number") {
|
if (property == "number") {
|
||||||
return object.number;
|
return object.number;
|
||||||
} else if (property == "id") {
|
} else if (property == "id") {
|
||||||
|
@ -572,8 +582,6 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
|
||||||
return object.cylinderList();
|
return object.cylinderList();
|
||||||
} else if (property == "cylinders") {
|
} else if (property == "cylinders") {
|
||||||
return object.cylinders;
|
return object.cylinders;
|
||||||
} else if (property == "cylinderObjects") {
|
|
||||||
return QVariant::fromValue(object.cylinderObjects);
|
|
||||||
} else if (property == "maxcns") {
|
} else if (property == "maxcns") {
|
||||||
return object.maxcns;
|
return object.maxcns;
|
||||||
} else if (property == "otu") {
|
} else if (property == "otu") {
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
#define TEMPLATELAYOUT_H
|
#define TEMPLATELAYOUT_H
|
||||||
|
|
||||||
#include "core/statistics.h"
|
#include "core/statistics.h"
|
||||||
|
#include "core/equipment.h"
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
class DiveObjectHelperGrantlee;
|
|
||||||
class CylinderObjectHelper;
|
class CylinderObjectHelper;
|
||||||
struct print_options;
|
struct print_options;
|
||||||
struct template_options;
|
struct template_options;
|
||||||
|
@ -36,14 +36,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct State {
|
struct State {
|
||||||
QList<DiveObjectHelperGrantlee> dives;
|
QList<const dive *> dives;
|
||||||
QList<stats_t *> years;
|
QList<stats_t *> years;
|
||||||
QMap<QString, QString> types;
|
QMap<QString, QString> types;
|
||||||
int forloopiterator = -1;
|
int forloopiterator = -1;
|
||||||
const DiveObjectHelperGrantlee *currentDive = nullptr;
|
const dive * const *currentDive = nullptr;
|
||||||
const stats_t * const *currentYear = nullptr;
|
const stats_t * const *currentYear = nullptr;
|
||||||
const QString *currentCylinder = nullptr;
|
const QString *currentCylinder = nullptr;
|
||||||
const CylinderObjectHelper *currentCylinderObject = nullptr;
|
const cylinder_t * const *currentCylinderObject = nullptr;
|
||||||
};
|
};
|
||||||
const print_options &printOptions;
|
const print_options &printOptions;
|
||||||
const template_options &templateOptions;
|
const template_options &templateOptions;
|
||||||
|
|
Loading…
Add table
Reference in a new issue