summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/templateedit.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/templateedit.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/templateedit.cpp')
-rw-r--r--desktop-widgets/templateedit.cpp62
1 files changed, 31 insertions, 31 deletions
diff --git a/desktop-widgets/templateedit.cpp b/desktop-widgets/templateedit.cpp
index 36af4c994..d96ebdeef 100644
--- a/desktop-widgets/templateedit.cpp
+++ b/desktop-widgets/templateedit.cpp
@@ -8,27 +8,27 @@
#include <QButtonGroup>
#include <QColorDialog>
-TemplateEdit::TemplateEdit(QWidget *parent, struct print_options *printOptions, struct template_options *templateOptions) :
+TemplateEdit::TemplateEdit(QWidget *parent, const print_options &printOptions, template_options &templateOptions) :
QDialog(parent),
- ui(new Ui::TemplateEdit)
+ ui(new Ui::TemplateEdit),
+ printOptions(printOptions),
+ templateOptions(templateOptions)
{
ui->setupUi(this);
- this->templateOptions = templateOptions;
- newTemplateOptions = *templateOptions;
- this->printOptions = printOptions;
+ newTemplateOptions = templateOptions;
// restore the settings and init the UI
- ui->fontSelection->setCurrentIndex(templateOptions->font_index);
- ui->fontsize->setValue(lrint(templateOptions->font_size));
- ui->colorpalette->setCurrentIndex(templateOptions->color_palette_index);
- ui->linespacing->setValue(templateOptions->line_spacing);
- ui->borderwidth->setValue(templateOptions->border_width);
-
- grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
- if (printOptions->type == print_options::DIVELIST)
- grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
- else if (printOptions->type == print_options::STATISTICS)
- grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template);
+ ui->fontSelection->setCurrentIndex(templateOptions.font_index);
+ ui->fontsize->setValue(lrint(templateOptions.font_size));
+ ui->colorpalette->setCurrentIndex(templateOptions.color_palette_index);
+ ui->linespacing->setValue(templateOptions.line_spacing);
+ ui->borderwidth->setValue(templateOptions.border_width);
+
+ grantlee_template = TemplateLayout::readTemplate(printOptions.p_template);
+ if (printOptions.type == print_options::DIVELIST)
+ grantlee_template = TemplateLayout::readTemplate(printOptions.p_template);
+ else if (printOptions.type == print_options::STATISTICS)
+ grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions.p_template);
// gui
btnGroup = new QButtonGroup;
@@ -58,7 +58,7 @@ void TemplateEdit::updatePreview()
int height = ui->label->height();
QPixmap map(width * 2, height * 2);
map.fill(QColor::fromRgb(255, 255, 255));
- Printer printer(&map, printOptions, &newTemplateOptions, Printer::PREVIEW);
+ Printer printer(&map, printOptions, newTemplateOptions, Printer::PREVIEW);
printer.previewOnePage();
ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio));
@@ -81,11 +81,11 @@ void TemplateEdit::updatePreview()
ui->colorpalette->setCurrentIndex(newTemplateOptions.color_palette_index);
// update grantlee template string
- grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
- if (printOptions->type == print_options::DIVELIST)
- grantlee_template = TemplateLayout::readTemplate(printOptions->p_template);
- else if (printOptions->type == print_options::STATISTICS)
- grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template);
+ grantlee_template = TemplateLayout::readTemplate(printOptions.p_template);
+ if (printOptions.type == print_options::DIVELIST)
+ grantlee_template = TemplateLayout::readTemplate(printOptions.p_template);
+ else if (printOptions.type == print_options::STATISTICS)
+ grantlee_template = TemplateLayout::readTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions.p_template);
}
void TemplateEdit::on_fontsize_valueChanged(int font_size)
@@ -137,7 +137,7 @@ void TemplateEdit::on_colorpalette_currentIndexChanged(int index)
void TemplateEdit::saveSettings()
{
- if ((*templateOptions) != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
+ if (templateOptions != newTemplateOptions || grantlee_template.compare(ui->plainTextEdit->toPlainText())) {
QMessageBox msgBox(this);
QString message = tr("Do you want to save your changes?");
bool templateChanged = false;
@@ -147,16 +147,16 @@ void TemplateEdit::saveSettings()
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
if (msgBox.exec() == QMessageBox::Save) {
- *templateOptions = newTemplateOptions;
+ templateOptions = newTemplateOptions;
if (templateChanged) {
- TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText());
- if (printOptions->type == print_options::DIVELIST)
- TemplateLayout::writeTemplate(printOptions->p_template, ui->plainTextEdit->toPlainText());
- else if (printOptions->type == print_options::STATISTICS)
- TemplateLayout::writeTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions->p_template, ui->plainTextEdit->toPlainText());
+ TemplateLayout::writeTemplate(printOptions.p_template, ui->plainTextEdit->toPlainText());
+ if (printOptions.type == print_options::DIVELIST)
+ TemplateLayout::writeTemplate(printOptions.p_template, ui->plainTextEdit->toPlainText());
+ else if (printOptions.type == print_options::STATISTICS)
+ TemplateLayout::writeTemplate(QString::fromUtf8("statistics") + QDir::separator() + printOptions.p_template, ui->plainTextEdit->toPlainText());
}
- if (templateOptions->color_palette_index == CUSTOM)
- custom_colors = templateOptions->color_palette;
+ if (templateOptions.color_palette_index == CUSTOM)
+ custom_colors = templateOptions.color_palette;
}
}
}