templatelayout.h: expose cylinders and weights in Grantlee HTML

This patch adds the following HTML variables:
"dive.cylinders" -> Dive::cylinders()
"dive.cylinderX" -> Dive::cylinder(X)
"dive.weights" -> Dive::weights()
"dive.weightX" -> Dive::weight(X)

The patch also creates some macros to ease the Dive variable
lookup visually.

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:20 +02:00 committed by Dirk Hohndel
parent 3365a506ef
commit c78a560442

View file

@ -49,43 +49,58 @@ Q_DECLARE_METATYPE(template_options)
Q_DECLARE_METATYPE(print_options) Q_DECLARE_METATYPE(print_options)
Q_DECLARE_METATYPE(YearInfo) Q_DECLARE_METATYPE(YearInfo)
#define _CONC_STR(prop, idx) _CONC_STR1(prop, idx)
#define _CONC_STR1(prop, idx) _CONC_STR2(prop ## idx)
#define _CONC_STR2(prop) #prop
#define _RETURN_DIVE_PROPERTY(prop) \
if (property == #prop) return object.prop()
#define _RETURN_DIVE_PROPERTY_IDX(prop, idx) \
if (property == _CONC_STR(prop, idx)) return object.prop(idx)
GRANTLEE_BEGIN_LOOKUP(Dive) GRANTLEE_BEGIN_LOOKUP(Dive)
if (property == "number") _RETURN_DIVE_PROPERTY(number);
return object.number(); else _RETURN_DIVE_PROPERTY(id);
else if (property == "id") else _RETURN_DIVE_PROPERTY(date);
return object.id(); else _RETURN_DIVE_PROPERTY(time);
else if (property == "date") else _RETURN_DIVE_PROPERTY(location);
return object.date(); else _RETURN_DIVE_PROPERTY(duration);
else if (property == "time") else _RETURN_DIVE_PROPERTY(depth);
return object.time(); else _RETURN_DIVE_PROPERTY(buddy);
else if (property == "location") else _RETURN_DIVE_PROPERTY(divemaster);
return object.location(); else _RETURN_DIVE_PROPERTY(airTemp);
else if (property == "duration") else _RETURN_DIVE_PROPERTY(waterTemp);
return object.duration(); else _RETURN_DIVE_PROPERTY(notes);
else if (property == "depth") else _RETURN_DIVE_PROPERTY(rating);
return object.depth(); else _RETURN_DIVE_PROPERTY(sac);
else if (property == "divemaster") else _RETURN_DIVE_PROPERTY(tags);
return object.divemaster(); else _RETURN_DIVE_PROPERTY(gas);
else if (property == "buddy") else _RETURN_DIVE_PROPERTY(suit);
return object.buddy(); else _RETURN_DIVE_PROPERTY(cylinders);
else if (property == "airTemp") else _RETURN_DIVE_PROPERTY_IDX(cylinder, 0);
return object.airTemp(); else _RETURN_DIVE_PROPERTY_IDX(cylinder, 1);
else if (property == "waterTemp") else _RETURN_DIVE_PROPERTY_IDX(cylinder, 2);
return object.waterTemp(); else _RETURN_DIVE_PROPERTY_IDX(cylinder, 3);
else if (property == "notes") else _RETURN_DIVE_PROPERTY_IDX(cylinder, 4);
return object.notes(); else _RETURN_DIVE_PROPERTY_IDX(cylinder, 5);
else if (property == "rating") else _RETURN_DIVE_PROPERTY_IDX(cylinder, 6);
return object.rating(); else _RETURN_DIVE_PROPERTY_IDX(cylinder, 7);
else if (property == "sac") else _RETURN_DIVE_PROPERTY(weights);
return object.sac(); else _RETURN_DIVE_PROPERTY_IDX(weight, 0);
else if (property == "tags") else _RETURN_DIVE_PROPERTY_IDX(weight, 1);
return object.tags(); else _RETURN_DIVE_PROPERTY_IDX(weight, 2);
else if (property == "gas") else _RETURN_DIVE_PROPERTY_IDX(weight, 3);
return object.gas(); else _RETURN_DIVE_PROPERTY_IDX(weight, 4);
else if (property == "suit") else _RETURN_DIVE_PROPERTY_IDX(weight, 5);
return object.suit();
GRANTLEE_END_LOOKUP GRANTLEE_END_LOOKUP
#undef _RETURN_DIVE_PROPERTY
#undef _RETURN_DIVE_PROPERTY_IDX
#undef _CONC_STR
#undef _CONC_STR1
#undef _CONC_STR2
GRANTLEE_BEGIN_LOOKUP(template_options) GRANTLEE_BEGIN_LOOKUP(template_options)
if (property == "font") { if (property == "font") {
switch (object.font_index) { switch (object.font_index) {