summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-12-06 18:24:28 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-12-06 09:23:02 -0800
commit5506fa4b38a5914e8149b3fd9283d9060df395bb (patch)
treed9a10d95d076c38afdfd3af43c8de7afd92209e7
parentc7a4bb185c33f2dfa9e2a54d97b27c9cee518e10 (diff)
downloadsubsurface-5506fa4b38a5914e8149b3fd9283d9060df395bb.tar.gz
Print: fix issues when printing a lot of dives in table print
This patch improves the algorithm when estimating where to put the new page header in the table and how we move larger dive rows on a new page. It now performs a couple of 'passes', where the first one processes the table and the second one is used to compensate for the lost space. Fixes #326 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/printlayout.cpp58
1 files changed, 38 insertions, 20 deletions
diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp
index 004188ca1..199c18b01 100644
--- a/qt-ui/printlayout.cpp
+++ b/qt-ui/printlayout.cpp
@@ -273,7 +273,7 @@ QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int
void PrintLayout::printTable()
{
struct dive *dive;
- const int stage = 33; // there are 3 stages in this routine: 100% / 3 ~= 33%
+ int done = 0; // percents done
int i, row = 0, progress, total = estimateTotalDives();
if (!total)
return;
@@ -308,8 +308,9 @@ void PrintLayout::printTable()
addTablePrintDataRow(&model, row, dive);
row++;
progress++;
- emit signalProgress((progress * stage) / total);
+ emit signalProgress((progress * 10) / total);
}
+ done = 10;
table.setModel(&model); // set model to table
// resize columns to percentages from page width
int accW = 0;
@@ -328,27 +329,44 @@ void PrintLayout::printTable()
// a list of vertical offsets where pages begin and some helpers
QList<unsigned int> pageIndexes;
pageIndexes.append(0);
- int tableHeight = 0, rowH = 0, accH = 0, headings = 0;
- // process all rows
- progress = 0;
- total = model.rows;
- for (int i = 0; i < total; i++) {
- rowH = table.rowHeight(i);
- accH += rowH;
- if (accH > scaledPageH) { // push a new page index and add a heading
- pageIndexes.append(pageIndexes.last() + (accH - rowH));
- addTablePrintHeadingRow(&model, i);
- headings += rowH; // last row was moved to a new page; compensate!
- accH = 0;
- i--;
+ /* the algorithm bellow processes the table rows in multiple passes,
+ * compensating for loss of space due to moving rows on a new page instead
+ * of truncating them.
+ * there is a 'passes' array defining how much percents of the total
+ * progress each will take. given, the first and last stage of this function
+ * use 10% each, then the sum of passes[] here should be 80%.
+ * two should be enough! */
+ const int passes[] = { 70, 10 };
+ int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings;
+ bool isHeading = false;
+
+ for (int pass = 0; pass < sizeof(passes); pass++) {
+ progress = headings = accH = 0;
+ total = model.rows - lastAccIndex;
+ for (int i = lastAccIndex; i < model.rows; i++) {
+ rowH = table.rowHeight(i);
+ accH += rowH;
+ if (isHeading) {
+ headings += rowH;
+ isHeading = false;
+ }
+ if (accH > scaledPageH) {
+ lastAccIndex = i;
+ pageIndexes.append(pageIndexes.last() + (accH - rowH));
+ addTablePrintHeadingRow(&model, i);
+ isHeading = true;
+ accH = 0;
+ i--;
+ }
+ tableHeight += table.rowHeight(i);
+ progress++;
+ emit signalProgress(done + (progress * passes[pass]) / total);
}
- tableHeight += rowH;
- progress++;
- emit signalProgress(stage + (progress * stage) / total);
+ done += passes[pass];
}
+ done = 90;
pageIndexes.append(pageIndexes.last() + accH + headings);
- // resize the whole widget so that it can be rendered
table.resize(scaledPageW, tableHeight);
// attach a painter and render pages by using pageIndexes
@@ -366,7 +384,7 @@ void PrintLayout::printTable()
pageIndexes.at(i + 1) - pageIndexes.at(i) + 1);
table.render(&painter, QPoint(0, 0), region);
progress++;
- emit signalProgress((stage << 1) + (progress * (stage + 1)) / total);
+ emit signalProgress(done + (progress * 10) / total);
}
}