2017-04-27 20:26:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-04-21 17:23:13 +02:00
|
|
|
#ifndef TEMPLATELAYOUT_H
|
|
|
|
#define TEMPLATELAYOUT_H
|
|
|
|
|
2016-04-05 09:40:03 -07:00
|
|
|
#include "core/statistics.h"
|
2020-12-14 23:21:58 +01:00
|
|
|
#include "core/equipment.h"
|
2020-12-13 13:32:40 +01:00
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
struct print_options;
|
|
|
|
struct template_options;
|
|
|
|
class QTextStream;
|
2015-04-21 17:23:13 +02:00
|
|
|
|
2015-07-24 09:26:25 +02:00
|
|
|
void find_all_templates();
|
2017-11-23 01:59:26 +02:00
|
|
|
void set_bundled_templates_as_read_only();
|
2017-11-24 22:54:54 +02:00
|
|
|
void copy_bundled_templates(QString src, QString dst, QStringList *templateBackupList);
|
2015-07-24 09:26:25 +02:00
|
|
|
|
2020-08-21 13:24:10 +02:00
|
|
|
enum token_t {LITERAL, FORSTART, FORSTOP, BLOCKSTART, BLOCKSTOP, IFSTART, IFSTOP, PARSERERROR};
|
|
|
|
|
|
|
|
struct token {
|
|
|
|
enum token_t type;
|
|
|
|
QString contents;
|
|
|
|
};
|
|
|
|
|
2015-08-21 19:03:42 +02:00
|
|
|
extern QList<QString> grantlee_templates, grantlee_statistics_templates;
|
2015-06-10 13:39:15 +02:00
|
|
|
|
2015-04-21 17:23:13 +02:00
|
|
|
class TemplateLayout : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-12-12 13:28:36 +01:00
|
|
|
TemplateLayout(const print_options &printOptions, const template_options &templateOptions);
|
2021-02-13 22:43:55 +01:00
|
|
|
QString generate(bool in_planner);
|
2015-08-21 19:03:42 +02:00
|
|
|
QString generateStatistics();
|
2015-07-05 06:21:39 +02:00
|
|
|
static QString readTemplate(QString template_name);
|
|
|
|
static void writeTemplate(QString template_name, QString grantlee_template);
|
2021-02-13 18:58:14 +01:00
|
|
|
int numDives; // valid after a call to generate()
|
2015-04-21 17:23:13 +02:00
|
|
|
|
|
|
|
private:
|
2020-12-12 15:08:56 +01:00
|
|
|
struct State {
|
2020-12-14 23:21:58 +01:00
|
|
|
QList<const dive *> dives;
|
2020-12-13 13:05:30 +01:00
|
|
|
QList<stats_t *> years;
|
2020-12-12 15:08:56 +01:00
|
|
|
QMap<QString, QString> types;
|
|
|
|
int forloopiterator = -1;
|
2020-12-14 23:21:58 +01:00
|
|
|
const dive * const *currentDive = nullptr;
|
2020-12-13 13:05:30 +01:00
|
|
|
const stats_t * const *currentYear = nullptr;
|
2020-12-12 15:08:56 +01:00
|
|
|
const QString *currentCylinder = nullptr;
|
2020-12-14 23:21:58 +01:00
|
|
|
const cylinder_t * const *currentCylinderObject = nullptr;
|
2020-12-12 15:08:56 +01:00
|
|
|
};
|
2020-12-12 13:28:36 +01:00
|
|
|
const print_options &printOptions;
|
|
|
|
const template_options &templateOptions;
|
2020-08-21 13:24:10 +02:00
|
|
|
QList<token> lexer(QString input);
|
2020-12-12 17:20:00 +01:00
|
|
|
void parser(QList<token> tokenList, int from, int to, QTextStream &out, State &state);
|
2020-12-12 15:08:56 +01:00
|
|
|
template<typename V, typename T>
|
2021-02-13 18:58:14 +01:00
|
|
|
void parser_for(QList<token> tokenList, int from, int to, QTextStream &out, State &state, const V &data, const T *&act, bool emitProgress);
|
2020-12-12 15:08:56 +01:00
|
|
|
QVariant getValue(QString list, QString property, const State &state);
|
|
|
|
QString translate(QString s, State &state);
|
2020-08-21 13:24:10 +02:00
|
|
|
|
2015-05-30 15:32:15 +02:00
|
|
|
signals:
|
|
|
|
void progressUpdated(int value);
|
2015-04-21 17:23:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|