aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/printer.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/printer.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/printer.cpp')
-rw-r--r--desktop-widgets/printer.cpp51
1 files changed, 24 insertions, 27 deletions
diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp
index cd7c11345..05f82d688 100644
--- a/desktop-widgets/printer.cpp
+++ b/desktop-widgets/printer.cpp
@@ -12,15 +12,15 @@
#include <QWebElement>
#include "profile-widget/profilewidget2.h"
-Printer::Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode)
+Printer::Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode) :
+ paintDevice(paintDevice),
+ webView(new QWebView),
+ printOptions(printOptions),
+ templateOptions(templateOptions),
+ printMode(printMode),
+ done(0),
+ dpi(0)
{
- this->paintDevice = paintDevice;
- this->printOptions = printOptions;
- this->templateOptions = templateOptions;
- this->printMode = printMode;
- dpi = 0;
- done = 0;
- webView = new QWebView();
}
Printer::~Printer()
@@ -36,7 +36,7 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
profile->plotDive(dive, true, true);
- if (!printOptions->color_selected) {
+ if (!printOptions.color_selected) {
QImage image(pos.width(), pos.height(), QImage::Format_ARGB32);
QPainter imgPainter(&image);
imgPainter.setRenderHint(QPainter::Antialiasing);
@@ -85,7 +85,7 @@ void Printer::flowRender()
} else {
// fill the page with background color
QRect fullPage(0, 0, pageSize.width(), pageSize.height());
- QBrush fillBrush(templateOptions->color_palette.color1);
+ QBrush fillBrush(templateOptions.color_palette.color1);
painter.fillRect(fullPage, fillBrush);
QRegion reigon(0, 0, pageSize.width(), end - start);
viewPort.setRect(0, start, pageSize.width(), end - start);
@@ -111,7 +111,7 @@ void Printer::flowRender()
}
// render the remianing page
QRect fullPage(0, 0, pageSize.width(), pageSize.height());
- QBrush fillBrush(templateOptions->color_palette.color1);
+ QBrush fillBrush(templateOptions.color_palette.color1);
painter.fillRect(fullPage, fillBrush);
QRegion reigon(0, 0, pageSize.width(), end - start);
webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer, reigon);
@@ -130,7 +130,7 @@ void Printer::render(int Pages = 0)
// apply printing settings to profile
profile->setFrameStyle(QFrame::NoFrame);
- profile->setPrintMode(true, !printOptions->color_selected);
+ profile->setPrintMode(true, !printOptions.color_selected);
profile->setToolTipVisibile(false);
qPrefDisplay::set_animation_speed(0);
@@ -195,16 +195,16 @@ void Printer::templateProgessUpdated(int value)
emit progessUpdated(done);
}
-QString Printer::exportHtml() {
+QString Printer::exportHtml()
+{
TemplateLayout t(printOptions, templateOptions);
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
QString html;
- if (printOptions->type == print_options::DIVELIST) {
+ if (printOptions.type == print_options::DIVELIST)
html = t.generate();
- } else if (printOptions->type == print_options::STATISTICS ) {
+ else if (printOptions.type == print_options::STATISTICS )
html = t.generateStatistics();
- }
// TODO: write html to file
return html;
@@ -231,17 +231,15 @@ void Printer::print()
webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
// export border width with at least 1 pixel
- // templateOptions->borderwidth = std::max(1, pageSize.width() / 1000);
- if (printOptions->type == print_options::DIVELIST) {
+ // templateOptions.borderwidth = std::max(1, pageSize.width() / 1000);
+ if (printOptions.type == print_options::DIVELIST)
webView->setHtml(t.generate());
- } else if (printOptions->type == print_options::STATISTICS ) {
+ else if (printOptions.type == print_options::STATISTICS )
webView->setHtml(t.generateStatistics());
- }
- if (printOptions->color_selected && printerPtr->colorMode()) {
+ if (printOptions.color_selected && printerPtr->colorMode())
printerPtr->setColorMode(QPrinter::Color);
- } else {
+ else
printerPtr->setColorMode(QPrinter::GrayScale);
- }
// apply user settings
int divesPerPage;
@@ -270,12 +268,11 @@ void Printer::previewOnePage()
pageSize.setWidth(paintDevice->width());
webView->page()->setViewportSize(pageSize);
// initialize the border settings
- // templateOptions->border_width = std::max(1, pageSize.width() / 1000);
- if (printOptions->type == print_options::DIVELIST) {
+ // templateOptions.border_width = std::max(1, pageSize.width() / 1000);
+ if (printOptions.type == print_options::DIVELIST)
webView->setHtml(t.generate());
- } else if (printOptions->type == print_options::STATISTICS ) {
+ else if (printOptions.type == print_options::STATISTICS )
webView->setHtml(t.generateStatistics());
- }
bool ok;
int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
if (!ok) {