diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-02-13 22:43:55 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-02-17 07:26:55 -0800 |
commit | 42cff9b3a506d2b52739d8714d5698e1a3b2e3f9 (patch) | |
tree | f473c21e7d8e056f1630078dc7207c35dd912d54 /desktop-widgets | |
parent | 18049bc8d08a4e223a9824efb26b710e6bca1958 (diff) | |
download | subsurface-42cff9b3a506d2b52739d8714d5698e1a3b2e3f9.tar.gz |
planner: pass in_planner down to TemplateLayout
The TemplateLayout prints different dives depending on
whether the planner is active. Instead of accessing a
global variable, pass the status down from the MainWindow.
That's all quite convoluted, since there are multiple
layers involved.
On the positive side, the in_planner() function has now
no users an can be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/printdialog.cpp | 7 | ||||
-rw-r--r-- | desktop-widgets/printdialog.h | 3 | ||||
-rw-r--r-- | desktop-widgets/printer.cpp | 9 | ||||
-rw-r--r-- | desktop-widgets/printer.h | 3 | ||||
-rw-r--r-- | desktop-widgets/templateedit.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.h | 2 |
8 files changed, 20 insertions, 14 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 91fd44fcb..e2fb7368a 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -653,7 +653,9 @@ void MainWindow::updateLastUsedDir(const QString &dir) void MainWindow::on_actionPrint_triggered() { #ifndef NO_PRINTING - PrintDialog dlg(this); + bool in_planner = getAppState() == ApplicationState::PlanDive || + getAppState() == ApplicationState::EditPlannedDive; + PrintDialog dlg(in_planner, this); dlg.exec(); #endif diff --git a/desktop-widgets/printdialog.cpp b/desktop-widgets/printdialog.cpp index 8187dda6e..a4c181c68 100644 --- a/desktop-widgets/printdialog.cpp +++ b/desktop-widgets/printdialog.cpp @@ -19,8 +19,9 @@ template_options::color_palette_struct ssrf_colors, almond_colors, blueshades_colors, custom_colors; -PrintDialog::PrintDialog(QWidget *parent) : +PrintDialog::PrintDialog(bool inPlanner, QWidget *parent) : QDialog(parent, QFlag(0)), + inPlanner(inPlanner), printer(NULL), qprinter(NULL) { @@ -174,10 +175,10 @@ void PrintDialog::createPrinterObj() { // create a new printer object if (!printer) { - qprinter = new QPrinter(); + qprinter = new QPrinter; qprinter->setResolution(printOptions.resolution); qprinter->setOrientation((QPrinter::Orientation)printOptions.landscape); - printer = new Printer(qprinter, printOptions, templateOptions, Printer::PRINT); + printer = new Printer(qprinter, printOptions, templateOptions, Printer::PRINT, inPlanner); } } diff --git a/desktop-widgets/printdialog.h b/desktop-widgets/printdialog.h index 6e34ca7cb..7e98f22f6 100644 --- a/desktop-widgets/printdialog.h +++ b/desktop-widgets/printdialog.h @@ -18,10 +18,11 @@ class PrintDialog : public QDialog { Q_OBJECT public: - explicit PrintDialog(QWidget *parent = 0); + explicit PrintDialog(bool inPlanner, QWidget *parent = 0); ~PrintDialog(); private: + bool inPlanner; PrintOptions *optionsWidget; QProgressBar *progressBar; Printer *printer; diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index b3af96a75..ff5a65b93 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -14,12 +14,13 @@ #include <QWebElement> #include "profile-widget/profilewidget2.h" -Printer::Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode) : +Printer::Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode, bool inPlanner) : paintDevice(paintDevice), webView(new QWebView), printOptions(printOptions), templateOptions(templateOptions), printMode(printMode), + inPlanner(inPlanner), done(0), dpi(0) { @@ -205,7 +206,7 @@ QString Printer::exportHtml() QString html; if (printOptions.type == print_options::DIVELIST) - html = t.generate(); + html = t.generate(inPlanner); else if (printOptions.type == print_options::STATISTICS ) html = t.generateStatistics(); @@ -235,7 +236,7 @@ void Printer::print() // export border width with at least 1 pixel // templateOptions.borderwidth = std::max(1, pageSize.width() / 1000); if (printOptions.type == print_options::DIVELIST) - webView->setHtml(t.generate()); + webView->setHtml(t.generate(inPlanner)); else if (printOptions.type == print_options::STATISTICS ) webView->setHtml(t.generateStatistics()); if (printOptions.color_selected && printerPtr->colorMode()) @@ -269,7 +270,7 @@ void Printer::previewOnePage() // initialize the border settings // templateOptions.border_width = std::max(1, pageSize.width() / 1000); if (printOptions.type == print_options::DIVELIST) - webView->setHtml(t.generate()); + webView->setHtml(t.generate(inPlanner)); else if (printOptions.type == print_options::STATISTICS ) webView->setHtml(t.generateStatistics()); bool ok; diff --git a/desktop-widgets/printer.h b/desktop-widgets/printer.h index 8030e9f75..43a1fa9b7 100644 --- a/desktop-widgets/printer.h +++ b/desktop-widgets/printer.h @@ -27,6 +27,7 @@ private: const template_options &templateOptions; QSize pageSize; PrintMode printMode; + bool inPlanner; int done; int dpi; void render(int Pages); @@ -38,7 +39,7 @@ private slots: void templateProgessUpdated(int value); public: - Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode); + Printer(QPaintDevice *paintDevice, const print_options &printOptions, const template_options &templateOptions, PrintMode printMode, bool inPlanner); ~Printer(); void print(); void previewOnePage(); diff --git a/desktop-widgets/templateedit.cpp b/desktop-widgets/templateedit.cpp index e7d81f8d9..db8a92007 100644 --- a/desktop-widgets/templateedit.cpp +++ b/desktop-widgets/templateedit.cpp @@ -59,7 +59,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, false); printer.previewOnePage(); ui->label->setPixmap(map.scaled(width, height, Qt::IgnoreAspectRatio)); diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index ca7e6218a..ec895687b 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -95,13 +95,13 @@ TemplateLayout::TemplateLayout(const print_options &printOptions, const template { } -QString TemplateLayout::generate() +QString TemplateLayout::generate(bool in_planner) { QString htmlContent; State state; - if (in_planner()) { + if (in_planner) { state.dives.append(&displayed_dive); } else { int i; diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h index 3b5c3b9b5..c25c9d4ea 100644 --- a/desktop-widgets/templatelayout.h +++ b/desktop-widgets/templatelayout.h @@ -27,7 +27,7 @@ class TemplateLayout : public QObject { Q_OBJECT public: TemplateLayout(const print_options &printOptions, const template_options &templateOptions); - QString generate(); + QString generate(bool in_planner); QString generateStatistics(); static QString readTemplate(QString template_name); static void writeTemplate(QString template_name, QString grantlee_template); |