diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-12-12 15:08:56 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-12-17 13:03:56 -0800 |
commit | f42a70586be15fcbb0f82260bd6774572cd375d2 (patch) | |
tree | 3a57548ff27a3eb7820b1192efb0ec62aa088ae5 /desktop-widgets/templatelayout.h | |
parent | 0cbb4487401b749476e939db20b842e04099bfa8 (diff) | |
download | subsurface-f42a70586be15fcbb0f82260bd6774572cd375d2.tar.gz |
printing: remove objects QVariant map
An artifact from the old grantlee code: the whole parser state
was kept in an untyped QVariant map. One case was particularly
bizarre: the options were a class member and yet added to the
weird map.
Replace this by a strongly typed state structure. Ultimately,
this will allow us to replace the "dive object helper".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/templatelayout.h')
-rw-r--r-- | desktop-widgets/templatelayout.h | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h index b59679285..0ed1951b4 100644 --- a/desktop-widgets/templatelayout.h +++ b/desktop-widgets/templatelayout.h @@ -24,6 +24,10 @@ struct token { extern QList<QString> grantlee_templates, grantlee_statistics_templates; +struct YearInfo { + stats_t *year; +}; + class TemplateLayout : public QObject { Q_OBJECT public: @@ -34,23 +38,27 @@ public: static void writeTemplate(QString template_name, QString grantlee_template); private: + struct State { + QList<DiveObjectHelperGrantlee> dives; + QList<YearInfo> years; + QMap<QString, QString> types; + int forloopiterator = -1; + const DiveObjectHelperGrantlee *currentDive = nullptr; + const YearInfo *currentYear = nullptr; + const QString *currentCylinder = nullptr; + const CylinderObjectHelper *currentCylinderObject = nullptr; + }; const print_options &printOptions; const template_options &templateOptions; QList<token> lexer(QString input); - void parser(QList<token> tokenList, int &pos, QTextStream &out, QHash<QString, QVariant> options); - QVariant getValue(QString list, QString property, QVariant option); - QString translate(QString s, QHash<QString, QVariant> options); + void parser(QList<token> tokenList, int &pos, QTextStream &out, State &state); + template<typename V, typename T> + void parser_for(QList<token> tokenList, int &pos, 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); }; -struct YearInfo { - stats_t *year; -}; - -Q_DECLARE_METATYPE(template_options) -Q_DECLARE_METATYPE(print_options) -Q_DECLARE_METATYPE(YearInfo) - #endif |