From 622e9ba373f898a0d51fc009f3615d83ffd3a7fc Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 13 Feb 2021 18:58:14 +0100 Subject: printing: "fix" progress indicator In TemplateLayout, there was a progress indication, which reported the progress - not of the actual rendering - but of adding the dives to the "to render" list. Which is of course done in less than a ms, making the whole thing completely pointless. Instead, emit progress when actually looping over the dives or statistics. Nobody ever noticed the problem because even rendering is done in fractions of a second and indeed is accounted to only one fifth of the total progress. The real purpose of this "fix" is to get rid of the getTotalWork() function, which was just insane. Instead of asking the TemplateLayout how many dives it rendered, this number was extracted from global state. Simply store the number of dives in the TemplateLayout object instead. Moreover, fix two coding style issues: - "Page" variable identifier starting with a capital - The Printer::render() being defined (as opposed to declared) with a default parameter. This is not how C++'s default parameters work, sorry. Signed-off-by: Berthold Stoeger --- desktop-widgets/printer.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'desktop-widgets/printer.cpp') diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index f38b661c5..b3af96a75 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -122,7 +122,7 @@ void Printer::flowRender() painter.end(); } -void Printer::render(int Pages = 0) +void Printer::render(int pages) { // keep original preferences ProfileWidget2 *profile = MainWindow::instance()->graphics; @@ -155,7 +155,7 @@ void Printer::render(int Pages = 0) profile->setFontPrintScale(printFontScale); int elemNo = 0; - for (int i = 0; i < Pages; i++) { + for (int i = 0; i < pages; i++) { // render the base Html template webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer); @@ -173,8 +173,8 @@ void Printer::render(int Pages = 0) viewPort.adjust(0, pageSize.height(), 0, pageSize.height()); // rendering progress is 4/5 of total work - emit(progessUpdated(lrint((i * 80.0 / Pages) + done))); - if (i < Pages - 1 && printMode == Printer::PRINT) + emit(progessUpdated(lrint((i * 80.0 / pages) + done))); + if (i < pages - 1 && printMode == Printer::PRINT) static_cast(paintDevice)->newPage(); } painter.end(); @@ -220,7 +220,6 @@ void Printer::print() return; } - QPrinter *printerPtr; printerPtr = static_cast(paintDevice); @@ -253,13 +252,10 @@ void Printer::print() divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed //TODO: show warning } - int Pages; - if (divesPerPage == 0) { + if (divesPerPage == 0) flowRender(); - } else { - Pages = qCeil(getTotalWork(printOptions) / (float)divesPerPage); - render(Pages); - } + else + render((t.numDives - 1) / divesPerPage + 1); } void Printer::previewOnePage() -- cgit v1.2.3-70-g09d2