From b722bf6931da3162b8c5c2608f477d9e9c4b5148 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Fri, 12 Jul 2013 14:08:25 +0300 Subject: Print: improve new page detection in table print There is a potential issue when placing a heading on a new page. If the height of a data row is larger of that of a heading, a new heading can end up at the bottom of a page leaving that page with two headings. To solve that we add line breaks (
) until the new page is reached and add the heading there. Algorithm assumes that the height of a heading is larger than a line break. Also it is now obviously even slower. Signed-off-by: Lubomir I. Ivanov --- qt-ui/printlayout.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp index f0cbacaa9..471b8f847 100644 --- a/qt-ui/printlayout.cpp +++ b/qt-ui/printlayout.cpp @@ -119,9 +119,11 @@ void PrintLayout::printTable() const "" ); // setDefaultStyleSheet() doesn't work here? + const QString heading(insertTableHeadingRow()); + const QString lineBreak("
"); QString htmlText = styleSheet + ""; QString htmlTextPrev; - int pageCountNew = 1, pageCount; + int pageCountNew = 1, pageCount = 0, lastPageWithHeading = 0; bool insertHeading = true; int i; @@ -130,16 +132,33 @@ void PrintLayout::printTable() const if (!dive->selected && printOptions->print_selected) continue; if (insertHeading) { - htmlText += insertTableHeadingRow(); + htmlTextPrev = htmlText; + htmlText += heading; + doc.setHtml(htmlText); + pageCount = doc.pageCount(); + // prevent adding two headings on the same page + if (pageCount == lastPageWithHeading) { + htmlText = htmlTextPrev; + // add line breaks until a new page is reached + while (pageCount == lastPageWithHeading) { + htmlTextPrev = htmlText; + htmlText += lineBreak; + doc.setHtml(htmlText); + pageCount = doc.pageCount(); + } + // revert last line break from the new page and add heading + htmlText = htmlTextPrev; + htmlText += heading; + } insertHeading = false; + lastPageWithHeading = pageCount; } htmlTextPrev = htmlText; htmlText += insertTableDataRow(dive); doc.setHtml(htmlText); pageCount = pageCountNew; pageCountNew = doc.pageCount(); - /* if the page count increases after adding this row we 'revert' - * and add a heading instead. */ + // if the page count increases revert and add heading instead if (pageCountNew > pageCount) { htmlText = htmlTextPrev; insertHeading = true; -- cgit v1.2.3-70-g09d2