subsurface/desktop-widgets/templatelayout.h
Berthold Stoeger 622e9ba373 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>
2021-02-13 12:20:25 -08:00

60 lines
1.9 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef TEMPLATELAYOUT_H
#define TEMPLATELAYOUT_H
#include "core/statistics.h"
#include "core/equipment.h"
#include <QStringList>
struct print_options;
struct template_options;
class QTextStream;
void find_all_templates();
void set_bundled_templates_as_read_only();
void copy_bundled_templates(QString src, QString dst, QStringList *templateBackupList);
enum token_t {LITERAL, FORSTART, FORSTOP, BLOCKSTART, BLOCKSTOP, IFSTART, IFSTOP, PARSERERROR};
struct token {
enum token_t type;
QString contents;
};
extern QList<QString> grantlee_templates, grantlee_statistics_templates;
class TemplateLayout : public QObject {
Q_OBJECT
public:
TemplateLayout(const print_options &printOptions, const template_options &templateOptions);
QString generate();
QString generateStatistics();
static QString readTemplate(QString template_name);
static void writeTemplate(QString template_name, QString grantlee_template);
int numDives; // valid after a call to generate()
private:
struct State {
QList<const dive *> dives;
QList<stats_t *> years;
QMap<QString, QString> types;
int forloopiterator = -1;
const dive * const *currentDive = nullptr;
const stats_t * const *currentYear = nullptr;
const QString *currentCylinder = nullptr;
const cylinder_t * const *currentCylinderObject = nullptr;
};
const print_options &printOptions;
const template_options &templateOptions;
QList<token> lexer(QString input);
void parser(QList<token> tokenList, int from, int to, QTextStream &out, State &state);
template<typename V, typename T>
void parser_for(QList<token> tokenList, int from, int to, QTextStream &out, State &state, const V &data, const T *&act, bool emitProgress);
QVariant getValue(QString list, QString property, const State &state);
QString translate(QString s, State &state);
signals:
void progressUpdated(int value);
};
#endif