summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/templatelayout.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-12-12 13:28:36 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-12-17 13:03:56 -0800
commit0cbb4487401b749476e939db20b842e04099bfa8 (patch)
tree2627229973b9d9cbb25c83953231e29fe0f1cd91 /desktop-widgets/templatelayout.cpp
parent7bdd968e05a3ec11ab9f207e7bd32ff7bffc34a8 (diff)
downloadsubsurface-0cbb4487401b749476e939db20b842e04099bfa8.tar.gz
cleanup: make templateOptions and printOptions reference types
These two structs describe options used during printing. They are passed through numerous classes as pointer. In this case, reference semantics are preferred, as references: - can never be null - can not change during their lifetime This not only helps the compiler, as it can optimize away null checks, but also your fellow coder. Moreover, it prevents unintentional creation of uninitialized references: one can't create an instance of a class without initializing a reference member. It does not prevent references from going dangling. However, pointers have the same disadvantage. Contains a few whitespace cleanups. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/templatelayout.cpp')
-rw-r--r--desktop-widgets/templatelayout.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp
index 10907767b..9ed5a35cf 100644
--- a/desktop-widgets/templatelayout.cpp
+++ b/desktop-widgets/templatelayout.cpp
@@ -9,9 +9,9 @@
QList<QString> grantlee_templates, grantlee_statistics_templates;
-int getTotalWork(print_options *printOptions)
+int getTotalWork(const print_options &printOptions)
{
- if (printOptions->print_selected) {
+ if (printOptions.print_selected) {
// return the correct number depending on all/selected dives
// but don't return 0 as we might divide by this number
return amount_selected && !in_planner() ? amount_selected : 1;
@@ -94,10 +94,9 @@ void copy_bundled_templates(QString src, QString dst, QStringList *templateBacku
}
}
-TemplateLayout::TemplateLayout(print_options *printOptions, template_options *templateOptions)
+TemplateLayout::TemplateLayout(const print_options &printOptions, const template_options &templateOptions) :
+ printOptions(printOptions), templateOptions(templateOptions)
{
- this->printOptions = printOptions;
- this->templateOptions = templateOptions;
}
QString TemplateLayout::generate()
@@ -117,7 +116,7 @@ QString TemplateLayout::generate()
int i;
for_each_dive (i, dive) {
//TODO check for exporting selected dives only
- if (!dive->selected && printOptions->print_selected)
+ if (!dive->selected && printOptions.print_selected)
continue;
diveList.append(QVariant::fromValue(DiveObjectHelperGrantlee(dive)));
progress++;
@@ -125,11 +124,11 @@ QString TemplateLayout::generate()
}
}
- QString templateContents = readTemplate(printOptions->p_template);
+ QString templateContents = readTemplate(printOptions.p_template);
QHash<QString, QVariant> options;
- options["print_options"] = QVariant::fromValue(*printOptions);
- options["template_options"] = QVariant::fromValue(*templateOptions);
+ options["print_options"] = QVariant::fromValue(printOptions);
+ options["template_options"] = QVariant::fromValue(templateOptions);
options["dives"] = QVariant::fromValue(diveList);
QList<token> tokens = lexer(templateContents);
QString buffer;
@@ -154,12 +153,12 @@ QString TemplateLayout::generateStatistics()
i++;
}
- QString templateFile = QString("statistics") + QDir::separator() + printOptions->p_template;
+ QString templateFile = QString("statistics") + QDir::separator() + printOptions.p_template;
QString templateContents = readTemplate(templateFile);
QHash<QString, QVariant> options;
- options["print_options"] = QVariant::fromValue(*printOptions);
- options["template_options"] = QVariant::fromValue(*templateOptions);
+ options["print_options"] = QVariant::fromValue(printOptions);
+ options["template_options"] = QVariant::fromValue(templateOptions);
options["years"] = QVariant::fromValue(years);
QList<token> tokens = lexer(templateContents);
QString buffer;