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
|
|
|
|
|
2017-11-24 20:54:54 +00:00
|
|
|
#include <QStringList>
|
2015-04-21 15:23:13 +00:00
|
|
|
#include "mainwindow.h"
|
2015-06-14 04:25:35 +00:00
|
|
|
#include "printoptions.h"
|
2016-04-05 16:40:03 +00:00
|
|
|
#include "core/statistics.h"
|
|
|
|
#include "core/qthelper.h"
|
2020-02-03 18:33:06 +00:00
|
|
|
#include "core/subsurface-qt/diveobjecthelper.h"
|
|
|
|
#include "core/subsurface-qt/cylinderobjecthelper.h" // TODO: remove once grantlee supports Q_GADGET objects
|
2015-04-21 15:23:13 +00:00
|
|
|
|
2020-12-12 12:28:36 +00:00
|
|
|
int getTotalWork(const print_options &printOptions);
|
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);
|
2015-04-21 15:23:13 +00:00
|
|
|
QString generate();
|
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);
|
2015-04-21 15:23:13 +00:00
|
|
|
|
|
|
|
private:
|
2020-12-12 14:08:56 +00:00
|
|
|
struct State {
|
|
|
|
QList<DiveObjectHelperGrantlee> 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;
|
|
|
|
const DiveObjectHelperGrantlee *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;
|
|
|
|
const CylinderObjectHelper *currentCylinderObject = nullptr;
|
|
|
|
};
|
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>
|
2020-12-12 16:20:00 +00:00
|
|
|
void parser_for(QList<token> tokenList, int from, int to, QTextStream &out, State &state, const V &data, const T *&act);
|
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
|