subsurface/desktop-widgets/templatelayout.h
Berthold Stoeger d9942269a9 printing: remove DiveObjectHelperGrantlee
This was a weird helper object, needed for grantlee. Instead
of storing this object, loop over cylinders and dives directly.

The actual accessor function is unchanged and now generates
a DiveObjectHelper or DiveCylinderHelper for every variable
access. Obviously, this is very inefficient. However, this
will be replaced in future commits by direct calls to formatting
functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-12-17 13:03:56 -08:00

61 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>
class CylinderObjectHelper;
struct print_options;
struct template_options;
class QTextStream;
int getTotalWork(const print_options &printOptions);
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);
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);
QVariant getValue(QString list, QString property, const State &state);
QString translate(QString s, State &state);
signals:
void progressUpdated(int value);
};
#endif