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>
This commit is contained in:
Berthold Stoeger 2021-02-13 22:43:55 +01:00 committed by Dirk Hohndel
parent 18049bc8d0
commit 42cff9b3a5
10 changed files with 20 additions and 20 deletions

View file

@ -1484,11 +1484,6 @@ extern "C" void parse_display_units(char *line)
qDebug() << line;
}
extern "C" bool in_planner()
{
return getAppState() == ApplicationState::PlanDive || getAppState() == ApplicationState::EditPlannedDive;
}
extern "C" enum deco_mode decoMode(bool in_planner)
{
return in_planner ? prefs.planner_deco_mode : prefs.display_deco_mode;

View file

@ -137,7 +137,6 @@ extern "C" {
#endif
char *printGPSCoordsC(const location_t *loc);
bool in_planner();
bool getProxyString(char **buffer);
bool canReachCloudServer();
void updateWindowTitle();

View file

@ -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

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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));

View file

@ -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;

View file

@ -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);