mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 (<br>) 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 <neolit123@gmail.com>
This commit is contained in:
parent
2bfda14c0b
commit
b722bf6931
1 changed files with 23 additions and 4 deletions
|
@ -119,9 +119,11 @@ void PrintLayout::printTable() const
|
||||||
"</style>"
|
"</style>"
|
||||||
);
|
);
|
||||||
// setDefaultStyleSheet() doesn't work here?
|
// setDefaultStyleSheet() doesn't work here?
|
||||||
|
const QString heading(insertTableHeadingRow());
|
||||||
|
const QString lineBreak("<br>");
|
||||||
QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>";
|
QString htmlText = styleSheet + "<table cellspacing='0' width='100%'>";
|
||||||
QString htmlTextPrev;
|
QString htmlTextPrev;
|
||||||
int pageCountNew = 1, pageCount;
|
int pageCountNew = 1, pageCount = 0, lastPageWithHeading = 0;
|
||||||
bool insertHeading = true;
|
bool insertHeading = true;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
@ -130,16 +132,33 @@ void PrintLayout::printTable() const
|
||||||
if (!dive->selected && printOptions->print_selected)
|
if (!dive->selected && printOptions->print_selected)
|
||||||
continue;
|
continue;
|
||||||
if (insertHeading) {
|
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;
|
insertHeading = false;
|
||||||
|
lastPageWithHeading = pageCount;
|
||||||
}
|
}
|
||||||
htmlTextPrev = htmlText;
|
htmlTextPrev = htmlText;
|
||||||
htmlText += insertTableDataRow(dive);
|
htmlText += insertTableDataRow(dive);
|
||||||
doc.setHtml(htmlText);
|
doc.setHtml(htmlText);
|
||||||
pageCount = pageCountNew;
|
pageCount = pageCountNew;
|
||||||
pageCountNew = doc.pageCount();
|
pageCountNew = doc.pageCount();
|
||||||
/* if the page count increases after adding this row we 'revert'
|
// if the page count increases revert and add heading instead
|
||||||
* and add a heading instead. */
|
|
||||||
if (pageCountNew > pageCount) {
|
if (pageCountNew > pageCount) {
|
||||||
htmlText = htmlTextPrev;
|
htmlText = htmlTextPrev;
|
||||||
insertHeading = true;
|
insertHeading = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue