mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
6ef4f377f0
commit
622e9ba373
3 changed files with 21 additions and 36 deletions
|
@ -15,16 +15,6 @@
|
|||
|
||||
QList<QString> grantlee_templates, grantlee_statistics_templates;
|
||||
|
||||
int getTotalWork(const print_options &printOptions)
|
||||
{
|
||||
if (printOptions.print_selected) {
|
||||
// return the correct number depending on all/selected dives
|
||||
// but don't return 0 as we might divide by this number
|
||||
return amount_selected && !in_planner() ? amount_selected : 1;
|
||||
}
|
||||
return dive_table.nr;
|
||||
}
|
||||
|
||||
void find_all_templates()
|
||||
{
|
||||
const QLatin1String ext(".html");
|
||||
|
@ -101,36 +91,31 @@ void copy_bundled_templates(QString src, QString dst, QStringList *templateBacku
|
|||
}
|
||||
|
||||
TemplateLayout::TemplateLayout(const print_options &printOptions, const template_options &templateOptions) :
|
||||
printOptions(printOptions), templateOptions(templateOptions)
|
||||
numDives(0), printOptions(printOptions), templateOptions(templateOptions)
|
||||
{
|
||||
}
|
||||
|
||||
QString TemplateLayout::generate()
|
||||
{
|
||||
int progress = 0;
|
||||
int totalWork = getTotalWork(printOptions);
|
||||
|
||||
QString htmlContent;
|
||||
|
||||
State state;
|
||||
|
||||
struct dive *dive;
|
||||
if (in_planner()) {
|
||||
state.dives.append(&displayed_dive);
|
||||
emit progressUpdated(100.0);
|
||||
} else {
|
||||
int i;
|
||||
struct dive *dive;
|
||||
for_each_dive (i, dive) {
|
||||
//TODO check for exporting selected dives only
|
||||
if (!dive->selected && printOptions.print_selected)
|
||||
continue;
|
||||
state.dives.append(dive);
|
||||
progress++;
|
||||
emit progressUpdated(lrint(progress * 100.0 / totalWork));
|
||||
}
|
||||
}
|
||||
|
||||
QString templateContents = readTemplate(printOptions.p_template);
|
||||
numDives = state.dives.size();
|
||||
|
||||
QList<token> tokens = lexer(templateContents);
|
||||
QString buffer;
|
||||
|
@ -290,7 +275,7 @@ static QRegularExpression ifstatement(R"(forloop\.counter\|\s*divisibleby\:\s*(\
|
|||
|
||||
template<typename V, typename T>
|
||||
void TemplateLayout::parser_for(QList<token> tokenList, int from, int to, QTextStream &out, State &state,
|
||||
const V &data, const T *&act)
|
||||
const V &data, const T *&act, bool emitProgress)
|
||||
{
|
||||
const T *old = act;
|
||||
int i = 1; // Loop iterators start at one
|
||||
|
@ -299,7 +284,11 @@ void TemplateLayout::parser_for(QList<token> tokenList, int from, int to, QTextS
|
|||
act = &item;
|
||||
state.forloopiterator = i++;
|
||||
parser(tokenList, from, to, out, state);
|
||||
if (emitProgress)
|
||||
emit progressUpdated(state.forloopiterator * 100 / data.size());
|
||||
}
|
||||
if (data.empty())
|
||||
emit progressUpdated(100);
|
||||
act = old;
|
||||
state.forloopiterator = olditerator;
|
||||
}
|
||||
|
@ -357,17 +346,17 @@ void TemplateLayout::parser(QList<token> tokenList, int from, int to, QTextStrea
|
|||
break;
|
||||
}
|
||||
if (listname == "years") {
|
||||
parser_for(tokenList, pos, loop_end, capture, state, state.years, state.currentYear);
|
||||
parser_for(tokenList, pos, loop_end, capture, state, state.years, state.currentYear, true);
|
||||
} else if (listname == "dives") {
|
||||
parser_for(tokenList, pos, loop_end, capture, state, state.dives, state.currentDive);
|
||||
parser_for(tokenList, pos, loop_end, capture, state, state.dives, state.currentDive, true);
|
||||
} else if (listname == "cylinders") {
|
||||
if (state.currentDive)
|
||||
parser_for(tokenList, pos, loop_end, capture, state, formatCylinders(*state.currentDive), state.currentCylinder);
|
||||
parser_for(tokenList, pos, loop_end, capture, state, formatCylinders(*state.currentDive), state.currentCylinder, false);
|
||||
else
|
||||
qWarning("cylinders loop outside of dive");
|
||||
} else if (listname == "cylinderObjects") {
|
||||
if (state.currentDive)
|
||||
parser_for(tokenList, pos, loop_end, capture, state, cylinderList(*state.currentDive), state.currentCylinderObject);
|
||||
parser_for(tokenList, pos, loop_end, capture, state, cylinderList(*state.currentDive), state.currentCylinderObject, false);
|
||||
else
|
||||
qWarning("cylinderObjects loop outside of dive");
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue