From 815072d2ae29811271af197e2330cc331d58f9c6 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sat, 4 Jul 2015 23:54:15 +0200 Subject: [PATCH] Printing: retrieve number of dives per page from the template file Add special data attribute 'data-numberofdives' in the template with the number of dives per page. This is standard HTML5 specification so it won't corrupt the template file. Any template that will be used for printing must contain this attribute to assure correct output. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- printer.cpp | 14 +++++++------- printing_templates/one_dive.html | 2 +- printing_templates/two_dives.html | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/printer.cpp b/printer.cpp index 83cc42d18..f8a90f96d 100644 --- a/printer.cpp +++ b/printer.cpp @@ -34,13 +34,13 @@ void Printer::render() } else { printer->setColorMode(QPrinter::GrayScale); } - switch (printOptions->p_template) { - case print_options::ONE_DIVE: - divesPerPage = 1; - break; - case print_options::TWO_DIVE: - divesPerPage = 2; - break; + + // get number of dives per page from data-numberofdives attribute in the body of the selected template + bool ok; + divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); + if (!ok) { + divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed + //TODO: show warning } int Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage); diff --git a/printing_templates/one_dive.html b/printing_templates/one_dive.html index 87b2976e0..d7ae8d477 100644 --- a/printing_templates/one_dive.html +++ b/printing_templates/one_dive.html @@ -92,7 +92,7 @@ } - + {% block main_rows %} {% for dive in dives %}
diff --git a/printing_templates/two_dives.html b/printing_templates/two_dives.html index b0ad9ba15..62502272b 100644 --- a/printing_templates/two_dives.html +++ b/printing_templates/two_dives.html @@ -102,7 +102,7 @@ } - + {% block main_rows %} {% for dive in dives %}