Changeset 5506fa4 in subsurface


Ignore:
Timestamp:
Dec 6, 2013, 9:23:02 AM (4 years ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
Mtest, android_test, dcDownload, foratdotde, gitMerge, gitdebug, gitpictures, ios, master, mergeKirigamiPort, pictimeshift, resolutionIndependence, spinner, testTomaz, testing, v4.0-branch, v4.0.3-branch, v4.2-branch, v4.4-branch, v4.5-branch
Children:
8f58faf
Parents:
c7a4bb1
git-author:
Lubomir I. Ivanov <neolit123@…> (12/06/13 08:24:28)
git-committer:
Dirk Hohndel <dirk@…> (12/06/13 09:23:02)
Message:

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@…>
Signed-off-by: Dirk Hohndel <dirk@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • qt-ui/printlayout.cpp

    r94f85bb r5506fa4  
    274274{
    275275        struct dive *dive;
    276         const int stage = 33; // there are 3 stages in this routine: 100% / 3 ~= 33%
     276        int done = 0; // percents done
    277277        int i, row = 0, progress, total = estimateTotalDives();
    278278        if (!total)
     
    309309                row++;
    310310                progress++;
    311                 emit signalProgress((progress * stage) / total);
    312         }
     311                emit signalProgress((progress * 10) / total);
     312        }
     313        done = 10;
    313314        table.setModel(&model); // set model to table
    314315        // resize columns to percentages from page width
     
    329330        QList<unsigned int> pageIndexes;
    330331        pageIndexes.append(0);
    331         int tableHeight = 0, rowH = 0, accH = 0, headings = 0;
    332 
    333         // process all rows
    334         progress = 0;
    335         total = model.rows;
    336         for (int i = 0; i < total; i++) {
    337                 rowH = table.rowHeight(i);
    338                 accH += rowH;
    339                 if (accH > scaledPageH) { // push a new page index and add a heading
    340                         pageIndexes.append(pageIndexes.last() + (accH - rowH));
    341                         addTablePrintHeadingRow(&model, i);
    342                         headings += rowH; // last row was moved to a new page; compensate!
    343                         accH = 0;
    344                         i--;
     332
     333        /* the algorithm bellow processes the table rows in multiple passes,
     334         * compensating for loss of space due to moving rows on a new page instead
     335         * of truncating them.
     336         * there is a 'passes' array defining how much percents of the total
     337         * progress each will take. given, the first and last stage of this function
     338         * use 10% each, then the sum of passes[] here should be 80%.
     339         * two should be enough! */
     340        const int passes[] = { 70, 10 };
     341        int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings;
     342        bool isHeading = false;
     343
     344        for (int pass = 0; pass < sizeof(passes); pass++) {
     345                progress = headings = accH = 0;
     346                total = model.rows - lastAccIndex;
     347                for (int i = lastAccIndex; i < model.rows; i++) {
     348                        rowH = table.rowHeight(i);
     349                        accH += rowH;
     350                        if (isHeading) {
     351                                headings += rowH;
     352                                isHeading = false;
     353                        }
     354                        if (accH > scaledPageH) {
     355                                lastAccIndex = i;
     356                                pageIndexes.append(pageIndexes.last() + (accH - rowH));
     357                                addTablePrintHeadingRow(&model, i);
     358                                isHeading = true;
     359                                accH = 0;
     360                                i--;
     361                        }
     362                        tableHeight += table.rowHeight(i);
     363                        progress++;
     364                        emit signalProgress(done + (progress * passes[pass]) / total);
    345365                }
    346                 tableHeight += rowH;
    347                 progress++;
    348                 emit signalProgress(stage + (progress * stage) / total);
    349         }
     366                done += passes[pass];
     367        }
     368        done = 90;
    350369        pageIndexes.append(pageIndexes.last() + accH + headings);
    351         // resize the whole widget so that it can be rendered
    352370        table.resize(scaledPageW, tableHeight);
    353371
     
    367385                table.render(&painter, QPoint(0, 0), region);
    368386                progress++;
    369                 emit signalProgress((stage << 1) + (progress * (stage + 1)) / total);
     387                emit signalProgress(done + (progress * 10) / total);
    370388        }
    371389}
Note: See TracChangeset for help on using the changeset viewer.