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