aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2020-12-08 23:44:44 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-12-08 21:46:10 -0800
commit11eec0a503df9df5619a294c2769437c4fee36ea (patch)
tree6efb46d3a1926c5afbd0e2260522082a771e22f7
parent5452001dce19010a79e709428d830f2abd7d23a6 (diff)
downloadsubsurface-11eec0a503df9df5619a294c2769437c4fee36ea.tar.gz
Fix cylinders in printing templates
These did not appear in our templates. With this commit, there are two lists to iterate over, cylinders and cylinderObjects: cylinders has just one property: description which is a string summarizing cylinder information cylinderObjects has the individual properties addresable This also fixes a bug when the iterator variable did not have the singular name of the list it iterates over. Signed-off-by: Robert C. Helling <helling@atdotde.de>
-rw-r--r--desktop-widgets/templatelayout.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp
index 997213fd6..76d6e771f 100644
--- a/desktop-widgets/templatelayout.cpp
+++ b/desktop-widgets/templatelayout.cpp
@@ -280,7 +280,8 @@ QString TemplateLayout::translate(QString s, QHash<QString, QVariant> options)
QString obname = match.captured(1);
QString memname = match.captured(2);
out += s.mid(last, match.capturedStart() - last);
- QVariant value = getValue(obname, memname, options.value(obname));
+ QString listname = options.contains("typeof:" + obname) ? options.value("typeof:" + obname).value<QString>() : obname;
+ QVariant value = getValue(listname, memname, options.value(obname));
out += value.toString();
last = match.capturedEnd();
match = var.match(s, last);
@@ -312,6 +313,7 @@ void TemplateLayout::parser(QList<token> tokenList, int &pos, QTextStream &out,
if (match.hasMatch()) {
QString itemname = match.captured(1);
QString listname = match.captured(2);
+ options["typeof:" + itemname] = listname;
QString buffer;
QTextStream capture(&buffer);
QVariantList list = options[listname].value<QVariantList>();
@@ -322,16 +324,21 @@ void TemplateLayout::parser(QList<token> tokenList, int &pos, QTextStream &out,
options[itemname] = item;
options["forloopiterator"] = i + 1;
pos = savepos;
- if (listname == "dives")
- options["cylinders"] = QVariant::fromValue(item.value<DiveObjectHelperGrantlee>().cylinderList());
+ if (listname == "dives") {
+ options["cylinderObjects"] = QVariant::fromValue(item.value<DiveObjectHelperGrantlee>().cylinderObjects);
+ options["cylinders"] = QVariant::fromValue(item.value<DiveObjectHelperGrantlee>().cylinders);
+ }
parser(tokenList, pos, capture, options);
options.remove(itemname);
options.remove("forloopiterator");
- if (listname == "dives")
+ if (listname == "dives") {
+ options.remove("cylinderObjects");
options.remove("cylinders");
+ }
if (olditerator.isValid())
options["forloopiterator"] = olditerator;
}
+ options.remove("typeof:" + itemname);
out << capture.readAll();
} else {
out << "PARSING ERROR: '" << argument << "'";
@@ -444,7 +451,11 @@ QVariant TemplateLayout::getValue(QString list, QString property, QVariant optio
} else if (property == "max_sac") {
return get_volume_string(object.year->max_sac);
}
- } else if (list == "cylinder") {
+ } else if (list == "cylinders") {
+ if (property == "description") {
+ return option.value<QString>();
+ }
+ } else if (list == "cylinderObjects") {
CylinderObjectHelper object = option.value<CylinderObjectHelper>();
if (property == "description") {
return object.description;
@@ -459,7 +470,7 @@ QVariant TemplateLayout::getValue(QString list, QString property, QVariant optio
} else if (property == "gasMix") {
return object.gasMix;
}
- } else if (list == "dive") {
+ } else if (list == "dives") {
DiveObjectHelperGrantlee object = option.value<DiveObjectHelperGrantlee>();
if (property == "number") {
return object.number;