From 7c1c22637e95910db9f45154e999fe732c2571c4 Mon Sep 17 00:00:00 2001 From: berrux_dev Date: Fri, 13 Nov 2026 23:49:40 +0100 Subject: [PATCH] Restore the full include/grantlee stub tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit include/grantlee/context.h (the only grantlee header referenced by kept code) includes its sibling stubs (abstractlocalizer.h, ...); the file-level include/ prune left those siblings behind, breaking codegen_grantlee compilation (fatal error: abstractlocalizer.h). The grantlee engine stubs are a self-contained header set — keep the whole dir, same treatment as include/GeographicLib. --- .../include/grantlee/abstractlocalizer.h | 163 +++++++ .../include/grantlee/abstractmarkupbuilder.h | 273 +++++++++++ .../include/grantlee/bbcodebuilder.h | 113 +++++ .../include/grantlee/cachingloaderdecorator.h | 112 +++++ .../include/grantlee/engine.h | 259 +++++++++++ .../include/grantlee/exception.h | 120 +++++ .../include/grantlee/filter.h | 117 +++++ .../include/grantlee/filterexpression.h | 200 ++++++++ .../grantlee/grantlee_templates_export.h | 42 ++ .../grantlee/grantlee_textdocument_export.h | 42 ++ .../include/grantlee/grantlee_version.h | 7 + .../include/grantlee/markupdirector.h | 306 ++++++++++++ .../include/grantlee/mediawikimarkupbuilder.h | 79 ++++ .../include/grantlee/metatype.h | 244 ++++++++++ .../include/grantlee/node.h | 380 +++++++++++++++ .../include/grantlee/outputstream.h | 145 ++++++ .../include/grantlee/parser.h | 144 ++++++ .../include/grantlee/plaintextmarkupbuilder.h | 211 +++++++++ .../include/grantlee/qtlocalizer.h | 135 ++++++ .../include/grantlee/rendercontext.h | 83 ++++ .../include/grantlee/safestring.h | 436 ++++++++++++++++++ .../include/grantlee/taglibraryinterface.h | 110 +++++ .../include/grantlee/template.h | 161 +++++++ .../include/grantlee/templateloader.h | 229 +++++++++ .../include/grantlee/texthtmlbuilder.h | 238 ++++++++++ .../include/grantlee/token.h | 57 +++ .../include/grantlee/typeaccessor.h | 48 ++ .../include/grantlee/util.h | 111 +++++ .../include/grantlee/variable.h | 129 ++++++ 29 files changed, 4694 insertions(+) create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/abstractlocalizer.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/abstractmarkupbuilder.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/bbcodebuilder.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/cachingloaderdecorator.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/engine.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/exception.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/filter.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/filterexpression.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_templates_export.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_textdocument_export.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_version.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/markupdirector.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/mediawikimarkupbuilder.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/metatype.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/node.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/outputstream.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/parser.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/plaintextmarkupbuilder.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/qtlocalizer.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/rendercontext.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/safestring.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/taglibraryinterface.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/template.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/templateloader.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/texthtmlbuilder.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/token.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/typeaccessor.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/util.h create mode 100644 qt6-after/qt6-migrated-legatus/include/grantlee/variable.h diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/abstractlocalizer.h b/qt6-after/qt6-migrated-legatus/include/grantlee/abstractlocalizer.h new file mode 100644 index 000000000..243a5ce7d --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/abstractlocalizer.h @@ -0,0 +1,163 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_ABSTRACTLOCALIZER_H +#define GRANTLEE_ABSTRACTLOCALIZER_H + +#include "grantlee_templates_export.h" + +#include +#include +#include + +class QDateTime; + +namespace Grantlee +{ + +/** + @brief Interface for implementing an internationalization system. + + This class defines an interface for accessing an internationalization, such as + QLocale/QTranslator or gettext/KLocale. + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT AbstractLocalizer +{ +public: + /** + Constructor + */ + AbstractLocalizer(); + + /** + Destructor + */ + virtual ~AbstractLocalizer(); + + /** + Processes the data in @p variant into a localized string. + + The base implementation can localize numbers, dates and times, and + strings. + */ + virtual QString localize(const QVariant &variant) const; + + /** + Returns the current locale as a string. + */ + virtual QString currentLocale() const = 0; + + /** + Makes this localizer use the locale specified by @p localeName for output. + */ + virtual void pushLocale(const QString &localeName) = 0; + + /** + Makes this localizer use the previous locale for output. + */ + virtual void popLocale() = 0; + + /** + Loads the @p catalog from @p path. + */ + virtual void loadCatalog(const QString &path, const QString &catalog) = 0; + + /** + Unloads the @p catalog + */ + virtual void unloadCatalog(const QString &catalog) = 0; + + /** + Localizes @p number + */ + virtual QString localizeNumber(int number) const = 0; + + /** + Localizes @p number + */ + virtual QString localizeNumber(qreal number) const = 0; + + /** + Localizes @p value as a monetary value in the currency specified by @p + currencyCode. + */ + virtual QString localizeMonetaryValue(qreal value, const QString ¤cyCode + = {}) const = 0; + + /** + Localizes @p date with the specified @p formatType + */ + virtual QString localizeDate(const QDate &date, + QLocale::FormatType formatType + = QLocale::ShortFormat) const = 0; + + /** + Localizes @p time with the specified @p formatType + */ + virtual QString localizeTime(const QTime &time, + QLocale::FormatType formatType + = QLocale::ShortFormat) const = 0; + + /** + Localizes @p dateTime with the specified @p formatType + */ + virtual QString localizeDateTime(const QDateTime &dateTime, + QLocale::FormatType formatType + = QLocale::ShortFormat) const = 0; + + /** + Localizes @p string with the specified @p arguments for substitution + */ + virtual QString localizeString(const QString &string, + const QVariantList &arguments = {}) const = 0; + + /** + Localizes @p string, disambiguated by @p context with the specified @p + arguments for substitution + */ + virtual QString + localizeContextString(const QString &string, const QString &context, + const QVariantList &arguments = {}) const = 0; + + /** + Localizes @p string or its @p pluralForm with the specified @p arguments + for substitution + */ + virtual QString + localizePluralString(const QString &string, const QString &pluralForm, + const QVariantList &arguments = {}) const = 0; + + /** + Localizes @p string or its @p pluralForm, disambiguated by @p context with + the specified @p arguments for substitution + */ + virtual QString + localizePluralContextString(const QString &string, const QString &pluralForm, + const QString &context, + const QVariantList &arguments = {}) const = 0; + +private: + Q_DISABLE_COPY(AbstractLocalizer) +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/abstractmarkupbuilder.h b/qt6-after/qt6-migrated-legatus/include/grantlee/abstractmarkupbuilder.h new file mode 100644 index 000000000..c63168048 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/abstractmarkupbuilder.h @@ -0,0 +1,273 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2008,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_ABSTRACTMARKUPBUILDER_H +#define GRANTLEE_ABSTRACTMARKUPBUILDER_H + +#include "grantlee_textdocument_export.h" + +#include +#include + +class QBrush; + +namespace Grantlee +{ + +class AbstractMarkupBuilderPrivate; + +/// @headerfile abstractmarkupbuilder.h grantlee/abstractmarkupbuilder.h + +/** + @brief Interface for creating marked-up text output. + + The **%AbstractMarkupBuilder** is used by a MarkupDirector to create marked-up + output such as html or markdown. + + See PlainTextMarkupBuilder and TextHTMLBuilder for example implementations. + + This interface can be extended to handle custom format types in a + QTextDocument. @see @ref custom_qtextobject + + @author Stephen Kelly +*/ +class GRANTLEE_TEXTDOCUMENT_EXPORT AbstractMarkupBuilder +{ +public: + /** Destructor */ + virtual ~AbstractMarkupBuilder() {} + + /** Begin a bold element in the markup */ + virtual void beginStrong() = 0; + + /** Close the bold element in the markup */ + virtual void endStrong() = 0; + + /** Begin an emphasised element in the markup */ + virtual void beginEmph() = 0; + + /** Close the emphasised element in the markup */ + virtual void endEmph() = 0; + + /** Begin an underlined element in the markup */ + virtual void beginUnderline() = 0; + + /** Close the underlined element in the markup */ + virtual void endUnderline() = 0; + + /** Begin a struck out element in the markup */ + virtual void beginStrikeout() = 0; + + /** Close the struck out element in the markup */ + virtual void endStrikeout() = 0; + + /** + Begin a decorarated foreground element in the markup (A text color) + using @p brush + */ + virtual void beginForeground(const QBrush &brush) = 0; + + /** Close the decorarated foreground element in the markup */ + virtual void endForeground() = 0; + + /** + Begin a decorarated background element in the markup (A text background + color) using @p brush + */ + virtual void beginBackground(const QBrush &brush) = 0; + + /** Close the decorarated background element in the markup */ + virtual void endBackground() = 0; + + /** + Begin a url anchor element in the markup + @param href The href of the anchor. + @param name The name of the anchor. + */ + virtual void beginAnchor(const QString &href = {}, const QString &name = {}) + = 0; + + /** Close the anchor element */ + virtual void endAnchor() = 0; + + /** + Begin a new font familiy element in the markup + @param family The name of the font family to begin. + */ + virtual void beginFontFamily(const QString &family) = 0; + + /** End font family element */ + virtual void endFontFamily() = 0; + + /** + Begin a new font point size element in the markup + @param size The point size to begin. + */ + virtual void beginFontPointSize(int size) = 0; + + /** End font point size element */ + virtual void endFontPointSize() = 0; + + /** + Begin a new paragraph in the markup + @param a The alignment of the new paragraph. + @param top The top margin of the new paragraph. + @param bottom The bottom margin of the new paragraph. + @param left The left margin of the new paragraph. + @param right The right margin of the new paragraph. + */ + virtual void beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, + qreal bottom = 0.0, qreal left = 0.0, + qreal right = 0.0) + = 0; + + /** Close the paragraph in the markup. */ + virtual void endParagraph() = 0; + /** Add a newline to the markup. */ + virtual void addNewline() = 0; + + /** + Insert a horizontal rule into the markup. + @param width The width of the rule. Default is full width. + */ + virtual void insertHorizontalRule(int width = -1) = 0; + + /** + Insert a new image element into the markup. + @param url The url of the image + @param width The width of the image + @param height The height of the image. + */ + virtual void insertImage(const QString &url, qreal width, qreal height) = 0; + + /** + Begin a new list element in the markup. + A list element contains list items, and may contain other lists. + @param style The style of list to create. + */ + virtual void beginList(QTextListFormat::Style style) = 0; + + /** + Close the list. + */ + virtual void endList() = 0; + + /** Begin a new list item in the markup */ + virtual void beginListItem() = 0; + + /** End the list item */ + virtual void endListItem() = 0; + + /** Begin a superscript element */ + virtual void beginSuperscript() = 0; + + /** End superscript element */ + virtual void endSuperscript() = 0; + + /** Begin a subscript element */ + virtual void beginSubscript() = 0; + + /** End subscript element */ + virtual void endSubscript() = 0; + + /** + Begin a table element. + + @param cellpadding The padding attribute for the table. + @param cellspacing The spacing attribute for the table. + @param width The width of the table. May be either an integer, or a + percentage value. + */ + virtual void beginTable(qreal cellpadding, qreal cellspacing, + const QString &width) + = 0; + + /** + Begin a new table row + */ + virtual void beginTableRow() = 0; + + /** + Begin a new table header cell. + @param width The width of the cell. + @param colSpan The column span of the cell. + @param rowSpan The row span of the cell. + */ + virtual void beginTableHeaderCell(const QString &width, int colSpan, + int rowSpan) + = 0; + + /** + Begin a new table cell. + @param width The width of the cell. + @param colSpan The column span of the cell. + @param rowSpan The row span of the cell. + */ + virtual void beginTableCell(const QString &width, int colSpan, int rowSpan) + = 0; + + /** End a table element */ + virtual void endTable() = 0; + + /** End a table row */ + virtual void endTableRow() = 0; + + /** End a table header cell */ + virtual void endTableHeaderCell() = 0; + + /** End a table cell */ + virtual void endTableCell() = 0; + + /** + Begin a level @p level header + @param level An integer between 1 and 6 + */ + virtual void beginHeader(int level) = 0; + + /** + End a level @p level header + @param level An integer between 1 and 6 + */ + virtual void endHeader(int level) = 0; + + /** + Append the plain text @p text to the markup + + @param text The text to append. + */ + virtual void appendLiteralText(const QString &text) = 0; + + /** + Append the raw text @p text to the markup. @p text is added unescaped + */ + virtual void appendRawText(const QString &text) = 0; + + /** + Return the fully marked up result of the building process. + + This may contain metadata etc, such as a head element in html. + + @return The fully marked up text. + */ + virtual QString getResult() = 0; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/bbcodebuilder.h b/qt6-after/qt6-migrated-legatus/include/grantlee/bbcodebuilder.h new file mode 100644 index 000000000..f8126a6b9 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/bbcodebuilder.h @@ -0,0 +1,113 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2008 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_BBCODEBUILDER_H +#define GRANTLEE_BBCODEBUILDER_H + +#include "abstractmarkupbuilder.h" + +namespace Grantlee +{ + +/** + @brief Builder to create BBCode from a QTextDocument +*/ +class BBCodeBuilder : public AbstractMarkupBuilder +{ +public: + /** + Creates a new BBCodeBuilder. + */ + BBCodeBuilder(); + + ~BBCodeBuilder() override; + + void beginStrong() override; + void endStrong() override; + void beginEmph() override; + void endEmph() override; + void beginUnderline() override; + void endUnderline() override; + void beginStrikeout() override; + void endStrikeout() override; + void beginForeground(const QBrush &brush) override; + void endForeground() override; + + // Background colour not supported by BBCode. + + void beginAnchor(const QString &href = {}, const QString &name = {}) override; + void endAnchor() override; + + // Font family not supported by BBCode. + + /** + Begin an element of font size @p size. Note that this size is in pixels, + and must be converted before it is suitable for use in BBCode. + @param size The size of font to begin. + */ + void beginFontPointSize(int size) override; + void endFontPointSize() override; + + void beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, + qreal bottom = 0.0, qreal left = 0.0, + qreal right = 0.0) override; + + void endParagraph() override; + void addNewline() override; + + void insertImage(const QString &src, qreal width, qreal height) override; + + void beginList(QTextListFormat::Style type) override; + + void endList() override; + + void beginListItem() override; + + void beginSuperscript() override; + + void endSuperscript() override; + + void beginSubscript() override; + + void endSubscript() override; + + void beginTable(qreal, qreal, const QString &) override; + + void beginTableRow() override; + + void appendLiteralText(const QString &text) override; + + /** + Escapes @p text appropriately for BBCode. + */ + const QString escape(const QString &text) const; + + QString getResult() override; + +private: + QList m_currentListItemStyles; + + QString m_text; + + Qt::Alignment m_currentAlignment; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/cachingloaderdecorator.h b/qt6-after/qt6-migrated-legatus/include/grantlee/cachingloaderdecorator.h new file mode 100644 index 000000000..652b3d3dc --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/cachingloaderdecorator.h @@ -0,0 +1,112 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_CACHINGLOADERDECORATOR_H +#define GRANTLEE_CACHINGLOADERDECORATOR_H + +#include "templateloader.h" + +#include "grantlee_templates_export.h" + +namespace Grantlee +{ + +class CachingLoaderDecoratorPrivate; + +/// @headerfile cachingloaderdecorator.h grantlee/cachingloaderdecorator.h + +/** + @brief Implements a loader decorator which caches compiled Template objects. + + The **%CachingLoaderDecorator** can be used with any implementation of + Grantlee::AbstractTemplateLoader. + + @code + auto loader = QSharedPointer::create(); + loader->setTemplateDirs({"/path/one", "/path/two"}); + + auto cache = + QSharedPointer::create( loader ); + m_engine->addTemplateLoader( cache ); + @endcode + + The effect is that templates do not need to be loaded from the filesystem and + compiled into Template objects on each access, but may be returned from the + cache instead. + + This can be significant if loading Templates in a loop, or loading the same + Template very often in an application. + + @code +
    + {% for item in list %} +
  • {% include "itemtemplate.html" %}
  • + {% endfor %} +
+ @endcode + + If the loading of Templates is a bottleneck in an application, it may make + sense to use the caching decorator. + + @author Stephen Kelly + */ +class GRANTLEE_TEMPLATES_EXPORT CachingLoaderDecorator + : public AbstractTemplateLoader +{ +public: + /** + Constructor + */ + CachingLoaderDecorator(QSharedPointer loader); + + /** + Destructor + */ + ~CachingLoaderDecorator() override; + + bool canLoadTemplate(const QString &name) const override; + + QPair getMediaUri(const QString &fileName) const override; + + Template loadByName(const QString &name, + const Grantlee::Engine *engine) const override; + + /** + Clears the Templates objects cached in the decorator. + */ + void clear(); + + /** + Returns the number of Template objects cached in the decorator. + */ + int size() const; + + /** + Returns whether the cache is empty. + */ + bool isEmpty() const; + +private: + Q_DECLARE_PRIVATE(CachingLoaderDecorator) + CachingLoaderDecoratorPrivate *const d_ptr; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/engine.h b/qt6-after/qt6-migrated-legatus/include/grantlee/engine.h new file mode 100644 index 000000000..c73a9048d --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/engine.h @@ -0,0 +1,259 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_ENGINE_H +#define GRANTLEE_ENGINE_H + +#include "template.h" +#include "templateloader.h" + +namespace Grantlee +{ +class TagLibraryInterface; + +class EnginePrivate; + +/// @headerfile engine.h grantlee/engine.h + +/** + @brief **%Grantlee::Engine** is the main entry point for creating %Grantlee + Templates. + + The **%Grantlee::Engine** is responsible for configuring and creating Template + objects. In typical use, one or more AbstractTemplateLoader objects will be + added to the Engine to load template objects, and plugin directories will be + set to enable finding template tags and filters. + + @code + auto engine = new Engine(); + + auto loader = QSharedPointer::create(); + loader->setTemplateDirs( {"/usr/share/myapp/templates"} ); + engine->addTemplateLoader( loader ); + + engine->addPluginPath( "/usr/lib/myapp" ); + + auto template1 = engine->newTemplate( "Template content", "template name" ); + + auto template2 = engine->loadByName( "templatefile.html" ); + @endcode + + Once it is configured, the **%Engine** can be used to create new templates by + name by loading the templates with the @ref loadByName method, or by defining + the content in the @ref newTemplate method. + + By default the builtin tags and filters distributed with %Grantlee are + available in all templates without using the @gr_tag{load} tag in the + template. These pre-loaded libraries may be configured if appropriate to the + application. For example, an application which defines its own tags and + filters may want them to be always available, or it may be desirable to + restrict the features available to template authors by removing built in + libraries. + + Different **%Engine** objects can be used to create templates with differing + configurations. + + @section smart_trim Insignificant whitespace + + The output of rendering a template depends on the content of the template. In + some cases when generating content in which whitespace is significant, this + can have undesired effects. For example, given a template to generate C++ code + like: + + @verbatim + class MyClass { + {# This loop creates the #} + {# methods in the class #} + {% for method in methods %} + {% if method.hasDox %} + {{ method.dox }} + {% endif %} + {{ method.signature }} + {% endfor %} + }; + @endverbatim + + The output would have a lot of whitespace which is not necessarily wanted. + + @code + class MyClass { + + + + + void foo() const; + + }; + @endcode + + It is possible to strip insignificant whitespace by enabling the smartTrim + feature with @ref setSmartTrimEnabled. When enabled the output will not + contain a newline for any line in the template which has only one token of + template syntax, such as a comment, tag or variable. + + @code + class MyClass { + + void foo() const; + }; + @endcode + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT Engine : public QObject +{ + Q_OBJECT +public: + /** + Constructor + */ + Engine(QObject *parent = {}); + + /** + Destructor. + */ + ~Engine() override; + + /** + Returns the TemplateLoaders currently configured on the **%Engine**. + */ + QList> templateLoaders(); + + /** + Adds @p loader to the TemplateLoaders currently configured on + the **%Engine**. + */ + void addTemplateLoader(QSharedPointer loader); + + /** + Sets the plugin dirs currently configured on the **%Engine** to @p dirs. + + @warning This overwrites the default paths. You normally want + @ref addPluginPath. + + @see @ref finding_plugins + */ + void setPluginPaths(const QStringList &dirs); + + /** + Prepend @p dir to the list of plugin dirs. + */ + void addPluginPath(const QString &dir); + + /** + Removes all instances of @p dir from the list of plugin dirs. + */ + void removePluginPath(const QString &dir); + + /** + Returns the currently configured plugin dirs + */ + QStringList pluginPaths() const; + + /** + Returns a URI for a media item with the name @p name. + + Typically this will be used for images. For example the media URI for the + image "header_logo.png" may be + "/home/user/common/header_logo.png" or + "/home/user/some_theme/header_logo.png" + depending on the @ref templateLoaders configured. + + This method will not usually be called by application code. To load media + in a template, use the @gr_tag{media_finder} template tag. + */ + QPair mediaUri(const QString &fileName) const; + + /** + Load the Template identified by @p name. + + The Templates and plugins loaded will be determined by + the **%Engine** configuration. + */ + Template loadByName(const QString &name) const; + + /** + Create a new Template with the content @p content identified by @p name. + + The secondary Templates and plugins loaded will be determined by + the **%Engine** configuration. + */ + Template newTemplate(const QString &content, const QString &name) const; + + /** + Returns the libraries available by default to new Templates. + */ + QStringList defaultLibraries() const; + + /** + Adds the library named @p libName to the libraries available by default to + new Templates. + */ + void addDefaultLibrary(const QString &libName); + + /** + Removes the library named @p libName from the libraries available by + default to new Templates. + */ + void removeDefaultLibrary(const QString &libName); + + /** + Returns whether the smart trim feature is enabled for newly loaded + templates. + + @see smart_trim + + This is false by default. + */ + bool smartTrimEnabled() const; + + /** + Sets whether the smart trim feature is enabled for newly loaded templates. + + @see smart_trim + */ + void setSmartTrimEnabled(bool enabled); + +#ifndef Q_QDOC + /** + @internal + + Loads and returns the libraries specified in defaultLibraries or @p state. + */ + void loadDefaultLibraries(); + + /** + @internal + + Loads and returns the library specified by @p name in the + current **%Engine** configuration or @p state. + + Templates wishing to load a library should use the @gr_tag{load} tag. + */ + TagLibraryInterface *loadLibrary(const QString &name); +#endif + +private: + Q_DECLARE_PRIVATE(Engine) + EnginePrivate *const d_ptr; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/exception.h b/qt6-after/qt6-migrated-legatus/include/grantlee/exception.h new file mode 100644 index 000000000..80bf2cf4f --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/exception.h @@ -0,0 +1,120 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_EXCEPTION_H +#define GRANTLEE_EXCEPTION_H + +#include "grantlee_templates_export.h" + +#include + +#include + +namespace Grantlee +{ + +/** + Types of errors that can occur while using %Grantlee +*/ +enum Error { + NoError, + EmptyVariableError, + EmptyBlockTagError, + InvalidBlockTagError, + UnclosedBlockTagError, + UnknownFilterError, + TagSyntaxError, + // VariableSyntaxError, + + VariableNotInContext, + ObjectReturnTypeInvalid, + CompileFunctionError +}; + +/// @headerfile exception.h grantlee/exception.h + +/** + @brief An exception for use when implementing template tags. + + The **%Exception** class can be used when implementing + AbstractNodeFactory::getNode. An exception can be thrown to indicate that + the syntax of a particular tag is invalid. + + For example, the following template markup should throw an error because the + include tag should have exactly one argument: + + @code +
+ {% include %} +
+ @endcode + + The corresponding implementation of IncludeNodeFactory::getNode is + + @code + QStringList tagContents = smartSplit( tagContent ); + + if ( tagContents.size() != 2 ) + throw Grantlee::Exception( TagSyntaxError, + "Error: Include tag takes exactly one argument" ); + + // The item at index 0 in the list is the tag name, "include" + QString includeName = tagContents.at( 1 ); + @endcode + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT Exception +{ +public: + /** + Creates an exception for the error @p errorCode and the verbose + message @p what + */ + Exception(Error errorCode, const QString &what) + : m_errorCode(errorCode), m_what(what) + { + } + + virtual ~Exception() throw() {} + +#ifndef Q_QDOC + /** + @internal + + Returns the verbose message for the exception. + */ + const QString what() const throw() { return m_what; } + + /** + @internal + + Returns the error code for the exception. + */ + Error errorCode() const { return m_errorCode; } +#endif + +private: + Error m_errorCode; + QString m_what; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/filter.h b/qt6-after/qt6-migrated-legatus/include/grantlee/filter.h new file mode 100644 index 000000000..3a08efcbe --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/filter.h @@ -0,0 +1,117 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +// krazy:excludeall=dpointer + +#ifndef GRANTLEE_FILTER_H +#define GRANTLEE_FILTER_H + +#include "grantlee_templates_export.h" +#include "outputstream.h" +#include "safestring.h" + +#include +#include +#include + +namespace Grantlee +{ + +/// @headerfile filter.h grantlee/filter.h + +/** + @brief Base class for all filters. + + The **%Filter** class can be implemented in plugin libraries to make + additional functionality available to templates. + + Developers are required only to implement the @ref doFilter method and + integrate the filter as part of a custom plugin, but will never create or + access filters directly in application code. + + The FilterExpression class is the access interface to a chain of **%Filter** + objects. + + The @ref escape and @ref conditionalEscape methods are available for escaping + data where needed. + + @see @ref filters + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT Filter +{ +public: + /** + Destructor. + */ + virtual ~Filter(); + +#ifndef Q_QDOC + /** + FilterExpression makes it possible to access stream methods like escape + while resolving. + */ + void setStream(OutputStream *stream); +#endif + + /** + Escapes and returns @p input. The OutputStream::escape method is used to + escape @p input. + */ + SafeString escape(const QString &input) const; + + /** + Escapes and returns @p input. The OutputStream::escape method is used to + escape @p input. + */ + SafeString escape(const SafeString &input) const; + + /** + Escapes @p input if not already safe from further escaping and returns it. + The OutputStream::escape method is used to escape @p input. + */ + SafeString conditionalEscape(const SafeString &input) const; + + /** + Reimplement to filter @p input given @p argument. + + @p autoescape determines whether the autoescape feature is currently on or + off. Most filters will not use this. + + @see @ref autoescaping + */ + virtual QVariant doFilter(const QVariant &input, + const QVariant &argument = {}, + bool autoescape = {}) const = 0; + + /** + Reimplement to return whether this filter is safe. + */ + virtual bool isSafe() const; + +private: +#ifndef Q_QDOC + OutputStream *m_stream; +#endif +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/filterexpression.h b/qt6-after/qt6-migrated-legatus/include/grantlee/filterexpression.h new file mode 100644 index 000000000..796d36f6b --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/filterexpression.h @@ -0,0 +1,200 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_FILTEREXPRESSION_H +#define GRANTLEE_FILTEREXPRESSION_H + +#include "variable.h" + +#include "grantlee_templates_export.h" + +namespace Grantlee +{ +class Filter; +class OutputStream; +class Parser; +struct Token; + +class FilterExpressionPrivate; + +/// @headerfile filterexpression.h grantlee/filterexpression.h + +/** + @brief A **%FilterExpression** object represents a filter expression in a + template. + + This class is only relevant if implementing custom tags or filters. Most of + the API here is internal. + Usually when implementing tags or filters, filter expressions will just be + created and resolved. + + In template markup, a filter expression is a variable followed by one or more + filters separated by pipes: + + %Filter expressions may appear in variable nodes: + @code + {{ some_var|upper_filter|lower_filter }} + @endcode + + Or as arguments to tags + @code + {% some_tag some_arg1|filter1|filter2 some_arg2|filter3 %} + @endcode + + The **%FilterExpression** class would be used in the getNode implementation of + the AbstractNodeFactory implementation for the some_tag tag. + + @code + Node* SomeTagFactory::getNode(const QString &tagContent, Parser *p) const { + auto parts = smartSplit( tagContent ); + + parts.removeFirst(); // Remove the "some_tag" part. + + FilterExpression arg1( parts.first(), p ); + FilterExpression arg2( parts.at( 1 ), p ); + + return new SomeTagNode( arg1, arg2, p ); + } + @endcode + + @see AbstractNodeFactory::getFilterExpressionList + + When implementing the Node::render method, the @ref resolve method may be used + to process the filter expression. + + For example, if our SomeTagNode was to concatenate the resolved + values given as arguments: + + @code + void SomeTagNode::render( QTextStream *stream, Context *c ) { + m_arg1.resolve( stream, c ); + m_arg2.resolve( stream, c ); + } + @endcode + + Because Filters are highly generic, they do not all write data to the stream. + For example, a Filter might take as input a string, and return a list by + splitting the string on commas, or a Filter might compare an input to its + argument and return whether they are the same, but not write anything to the + stream. For that reason, the @ref resolve method writes data to the given + stream, and returns the same data in its returned QVariant. + + The suitability of either of the @ref resolve methods will depend on the + implementation and requirements of your custom tag. For example if the + SomeTagNode ran a comparison of the arguments: + + @code + void SomeTagNode::render( QTextStream *stream, Context *c ) { + QString first = m_arg1.resolve( c ).toString(); + QString second = m_arg2.resolve( c ).toString(); + + if ( first == second ) + m_trueList.render( stream, c ); + else + m_falseList.render( stream, c ); + } + @endcode + + @see @ref tags_with_end_tags + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT FilterExpression +{ +public: + /** + Constructs an invalid **%FilterExpression**. + */ + FilterExpression(); + + /** + Constructs a filter expression from the string @p varString. The Parser @p + parser is used to retrieve filters. + */ + FilterExpression(const QString &varString, Grantlee::Parser *parser); + + /** + Copy constructor. + */ + FilterExpression(const FilterExpression &other); + + /** + Destructor. + */ + ~FilterExpression(); + + /** + Assignment operator. + */ + FilterExpression &operator=(const FilterExpression &other); + + /** + Returns the initial variable in the **%FilterExpression**. + */ + Variable variable() const; + + /** + Resolves the **%FilterExpression** in the Context @p c and writes it to the + stream @p stream. + */ + QVariant resolve(OutputStream *stream, Context *c) const; + + /** + Resolves the **%FilterExpression** in the Context @p c. + */ + QVariant resolve(Context *c) const; + + /** + Returns whether the Filter resolves to true in the Context @p c. + @see @ref truthiness + */ + bool isTrue(Context *c) const; + + /** + Returns a list for the **%FilterExpression**. + + If the **%FilterExpression** can not be resolved to a list, an empty list + will be returned. + */ + QVariantList toList(Context *c) const; + + /** + Returns whether a filter expression is valid. + + A **%FilterExpression** is valid if all filters in the expression exist and + the initial variable being filtered is valid. + */ + bool isValid() const; + +#ifndef Q_QDOC + /** + @internal + Returns the list of filters in the **%FilterExpression**. + */ + QStringList filters() const; +#endif + +private: + Q_DECLARE_PRIVATE(FilterExpression) + FilterExpressionPrivate *const d_ptr; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_templates_export.h b/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_templates_export.h new file mode 100644 index 000000000..1624c4b82 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_templates_export.h @@ -0,0 +1,42 @@ + +#ifndef GRANTLEE_TEMPLATES_EXPORT_H +#define GRANTLEE_TEMPLATES_EXPORT_H + +#ifdef GRANTLEE_TEMPLATES_STATIC_DEFINE +# define GRANTLEE_TEMPLATES_EXPORT +# define GRANTLEE_TEMPLATES_NO_EXPORT +#else +# ifndef GRANTLEE_TEMPLATES_EXPORT +# ifdef Grantlee_Templates_EXPORTS + /* We are building this library */ +# define GRANTLEE_TEMPLATES_EXPORT __attribute__((visibility("default"))) +# else + /* We are using this library */ +# define GRANTLEE_TEMPLATES_EXPORT __attribute__((visibility("default"))) +# endif +# endif + +# ifndef GRANTLEE_TEMPLATES_NO_EXPORT +# define GRANTLEE_TEMPLATES_NO_EXPORT __attribute__((visibility("hidden"))) +# endif +#endif + +#ifndef GRANTLEE_TEMPLATES_DEPRECATED +# define GRANTLEE_TEMPLATES_DEPRECATED __attribute__ ((__deprecated__)) +#endif + +#ifndef GRANTLEE_TEMPLATES_DEPRECATED_EXPORT +# define GRANTLEE_TEMPLATES_DEPRECATED_EXPORT GRANTLEE_TEMPLATES_EXPORT GRANTLEE_TEMPLATES_DEPRECATED +#endif + +#ifndef GRANTLEE_TEMPLATES_DEPRECATED_NO_EXPORT +# define GRANTLEE_TEMPLATES_DEPRECATED_NO_EXPORT GRANTLEE_TEMPLATES_NO_EXPORT GRANTLEE_TEMPLATES_DEPRECATED +#endif + +#if 0 /* DEFINE_NO_DEPRECATED */ +# ifndef GRANTLEE_TEMPLATES_NO_DEPRECATED +# define GRANTLEE_TEMPLATES_NO_DEPRECATED +# endif +#endif + +#endif /* GRANTLEE_TEMPLATES_EXPORT_H */ diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_textdocument_export.h b/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_textdocument_export.h new file mode 100644 index 000000000..63bf5e2f7 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_textdocument_export.h @@ -0,0 +1,42 @@ + +#ifndef GRANTLEE_TEXTDOCUMENT_EXPORT_H +#define GRANTLEE_TEXTDOCUMENT_EXPORT_H + +#ifdef GRANTLEE_TEXTDOCUMENT_STATIC_DEFINE +# define GRANTLEE_TEXTDOCUMENT_EXPORT +# define GRANTLEE_TEXTDOCUMENT_NO_EXPORT +#else +# ifndef GRANTLEE_TEXTDOCUMENT_EXPORT +# ifdef Grantlee_TextDocument_EXPORTS + /* We are building this library */ +# define GRANTLEE_TEXTDOCUMENT_EXPORT __attribute__((visibility("default"))) +# else + /* We are using this library */ +# define GRANTLEE_TEXTDOCUMENT_EXPORT __attribute__((visibility("default"))) +# endif +# endif + +# ifndef GRANTLEE_TEXTDOCUMENT_NO_EXPORT +# define GRANTLEE_TEXTDOCUMENT_NO_EXPORT __attribute__((visibility("hidden"))) +# endif +#endif + +#ifndef GRANTLEE_TEXTDOCUMENT_DEPRECATED +# define GRANTLEE_TEXTDOCUMENT_DEPRECATED __attribute__ ((__deprecated__)) +#endif + +#ifndef GRANTLEE_TEXTDOCUMENT_DEPRECATED_EXPORT +# define GRANTLEE_TEXTDOCUMENT_DEPRECATED_EXPORT GRANTLEE_TEXTDOCUMENT_EXPORT GRANTLEE_TEXTDOCUMENT_DEPRECATED +#endif + +#ifndef GRANTLEE_TEXTDOCUMENT_DEPRECATED_NO_EXPORT +# define GRANTLEE_TEXTDOCUMENT_DEPRECATED_NO_EXPORT GRANTLEE_TEXTDOCUMENT_NO_EXPORT GRANTLEE_TEXTDOCUMENT_DEPRECATED +#endif + +#if 0 /* DEFINE_NO_DEPRECATED */ +# ifndef GRANTLEE_TEXTDOCUMENT_NO_DEPRECATED +# define GRANTLEE_TEXTDOCUMENT_NO_DEPRECATED +# endif +#endif + +#endif /* GRANTLEE_TEXTDOCUMENT_EXPORT_H */ diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_version.h b/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_version.h new file mode 100644 index 000000000..b3c110b29 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/grantlee_version.h @@ -0,0 +1,7 @@ +#define GRANTLEE_VERSION_MAJOR 5 +#define GRANTLEE_VERSION_MINOR 3 +#define GRANTLEE_VERSION_PATCH 0 +#define GRANTLEE_VERSION_STRING "5.3.0" +#define GRANTLEE_VERSION ((5<<16)|(3<<8)|(0)) +#define GRANTLEE_MAJOR_MINOR_VERSION_STRING "5.3" +#define GRANTLEE_MIN_PLUGIN_VERSION 0 diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/markupdirector.h b/qt6-after/qt6-migrated-legatus/include/grantlee/markupdirector.h new file mode 100644 index 000000000..ca9daa1d5 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/markupdirector.h @@ -0,0 +1,306 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2008 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_MARKUPDIRECTOR_H +#define GRANTLEE_MARKUPDIRECTOR_H + +#include "abstractmarkupbuilder.h" +#include "grantlee_textdocument_export.h" + +#include +#include + +class QTextTable; +class QTextTableCell; +class QTextList; +class QTextCharFormat; + +namespace Grantlee +{ + +class MarkupDirectorPrivate; + +/// @headerfile markupdirector.h grantlee/markupdirector.h + +/** + @brief Instructs a builder object to create markup output + + The **%MarkupDirector** is used with an implementation of + AbstractMarkupBuilder to create a marked up document output. + + Usage can be quite simple. + + @code + auto doc = editor->document(); // editor is a QTextEdit + + auto builder = new HTMLBuilder(); + auto md = new MarkupDirector(builder); + md->processDocument(doc); + browser->setHtml(builder->getResult()); // browser is a QTextBrowser. + @endcode + + Or with a different builder: + + @code + auto builder = new PlainTextMarkupBuilder(); + auto md = new MarkupDirector(builder); + md->processDocument(doc); + browser->setPlainText(builder->getResult()); + @endcode + + The **%MarkupDirector** also provides API for processing just part of a + QTextDocument, such as a QTextFrame or a QTextBlock. The appropriate method + may then be called with an invalid iterator as appropriate. + + @code + // ... Do some processing to get a QTextFrame. + auto frame = getFrame(); + + auto builder = new PlainTextMarkupBuilder(); + auto md = new MarkupDirector(builder); + + // Create output from only the frame. + md->processFrame(QTextFrame::iterator(), frame); + browser->setPlainText(builder->getResult()); + @endcode + + The behaviour of the **%MarkupDirector** can be customized by subclassing. + Support for custom types can also be added by implementing the @ref + processCustomFragment method. + + @see @ref custom_qtextobject + + @author Stephen Kelly +*/ +class GRANTLEE_TEXTDOCUMENT_EXPORT MarkupDirector +{ +public: + /** + Constructor + */ + MarkupDirector(AbstractMarkupBuilder *builder); + + /** + Destructor + */ + virtual ~MarkupDirector(); + + /** + Constructs the output by directing the builder to create the markup. + */ + virtual void processDocument(QTextDocument *doc); + + /** + Directs the builder to create output for the single @p frame. If calling + this method directly, an invalid QTextFrame::iterator may be used. + */ + virtual QTextFrame::iterator processFrame(QTextFrame::iterator it, + QTextFrame *frame); + + /** + Directs the builder to create output for the single @p block. If calling + this method directly, an invalid QTextFrame::iterator may be used. + + This method does not process the contents of the @p block, but uses the + @ref processBlockContents method to do so. + */ + virtual QTextFrame::iterator processBlock(QTextFrame::iterator it, + const QTextBlock &block); + + /** + Directs the builder to create output for the single @p textObject. If + calling this method directly, an invalid QTextFrame::iterator may be used. + + The block @p block is the container of the @p textObject. + */ + virtual QTextFrame::iterator processObject(QTextFrame::iterator it, + const QTextBlock &block, + QTextObject *textObject); + + /** + Directs the builder to create output for the single @p textBlockGroup. If + calling this method directly, an invalid QTextFrame::iterator may be used. + + The block @p block is the first block in the @p textBlockGroup. + */ + virtual QPair + processBlockGroup(QTextFrame::iterator it, const QTextBlock &block, + QTextBlockGroup *textBlockGroup); + + /** + Directs the builder to create output for the single @p textList. If + calling this method directly, an invalid QTextFrame::iterator may be used. + + The block @p block is the first block in the @p textList. + */ + virtual QPair + processList(QTextFrame::iterator it, const QTextBlock &block, + QTextList *textList); + + /** + Directs the builder to create output for the contents of the single @p + block. If calling this method directly, an invalid QTextFrame::iterator + may be used. + */ + virtual QTextFrame::iterator processBlockContents(QTextFrame::iterator it, + const QTextBlock &block); + + /** + Hook for instructing the builder to create output for the @p fragemnt with + a custom type. @p doc is the document the fragment is in. + */ + virtual void processCustomFragment(const QTextFragment &fragment, + QTextDocument const *doc); + + /** + Directs the builder to create output for the contents of the single @p + fragment. If calling this method directly, an invalid QTextBlock::iterator + may be used. @p doc is the document the fragment is in. + */ + virtual QTextBlock::iterator processFragment(QTextBlock::iterator it, + const QTextFragment &fragment, + QTextDocument const *doc); + + /** + Directs the builder to create output for the contents of the single @p + textObject. The @p textObject is represented in the QTextDocument with the + QTextFragment @p fragment. + + If calling this method directly, an invalid QTextBlock::iterator may be + used. + */ + virtual QTextBlock::iterator + processCharTextObject(QTextBlock::iterator it, const QTextFragment &fragment, + QTextObject *textObject); + + /** + Directs the builder to create output for the image represented by the @p + imageFormat. + + If calling this method directly, an invalid QTextBlock::iterator may be + used. @p doc is the document the fragment is in. + */ + virtual QTextBlock::iterator processImage(QTextBlock::iterator it, + const QTextImageFormat &imageFormat, + QTextDocument *doc); + + /** + Directs the builder to create output for the contents of the single @p + table. + + If calling this method directly, an invalid QTextFrame::iterator may be + used. + */ + virtual QTextFrame::iterator processTable(QTextFrame::iterator it, + QTextTable *table); + + /** + Directs the builder to create output for the contents of the single @p + tableCell. The tableCell is in the @p table. + */ + virtual void processTableCell(const QTextTableCell &tableCell, + QTextTable *table); + +protected: + /** + Processes the document between @p begin and @p end + */ + void processDocumentContents(QTextFrame::iterator begin, + QTextFrame::iterator end); + + /** + Iterates the iterator @p it to the first block after @p blockGroup. @p + _block is any block in the @p blockGroup. + + The return pair is the iterator pointing after the end of @p blockGroup + and the first block after @p blockGroup. + */ + QPair + skipBlockGroup(QTextFrame::iterator it, const QTextBlock &_block, + QTextBlockGroup *blockGroup); + + /** + Returns a list of tags contained in @p openingTags sorted so they can be + opened in order and will be closed in the correct order. + + @p openingTags should be a set of tags opened at the fragment pointed to + by @p it. + */ + QList sortOpeningOrder(QSet openingTags, + QTextBlock::iterator it) const; + + /** + Directs the builder to close the appropriate tags at the position of @p + it. + */ + virtual void processClosingElements(QTextBlock::iterator it); + + /** + Directs the builder to open the appropriate tags at the position of @p it. + */ + virtual void processOpeningElements(QTextBlock::iterator it); + + /** + Returns the tags that should be closed at the position of @p it. + */ + virtual QSet getElementsToClose(QTextBlock::iterator it) const; + + /** + Returns the tags that should be opened at the position of @p it. + */ + virtual QList getElementsToOpen(QTextBlock::iterator it); + + /** + Flags for the tags that may be open. + */ + enum OpenElementValues { + None = 0x0, /// No tags are open + SuperScript = 0x01, /// A superscript tag is open + SubScript = 0x02, /// A subscript tag is open + Anchor = 0x04, /// An anchor tag is open + SpanForeground = 0x08, /// A foreground altering span tag is open. + SpanBackground = 0x10, /// A background altering span tag is open. + SpanFontFamily = 0x20, /// A font family altering span tag is open. + SpanFontPointSize = 0x40, /// A font size altering span tag is open. + Strong = 0x80, /// A strong tag is open. + Emph = 0x100, /// A emphasis tag is open. + Underline = 0x200, /// An underline tag is open. + StrikeOut = 0x400 /// A strikeout tag is open. + }; + +protected: +#ifndef Q_QDOC + MarkupDirectorPrivate *const d_ptr; +#endif + + /** + The builder this MarkupDirector is operating on. This is available when + subclassing to customize behaviour. + */ + AbstractMarkupBuilder *m_builder; + +#ifndef Q_QDOC +private: + Q_DECLARE_PRIVATE(MarkupDirector) +#endif +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/mediawikimarkupbuilder.h b/qt6-after/qt6-migrated-legatus/include/grantlee/mediawikimarkupbuilder.h new file mode 100644 index 000000000..ec8652886 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/mediawikimarkupbuilder.h @@ -0,0 +1,79 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2008 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_MEDIAWIKIMARKUPBUILDER_H +#define GRANTLEE_MEDIAWIKIMARKUPBUILDER_H + +#include "abstractmarkupbuilder.h" + +namespace Grantlee +{ + +/** + @brief Creates MediaWiki markup from a QTextDocument +*/ +class MediaWikiMarkupBuilder : public AbstractMarkupBuilder +{ +public: + MediaWikiMarkupBuilder(); + ~MediaWikiMarkupBuilder() override; + + void beginStrong() override; + void endStrong() override; + void beginEmph() override; + void endEmph() override; + void beginUnderline() override; + void endUnderline() override; + void beginStrikeout() override; + void endStrikeout() override; + + void endParagraph() override; + void addNewline() override; + + void beginAnchor(const QString &href = {}, const QString &name = {}) override; + void endAnchor() override; + + void beginHeader(int level) override; + void endHeader(int level) override; + + void beginList(QTextListFormat::Style type) override; + + void endList() override; + + void beginListItem() override; + void endListItem() override; + + void appendLiteralText(const QString &text) override; + + /** + Escapes @p text appropriately for MediaWiki. + */ + const QString escape(const QString &s); + + QString getResult() override; + +private: + QList currentListItemStyles; + + QString m_text; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/metatype.h b/qt6-after/qt6-migrated-legatus/include/grantlee/metatype.h new file mode 100644 index 000000000..e4fc48df8 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/metatype.h @@ -0,0 +1,244 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2010 Michael Jansen + Copyright (c) 2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_METATYPE_H +#define GRANTLEE_METATYPE_H + +#include "grantlee_templates_export.h" + +#include "typeaccessor.h" + +#include + +/// @file + +namespace Grantlee +{ + +/// @headerfile metatype.h grantlee/metatype.h + +#ifndef Q_QDOC +/** + @brief The **%MetaType** is the interface to the Grantlee introspection + system. + + The **%MetaType** class is used as part of the type registration system of + %Grantlee. + + @see @ref generic_types_and_templates + @author Michael Jansen + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT MetaType +{ +public: + /** + @internal The signature for a property lookup method + */ + typedef QVariant (*LookupFunction)(const QVariant &, const QString &); + + /** + @internal Registers a property lookup method + */ + static void registerLookUpOperator(int id, LookupFunction f); + + /** + @internal + */ + static void internalLock(); + + /** + @internal + */ + static void internalUnlock(); + + /** + @internal + */ + static QVariant lookup(const QVariant &object, const QString &property); + + /** + @internal + */ + static bool lookupAlreadyRegistered(int id); + +private: + MetaType(); +}; +#endif + +namespace +{ + +/* + This is a helper to select an appropriate overload of indexAccess + */ +template struct LookupTrait { + static QVariant doLookUp(const QVariant &object, const QString &property) + { + typedef typename Grantlee::TypeAccessor Accessor; + return Accessor::lookUp(object.value(), property); + } +}; + +template +struct LookupTrait { + static QVariant doLookUp(const QVariant &object, const QString &property) + { + typedef typename Grantlee::TypeAccessor Accessor; + return Accessor::lookUp(object.value(), property); + } +}; + +template static int doRegister(int id) +{ + if (MetaType::lookupAlreadyRegistered(id)) + return id; + + QVariant (*lf)(const QVariant &, const QString &) + = LookupTrait::doLookUp; + + MetaType::registerLookUpOperator( + id, reinterpret_cast(lf)); + + return id; +} + +/* + Register a type so grantlee knows how to handle it. + */ +template struct InternalRegisterType { + static int doReg() + { + const int id = qMetaTypeId(); + return doRegister(id); + } +}; + +template +struct InternalRegisterType { + static int doReg() + { + const int id = qMetaTypeId(); + return doRegister(id); + } +}; +} + +/** + @brief Registers the type RealType with the metatype system. + + This method can take a second template parameter to specify a cast + that should be invoked during registration. This is useful if a base type is + already supported. + + @code + class SomeType + { + public: + QString someProp() const; + }; + + // define some introspectable API for SomeType + + GRANTLEE_BEGIN_LOOKUP(SomeType) + if (property == "someProp") + return object.someProp(); + GRANTLEE_END_LOOKUP + + + class OtherType : public SomeType + { + // ... + }; + + registerMetaType(); + + // Only the introspectable API from SomeType is needed, so we can reuse that + registration. + registerMetaType(); + @endcode + + @see @ref generic_types_and_templates + */ +template int registerMetaType() +{ + MetaType::internalLock(); + + const int id = InternalRegisterType::doReg(); + + MetaType::internalUnlock(); + + return id; +} + +#ifndef Q_QDOC +/** + @internal + Register a type so %Grantlee knows how to handle it. + + This is a convenience method. + */ +template int registerMetaType() +{ + return registerMetaType(); +} + +#endif +} // namespace Grantlee + +/** + Top boundary of a lookup function for Type. + + @see @ref generic_types + */ +#define GRANTLEE_BEGIN_LOOKUP(Type) \ + namespace Grantlee \ + { \ + template <> \ + inline QVariant TypeAccessor::lookUp(const Type &object, \ + const QString &property) \ + { + +/** + Top boundary of a lookup function for Type*. + + @see @ref generic_types + */ +#define GRANTLEE_BEGIN_LOOKUP_PTR(Type) \ + namespace Grantlee \ + { \ + template <> \ + inline QVariant TypeAccessor::lookUp(const Type *const object, \ + const QString &property) \ + { + +/** + Bottom boundary of a lookup function for Type. + + @see @ref generic_types + */ +#define GRANTLEE_END_LOOKUP \ + return QVariant(); \ + } \ + } + +#endif // #define GRANTLEE_METATYPE_H diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/node.h b/qt6-after/qt6-migrated-legatus/include/grantlee/node.h new file mode 100644 index 000000000..56be517b4 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/node.h @@ -0,0 +1,380 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_NODE_H +#define GRANTLEE_NODE_H + +// krazy:excludeall=dpointer + +#include "context.h" +#include "filterexpression.h" +#include "grantlee_templates_export.h" +#include "outputstream.h" +#include "safestring.h" + +#include + +// Need these for inheriting from QList to work +// http://lists.trolltech.com/qt-interest/2008-01/thread00578-0.html +#include +#include + +namespace Grantlee +{ + +class Engine; +class NodeList; +class TemplateImpl; + +class NodePrivate; + +/// @headerfile node.h grantlee/node.h + +/** + @brief Base class for all nodes. + + The **%Node** class can be implemented to make additional functionality + available to Templates. + + A node is represented in template markup as content surrounded by percent + signed tokens. + + @code + text content + {% some_tag arg1 arg2 %} + text content + {% some_other_tag arg1 arg2 %} + text content + {% end_some_other_tag %} + text content + @endcode + + This is parsed into a tree of **%Node** objects by an implementation of + AbstractNodeFactory. The **%Node** objects can then later be rendered by their + @ref render method. + + Rendering a **%Node** will usually mean writing some output to the stream. The + content written to the stream could be determined by the arguments to the tag, + or by the content of child nodes between a start and end tag, or both. + + @see FilterExpression + @see @ref tags + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT Node : public QObject +{ + Q_OBJECT +public: + /** + Constructor. + + @param parent The parent QObject + */ + explicit Node(QObject *parent = {}); + + /** + Destructor. + */ + ~Node() override; + + /** + Reimplement this to render the template in the Context @p c. + + This will also involve calling render on and child nodes. + */ + virtual void render(OutputStream *stream, Context *c) const = 0; + +#ifndef Q_QDOC + /** + @internal + */ + virtual bool mustBeFirst() + { // krazy:exclude:inline + return false; + } +#endif + +protected: + /** + Renders the value @p input in the Context @p c. This will involve escaping + @p input if necessary. + + This is only relevant to developing template tags. + */ + void streamValueInContext(OutputStream *stream, const QVariant &input, + Grantlee::Context *c) const; + + /** + Returns a raw pointer to the Template this **%Node** is in. + */ + TemplateImpl *containerTemplate() const; + +private: + Q_DECLARE_PRIVATE(Node) + NodePrivate *const d_ptr; +}; + +/// @headerfile node.h grantlee/node.h + +/** + @brief A list of Nodes with some convenience API for rendering them. + + Typically, tags which have an end tag will create and later render a list of + child nodes. + + This class contains API such as @ref append and @ref render to make creating + such list easily. + + The @ref findChildren method behaves similarly to the QObject::findChildren + method, returning a list of nodes of a particular type from the Node objects + contained in the list (and their children). + + @see @ref tags_with_end_tags +*/ +class GRANTLEE_TEMPLATES_EXPORT NodeList : public QList +{ +public: + /** + Creates an empty **%NodeList**. + */ + NodeList(); + + /** + Copy constructor. + */ + NodeList(const NodeList &list); + + NodeList &operator=(const NodeList &list); + + /** + Convenience constructor + */ + /* implicit */ NodeList(const QList &list); + + /** + Destructor. + */ + ~NodeList(); + + /** + Appends @p node to the end of this **%NodeList**. + */ + void append(Grantlee::Node *node); + + /** + Appends @p nodeList to the end of this **%NodeList**. + */ + void append(QList nodeList); + + /** + Returns true if this **%NodeList** contains non-text nodes. + */ + bool containsNonText() const; + + /** + A recursive listing of nodes in this tree of type @p T. + */ + template QList findChildren() + { + QList children; + QList::const_iterator it; + const QList::const_iterator first = constBegin(); + const QList::const_iterator last = constEnd(); + for (it = first; it != last; ++it) { + T object = qobject_cast(*it); + if (object) { + children << object; + } + children << (*it)->findChildren(); + } + return children; + } + + /** + Renders the list of Nodes in the Context @p c. + */ + void render(OutputStream *stream, Context *c) const; + +private: + bool m_containsNonText; +}; + +class AbstractNodeFactoryPrivate; + +/// @headerfile node.h grantlee/node.h + +/** + @brief Base class for all NodeFactories + + This class can be used to make custom tags available to templates. + The getNode method should be implemented to return a Node to be rendered. + + A node is represented in template markup as content surrounded by percent + signed tokens. + + @code + text content + {% some_tag arg1 arg2 %} + text content + {% some_other_tag arg1 arg2 %} + text content + {% end_some_other_tag %} + text content + @endcode + + It is the responsibility of an **%AbstractNodeFactory** implementation to + process the contents of a tag and return a Node implementation from its + getNode method. + + The @ref getNode method would for example be called with the tagContent + \"some_tag arg1 arg2\". That content could then be split up, the + arguments processed and a Node created + + @code + Node* SomeTagFactory::getNode(const QString &tagContent, Parser *p) { + QStringList parts = smartSplit( tagContent ); + + parts.removeFirst(); // Remove the "some_tag" part. + + FilterExpression arg1( parts.first(), p ); + FilterExpression arg2( parts.at( 1 ), p ); + + return new SomeTagNode( arg1, arg2, p ); + } + @endcode + + The @ref getNode implementation might also advance the parser. For example if + we had a @gr_tag{times} tag which rendered content the amount of times it was + given in its argument, it could be used like this: + + @code + Some text content. + {% times 5 %} + the bit to be repeated + {% end_times %} + End text content + @endcode + + The argument to @gr_tag{times} might not be a simple number, but could be a + FilterExpression such as \"someobject.some_property|getDigit:1\". + + The implementation could look like + + @code + Node* SomeOtherTagFactory::getNode(const QString &tagContent, Parser *p) { + QStringList parts = smartSplit( tagContent ); + + parts.removeFirst(); // Remove the "times" part. + + FilterExpression arg( parts.first(), p ); + + auto node = new SomeTagNode( arg, p ); + auto childNodes = p->parse( node, "end_times" ); + node->setChildNodes( childNodes ); + p->removeNextToken(); + + return node; + } + @endcode + + Note that it is necessary to invoke the parser to create the child nodes only + after creating the Node to return. That node must be passed to the Parser to + perform as the parent QObject to the child nodes. + + @see Parser::parse +*/ +class GRANTLEE_TEMPLATES_EXPORT AbstractNodeFactory : public QObject +{ + Q_OBJECT +public: + /** + Constructor. + + @param parent The parent QObject + */ + explicit AbstractNodeFactory(QObject *parent = {}); + + /** + Destructor. + */ + ~AbstractNodeFactory() override; + + /** + This method should be reimplemented to return a Node which can be + rendered. + + The @p tagContent is the content of the tag including the tag name and + arguments. For example, if the template content is @gr_tag{my_tag arg1 + arg2}, the tagContent will be "my_tag arg1 arg2". + + The Parser @p p is available and can be advanced if appropriate. For + example, if the tag has an end tag, the parser can be advanced to the end + tag. + + @see tags + */ + virtual Node *getNode(const QString &tagContent, Parser *p) const = 0; + +#ifndef Q_QDOC + /** + @internal + + Sets the Engine which created this NodeFactory. Used by the + ScriptableNodeFactory. + */ + virtual void setEngine(Engine *) {} +#endif + +protected: + /** + Splits @p str into a list, taking quote marks into account. + + This is typically used in the implementation of getNode with the + tagContent. + + If @p str is 'one "two three" four 'five " six' seven', the + returned list will contain the following strings: + + - one + - "two three" + - four + - five " six + - seven + */ + Q_INVOKABLE QStringList smartSplit(const QString &str) const; + +protected: + /** + Returns a list of FilterExpression objects created with Parser @p p as + described by the content of @p list. + + This is used for convenience when handling the arguments to a tag. + */ + QList getFilterExpressionList(const QStringList &list, + Parser *p) const; + +private: + Q_DECLARE_PRIVATE(AbstractNodeFactory) + AbstractNodeFactoryPrivate *const d_ptr; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/outputstream.h b/qt6-after/qt6-migrated-legatus/include/grantlee/outputstream.h new file mode 100644 index 000000000..d8cb6a46b --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/outputstream.h @@ -0,0 +1,145 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_OUTPUTSTREAM_H +#define GRANTLEE_OUTPUTSTREAM_H + +#include "grantlee_templates_export.h" + +#include +#include + +namespace Grantlee +{ + +class SafeString; + +/// @headerfile outputstream.h grantlee/outputstream.h + +/** + @brief The **%OutputStream** class is used to render templates to a + QTextStream + + A **%OutputStream** instance may be passed to the render method of a Template + to render the template to a stream. + + @code + QFile outputFile("./output"); + outputFile.open(QFile::WriteOnly); + QTextStream tstream( &outputFile ); + + OutputStream os(&tstream); + t->render( &os, &context ); + @endcode + + The **%OutputStream** is used to escape the content streamed to it. By + default, the escaping is html escaping, converting "&" to "&" for example. + If generating non-html output, the @ref escape method may be overriden to + perform a different escaping, or non at all. + + If overriding the @ref escape method, the @ref clone method must also be + overriden to return an **%OutputStream** with the same escaping behaviour. + + @code + class NoEscapeStream : public Grantlee::OutputStream + { + public: + // ... + + QString escape( const QString &input ) const + { + return input; + } + + QSharedPointer clone( QTextStream *stream ) const + { + return QSharedPointer::create( stream ); + } + }; + @endcode + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT OutputStream +{ +public: + /** + Creates a null **%OutputStream**. Content streamed to + this **%OutputStream** is sent to /dev/null + */ + OutputStream(); + + /** + Creates an **%OutputStream** which will stream content to @p stream + with appropriate escaping. + */ + explicit OutputStream(QTextStream *stream); + + /** + Destructor + */ + virtual ~OutputStream(); + + /** + Returns an escaped version of @p input. Does not write anything to the + stream. + */ + virtual QString escape(const QString &input) const; + + /** + Returns an escaped version of @p input. Does not write anything to the + stream. + */ + QString escape(const SafeString &input) const; + + /** + Returns a cloned **%OutputStream** with the same filtering behaviour. + */ + virtual QSharedPointer clone(QTextStream *stream) const; + + /** + Returns @p after escaping it, unless @p input is "safe", in which case, + @p input is returned unmodified. + */ + QString conditionalEscape(const Grantlee::SafeString &input) const; + + /** + Writes @p input to the stream after escaping it. + */ + OutputStream &operator<<(const QString &input); + + /** + Writes @p input to the stream after escaping it if necessary. + */ + OutputStream &operator<<(const SafeString &input); + + /** + Reads the content of @p stream and writes it unmodified to the result + stream. + */ + OutputStream &operator<<(QTextStream *stream); + +private: + QTextStream *m_stream; + Q_DISABLE_COPY(OutputStream) +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/parser.h b/qt6-after/qt6-migrated-legatus/include/grantlee/parser.h new file mode 100644 index 000000000..3e54aeb70 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/parser.h @@ -0,0 +1,144 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_PARSER_H +#define GRANTLEE_PARSER_H + +#include "filter.h" +#include "node.h" +#include "token.h" + +#include + +namespace Grantlee +{ +class TemplateImpl; + +class ParserPrivate; + +/// @headerfile parser.h grantlee/parser.h + +/** + @brief The **%Parser** class processes a string template into a tree of nodes. + + For application developers, this class is internal. + + For template tag authors it may be necessary to advance the parser and process + contained tags if the tag works in a tag -- endtag fashion. + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT Parser : public QObject +{ + Q_OBJECT +public: + /** + Constructor. + + Initialises the **%Parser** with the @p tokenList. + */ + Parser(const QList &tokenList, QObject *parent); + + /** + Destructor. + */ + ~Parser() override; + + /** + Advance the parser, using @p parent as the parent of new Nodes. The parser + will stop if it encounters a tag which is contained in the list @p stopAt. + + For example, the @gr_tag{if} tag would stopAt both @gr_tag{endif} and + @gr_tag{else} tags. + + @see AbstractNodeFactory::getNode + */ + NodeList parse(Node *parent, const QStringList &stopAt = {}); + + /** + This is an overloaded method. + @see parse. + */ + NodeList parse(TemplateImpl *parent, const QStringList &stopAt = {}); + + /** + This is an overloaded method. + @see parse. + */ + NodeList parse(Node *parent, const QString &stopAt); + + /** + Returns the filter object called @p name or an invalid object if no filter + with that name is loaded. + */ + QSharedPointer getFilter(const QString &name) const; + + /** + Advances the parser to the tag @p tag. This method is similar to @ref parse, + but it does not create nodes for tags encountered. + */ + void skipPast(const QString &tag); + + /** + Returns the next token to be processed by the parser. This can be examined + in template tag implementations to determine why parsing stopped. + + For example, if the @gr_tag{if} tag, parsing may stop at an @gr_tag{else} + tag, in which case parsing should be restarted, or it could stop at an + @gr_tag{endif} tag, in which case parsing is finished for that node. + */ + Token takeNextToken(); + + /** + Returns whether the parser has another token to process. + */ + bool hasNextToken() const; + + /** + Deletes the next token available to the parser. + */ + void removeNextToken(); + + void invalidBlockTag(const Token &token, const QString &command, + const QStringList &stopAt = {}); + +#ifndef Q_QDOC + /** + @internal + + Used by the @gr_tag{load} tag to load libraries. + */ + void loadLib(const QString &name); +#endif + +protected: + /** + Puts the token @p token to the front of the list to be processed by the + parser. + */ + void prependToken(const Token &token); + +private: + Q_DECLARE_PRIVATE(Parser) + ParserPrivate *const d_ptr; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/plaintextmarkupbuilder.h b/qt6-after/qt6-migrated-legatus/include/grantlee/plaintextmarkupbuilder.h new file mode 100644 index 000000000..bee0dfc8a --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/plaintextmarkupbuilder.h @@ -0,0 +1,211 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2008 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_PLAINTEXTMARKUPBUILDER_H +#define GRANTLEE_PLAINTEXTMARKUPBUILDER_H + +#ifdef Q_OS_WIN +#pragma warning(disable : 4250) +#endif + +#define LETTERSINALPHABET 26 +#define DIGITSOFFSET 10 + +#include "abstractmarkupbuilder.h" +#include "grantlee_textdocument_export.h" +#include "markupdirector.h" + +class QBrush; + +namespace Grantlee +{ + +class PlainTextMarkupBuilderPrivate; + +/// @headerfile plaintextmarkupbuilder.h grantlee/plaintextmarkupbuilder.h + +/** + @brief Creates a simple marked up plain text document + + This class creates a simple plain text markup. + + Text that may be represented as + + @code + A paragraph with bold text, italic text, + and underlined text. + @endcode + + would be output as + + @code + A paragraph with *bold* text /italic/ text, + and _underlined_ text. + @endcode + + The markup is intended to be simple, plain and easily human readable. No + markup is created for different font-familiy, font-size, foreground or + background colors. + + Lists are marked up by preceding the list element with '*' for disc, 'o' for + circle, 'X' for square, or a letter or number. Lists are also indented if + nested. eg: + + @code + A. One + B. Two + o Three + o Four + \* Five + \* Six + C. Seven + @endcode + + External references such as external urls and images are represented in the + body text as a reference, and references are maintained at the bottom of the + output. + + Eg, + @code + Here is a link to KDE and + the KDEPIM project. + @endcode + + becomes: + + @code + Here is a link to KDE[1], and + the KDEPIM project[2]. + + ---- References ---- + [1] http://www.kde.org + [2] http://pim.kde.org + @endcode + + @author Stephen Kelly +*/ +class GRANTLEE_TEXTDOCUMENT_EXPORT PlainTextMarkupBuilder + : virtual public AbstractMarkupBuilder +{ +public: + PlainTextMarkupBuilder(); + + ~PlainTextMarkupBuilder() override; + + void beginStrong() override; + void endStrong() override; + void beginEmph() override; + void endEmph() override; + void beginUnderline() override; + void endUnderline() override; + void beginStrikeout() override; + void endStrikeout() override; + + void beginAnchor(const QString &href = {}, const QString &name = {}) override; + + void endAnchor() override; + + void beginForeground(const QBrush &brush) override; + + void endForeground() override; + + void beginBackground(const QBrush &brush) override; + + void endBackground() override; + + void beginFontFamily(const QString &family) override; + + void endFontFamily() override; + + void beginFontPointSize(int size) override; + + void endFontPointSize() override; + + void beginParagraph(Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, + qreal bottom = 0.0, qreal left = 0.0, + qreal right = 0.0) override; + + void endParagraph() override; + void addNewline() override; + + void insertHorizontalRule(int width = -1) override; + + void insertImage(const QString &src, qreal width, qreal height) override; + + void beginList(QTextListFormat::Style style) override; + + void endList() override; + + void beginListItem() override; + + void endListItem() override; + + void beginSuperscript() override; + + void endSuperscript() override; + + void beginSubscript() override; + + void endSubscript() override; + + void beginTable(qreal cellpadding, qreal cellspacing, + const QString &width) override; + + void beginTableRow() override; + + void beginTableHeaderCell(const QString &width, int colSpan, + int rowSpan) override; + + void beginTableCell(const QString &width, int colSpan, int rowSpan) override; + + void endTable() override; + + void endTableRow() override; + + void endTableHeaderCell() override; + + void endTableCell() override; + + void beginHeader(int level) override; + + void endHeader(int level) override; + + void appendLiteralText(const QString &text) override; + + void appendRawText(const QString &text) override; + + /** + Adds a reference to @p reference to the internal list of references in the + document. + */ + int addReference(const QString &reference); + + /** + Returns the finalised plain text markup, including references at the end. + */ + QString getResult() override; + +private: + PlainTextMarkupBuilderPrivate *const d_ptr; + Q_DECLARE_PRIVATE(PlainTextMarkupBuilder) +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/qtlocalizer.h b/qt6-after/qt6-migrated-legatus/include/grantlee/qtlocalizer.h new file mode 100644 index 000000000..4d8ecdb4d --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/qtlocalizer.h @@ -0,0 +1,135 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_QTLOCALIZER_P_H +#define GRANTLEE_QTLOCALIZER_P_H + +#include "abstractlocalizer.h" + +class QTranslator; + +namespace Grantlee +{ + +class QtLocalizerPrivate; + +/** + @brief Provides internationalization based on QLocale and QTranslator. + + This class implements access to the %Qt Localization system. Localizable + types such as strings, numbers, dates and times can be processed. + + @code + auto t = m_engine->loadTemplate(someTemplate); + auto c = getContext(); + + // Render with the German locale + c.setLocalizer(m_de_Localizer); + auto deText = t->render(&c); + de_display->setText(deText); + + // Render with the French locale + c.setLocalizer(m_fr_Localizer); + auto frText = t->render(&c); + fr_display->setText(frText); + @endcode + +*/ +class GRANTLEE_TEMPLATES_EXPORT QtLocalizer : public AbstractLocalizer +{ +public: + /** + Constructs a new **%QtLocalizer** using the @p locale + */ + QtLocalizer(const QLocale &locale = QLocale::system()); + + /** + Destructor + */ + ~QtLocalizer() override; + + /** + Set the path to look for translations of the application strings. + */ + void setAppTranslatorPath(const QString &path); + + /** + Set the prefix of translation files. For example, if the German translation + file is called myapp_de_DE.qm, the prefix should be set to + myapp_. + */ + void setAppTranslatorPrefix(const QString &prefix); + + /** + Install a @p translator to use for a particular @p localeName. + + @code + auto deTranslator = new QTranslator(this); + auto loaded = deTranslator->load("myapp_de_DE"); + if (!loaded) + return; + + de_localizer->installTranslator(deTranslator, "de_DE"); + @endcode + */ + void installTranslator(QTranslator *translator, + const QString &localeName = QLocale::system().name()); + + QString currentLocale() const override; + void pushLocale(const QString &localeName) override; + void popLocale() override; + void loadCatalog(const QString &path, const QString &catalog) override; + void unloadCatalog(const QString &catalog) override; + + QString localizeNumber(int number) const override; + QString localizeNumber(qreal number) const override; + QString localizeMonetaryValue(qreal value, const QString ¤cyCode + = {}) const override; + QString localizeDate(const QDate &date, + QLocale::FormatType formatType + = QLocale::ShortFormat) const override; + QString localizeTime(const QTime &time, + QLocale::FormatType formatType + = QLocale::ShortFormat) const override; + QString localizeDateTime(const QDateTime &dateTime, + QLocale::FormatType formatType + = QLocale::ShortFormat) const override; + QString localizeString(const QString &string, + const QVariantList &arguments = {}) const override; + QString localizeContextString(const QString &string, const QString &context, + const QVariantList &arguments + = {}) const override; + QString localizePluralContextString(const QString &string, + const QString &pluralForm, + const QString &context, + const QVariantList &arguments + = {}) const override; + QString localizePluralString(const QString &string, const QString &pluralForm, + const QVariantList &arguments + = {}) const override; + +private: + Q_DECLARE_PRIVATE(QtLocalizer) + Q_DISABLE_COPY(QtLocalizer) + QtLocalizerPrivate *const d_ptr; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/rendercontext.h b/qt6-after/qt6-migrated-legatus/include/grantlee/rendercontext.h new file mode 100644 index 000000000..315102212 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/rendercontext.h @@ -0,0 +1,83 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_RENDERCONTEXT_H +#define GRANTLEE_RENDERCONTEXT_H + +#include "grantlee_templates_export.h" + +#include + +/// @headerfile rendercontext.h grantlee/rendercontext.h + +namespace Grantlee +{ + +class ContextPrivate; +class TemplateImpl; +class Node; + +class RenderContextPrivate; + +/** + @brief Provides storage facility for state while rendering a template. + + This class can not be instatiated by users of it. An instance + of **%RenderContext** is available through Context::renderContext() for use + with implementations of re-entrant template tags. + */ +class GRANTLEE_TEMPLATES_EXPORT RenderContext +{ +public: + /** + Returns the data for the node @p scopeNode. + */ + QVariant &data(const Node *const scopeNode); + + /** + Returns whether the **%RenderContext** contains data for @p scopeNode. + */ + bool contains(Node *const scopeNode) const; + + /** + Destructor + */ + ~RenderContext(); + +#ifndef Q_QDOC +private: + RenderContext(); + + void push(); + + void pop(); + +private: + friend class ContextPrivate; + friend class TemplateImpl; + + Q_DISABLE_COPY(RenderContext) + Q_DECLARE_PRIVATE(RenderContext) + RenderContextPrivate *const d_ptr; +#endif +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/safestring.h b/qt6-after/qt6-migrated-legatus/include/grantlee/safestring.h new file mode 100644 index 000000000..40f136440 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/safestring.h @@ -0,0 +1,436 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_SAFESTRING_H +#define GRANTLEE_SAFESTRING_H + +#include "grantlee_templates_export.h" + +#include +#include + +namespace Grantlee +{ + +/// @headerfile safestring.h grantlee/safestring.h + +/** + @brief A QString wrapper class for containing whether a string is safe or + needs to be escaped. + + This allows lazy escaping of strings. Otherwise a string may be escaped + multiple times where it should only be escaped once. + + The **%SafeString** class itself provides information about whether a string + is safe from further escaping through the @ref isSafe method. The actual + string content held by the **%SafeString** instance is available through the + @ref get method. The @ref get method returns a QString subclass which should + be used like any other QString. The difference is that all methods on + NestedString return a **%SafeString** instead of a QString. + + @code + SafeString s("this & that", SafeString::IsSafe); + s.get().replace( "this", "these" ).toUpper(); + + qDebug() << s.get() << s.isSafe(); // outputs "these & that" false + @endcode + + Note that most operations on strings make the string unsafe. For example, + while "K & R" is safe, using replace("m", "n") will result in + "K &anp; R", which is unsafe. Likewise using upper() will return + "K & R", which is unsafe. Because the **%SafeString** can not + determine whether a method call with particular arguments will change + a **%SafeString** from being safe to being unsafe, any operation which can + possibly make the string unsafe does cause the string to become unsafe. It is + then up to the caller to restore safe-ness if needed. + + NestedString has overloads for SafeStrings whereever appropriate so that + strings remain marked as safe where possible. + + For example: + + @code + SafeString s1("this & that", SafeString::IsSafe); + s2 = s1; + s1.append( QString( " & the other" ) ); + // s1 is now "this & that & the other" and is unsafe. + + SafeString s3(" Wobl & Bob", SafeString::IsSafe); + s2.append(s3); + // Both s2 and s3 are safe, and append is a safe operation, so s2 + // is still safe + @endcode + + @see @ref autoescaping + @see OutputStream::escape + + The **%SafeString** class has appropriate operator overloads to make it + convenient to use in methods returning a QVariant, such as Filter::doFilter, + or as a QString. Note that a raw QString is essentially the same + as a **%SafeString** which is marked as unsafe. + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT SafeString +{ +public: + /** + Possible safety states of a **%SafeString** + */ + enum Safety { + IsSafe, ///< The string is safe and requires no further escaping + IsNotSafe ///< The string is not safe. It will be escaped before being + /// added to the output of rendering. + }; + + /** + Constructs an empty **%SafeString**. + */ + SafeString(); + + /** + Copy constructor + */ + SafeString(const SafeString &safeString); + + /** + Constructs a **%SafeString** with the content @p str whose safety is given + by @p safe. + */ + SafeString(const QString &str, bool safe); + + /** + Constructs a **%SafeString** with the content @p str whose safety is given + by @p safety. + */ + /* implicit */ SafeString(const QString &str, + Safety safety + = IsNotSafe); // krazy:exclude=explicit + + /** + Destructor + */ + ~SafeString(); + +#ifndef Q_QDOC + /** + Set whether the string should be escaped. + */ + void setNeedsEscape(bool needsEscape); +#endif + + /** + Whether the string needs to be escaped. + */ + bool needsEscape() const; + + /** + Whether the string is safe. + */ + bool isSafe() const; + +#ifndef Q_QDOC + /** + Set whether the string is safe. + */ + void setSafety(Safety safety); +#endif + + /** + @brief The NestedString is a QString whose methods always return a + SafeString + + This class is largely an implementation detail. See the SafeString + documentation for details. + */ + class GRANTLEE_TEMPLATES_EXPORT NestedString : public QString + { +#ifndef Q_QDOC + friend class SafeString; + SafeString *m_safeString; + + public: + NestedString(SafeString *safeString); + NestedString(const QString &content, SafeString *safeString); + + SafeString &append(const SafeString &str); + SafeString &append(const QString &str); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + SafeString &append(const QStringRef &ref); +#endif + SafeString &append(const QLatin1String &str); +#ifndef QT_NO_CAST_FROM_ASCII + SafeString &append(const QByteArray &ba) + { + QString::append(ba); + m_safeString->m_safety = IsNotSafe; + return *m_safeString; + } + + SafeString &append(const char *str) + { + QString::append(str); + m_safeString->m_safety = IsNotSafe; + return *m_safeString; + } +#endif + SafeString &append(const QChar ch); + + SafeString &fill(QChar ch, int size = -1); + + SafeString &insert(int position, const SafeString &str); + SafeString &insert(int position, const QString &str); + SafeString &insert(int position, const QLatin1String &str); + SafeString &insert(int position, const QChar *unicode, int size); + SafeString &insert(int position, QChar ch); + + SafeString left(int n) const; + SafeString leftJustified(int width, QChar fill = QLatin1Char(' '), + bool truncate = {}) const; + SafeString mid(int position, int n = -1) const; + + SafeString normalized(NormalizationForm mode) const; + SafeString normalized(NormalizationForm mode, + QChar::UnicodeVersion version) const; + + SafeString &prepend(const SafeString &str); + SafeString &prepend(const QString &str); + SafeString &prepend(const QLatin1String &str); +#ifndef QT_NO_CAST_FROM_ASCII + SafeString &prepend(const QByteArray &ba) + { + QString::prepend(ba); + m_safeString->m_safety = IsNotSafe; + return *m_safeString; + } + + SafeString &prepend(const char *str) + { + QString::prepend(str); + m_safeString->m_safety = IsNotSafe; + return *m_safeString; + } +#endif + SafeString &prepend(QChar ch); + + void push_back(const SafeString &other); + void push_front(const SafeString &other); + + SafeString &remove(int position, int n); + SafeString &remove(QChar ch, Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &remove(const SafeString &str, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &remove(const QString &str, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &remove(const QRegularExpression &rx); + SafeString repeated(int times) const; + SafeString &replace(int position, int n, const SafeString &after); + SafeString &replace(int position, int n, const QString &after); + SafeString &replace(int position, int n, const QChar *unicode, int size); + SafeString &replace(int position, int n, QChar after); + SafeString &replace(const SafeString &before, const SafeString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QString &before, const SafeString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const SafeString &before, const QString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QString &before, const QString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QChar *before, int blen, const QChar *after, + int alen, Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(QChar ch, const SafeString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(QChar ch, const QString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(QChar before, QChar after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QLatin1String &before, const QLatin1String &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QLatin1String &before, const SafeString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QLatin1String &before, const QString &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const SafeString &before, const QLatin1String &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QString &before, const QLatin1String &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(QChar c, const QLatin1String &after, + Qt::CaseSensitivity cs = Qt::CaseSensitive); + SafeString &replace(const QRegularExpression &rx, const SafeString &after); + SafeString &replace(const QRegularExpression &rx, const QString &after); + + SafeString right(int n) const; + SafeString rightJustified(int width, QChar fill = QLatin1Char(' '), + bool truncate = {}) const; + + SafeString section(QChar sep, int start, int end = -1, + SectionFlags flags = SectionDefault) const; + SafeString section(const SafeString &sep, int start, int end = -1, + SectionFlags flags = SectionDefault) const; + SafeString section(const QString &sep, int start, int end = -1, + SectionFlags flags = SectionDefault) const; + SafeString section(const QRegularExpression ®, int start, int end = -1, + SectionFlags flags = SectionDefault) const; + SafeString &setNum(int n, int base = 10); + SafeString &setNum(uint n, int base = 10); + SafeString &setNum(long n, int base = 10); + SafeString &setNum(ulong n, int base = 10); + SafeString &setNum(qlonglong n, int base = 10); + SafeString &setNum(qulonglong n, int base = 10); + SafeString &setNum(short n, int base = 10); + SafeString &setNum(ushort n, int base = 10); + SafeString &setNum(double n, char format = 'g', int precision = 6); + SafeString &setNum(float n, char format = 'g', int precision = 6); + SafeString &setUnicode(const QChar *unicode, int size); + SafeString &setUtf16(const ushort *unicode, int size); + SafeString simplified() const; + + // QT_DEPRECATED_SINCE(5, 15) to support consumers building with + // -DQT_DISABLE_DEPRECATED_BEFORE=0x050f00 + // where QString enums will be invisible to the compiler +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT_DEPRECATED_SINCE(5, 15) + // Calls with default argument for "behavior" should pick the Qt >= 5.14 + // version, if available +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QStringList split(const SafeString &sep, QString::SplitBehavior behavior, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QString &sep, QString::SplitBehavior behavior, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QChar &sep, QString::SplitBehavior behavior, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QRegularExpression &rx, + QString::SplitBehavior behavior) const; +#else + QStringList split(const SafeString &sep, + QString::SplitBehavior behavior = QString::KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QString &sep, + QString::SplitBehavior behavior = QString::KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QChar &sep, + QString::SplitBehavior behavior = QString::KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QRegularExpression &rx, + QString::SplitBehavior behavior + = QString::KeepEmptyParts) const; +#endif +#endif + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QStringList split(const SafeString &sep, + Qt::SplitBehavior behavior = Qt::KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QString &sep, + Qt::SplitBehavior behavior = Qt::KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QChar &sep, + Qt::SplitBehavior behavior = Qt::KeepEmptyParts, + Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + QStringList split(const QRegularExpression &rx, + Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const; +#endif + + SafeString toLower() const; + SafeString toUpper() const; + SafeString trimmed() const; + + void chop(int n); +#endif + }; + + /** + Returns the String held by this **%SafeString** + */ + const NestedString &get() const { return m_nestedString; } + + /** + Returns the String held by this **%SafeString** + */ + NestedString &get() { return m_nestedString; } + + /** + Convenience operator for treating a **%SafeString** like a QString. + */ + operator QString() const { return m_nestedString; } + + /** + Assignment operator. + */ + SafeString &operator=(const SafeString &str); + + /** + Returns a concatenation of this with @p str. + + The result is not safe because str is not safe. + */ + SafeString operator+(const QString &str); + + /** + Returns a concatenation of this with @p str. + + The result is safe if both this and str are safe. + */ + SafeString operator+(const SafeString &str); + + /** + Appends the content of @p str to this. + + The result is not safe because @p str is not safe. + */ + SafeString &operator+=(const QString &str); + + /** + Appends the content of @p str to this. + + The result is safe if both this and @p str are safe. + */ + SafeString &operator+=(const SafeString &str); + + /** + Returns true if the content of @p other matches the content of this. + + Safeness and needing escaping are not accounted for in the comparison. + */ + bool operator==(const SafeString &other) const; + + /** + Returns true if the content of @p other matches the content of this. + + Safeness and needing escaping are not accounted for in the comparison. + */ + bool operator==(const QString &other) const; + + /** + Convenience operator for storing a **%SafeString** in a QVariant. + */ + operator QVariant() const { return QVariant::fromValue(*this); } + +private: +#ifndef Q_QDOC + NestedString m_nestedString; +#endif + Safety m_safety; + bool m_needsescape; +}; +} + +Q_DECLARE_METATYPE(Grantlee::SafeString) + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/taglibraryinterface.h b/qt6-after/qt6-migrated-legatus/include/grantlee/taglibraryinterface.h new file mode 100644 index 000000000..a03e46a66 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/taglibraryinterface.h @@ -0,0 +1,110 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef TAGLIBRARYINTERFACE_H +#define TAGLIBRARYINTERFACE_H + +#include "outputstream.h" + +#include +#include + +namespace Grantlee +{ +class AbstractNodeFactory; +class Engine; +class Filter; + +/// @headerfile taglibraryinterface.h grantlee/taglibraryinterface.h + +/** + @brief The **%TagLibraryInterface** returns available tags and filters from + libraries. + + This interface must be implemented in tag and filter libraries. + + The implementation will usually be very simple. + + @code + class MyTagLibrary : public QObject, public TagLibraryInterface + { + Q_OBJECT + Q_INTERFACES( Grantlee::TagLibraryInterface ) + public: + MyTagLibrary( QObject *parent = {} ) + : QObject( parent ) { + } + + QHash + nodeFactories(const QString &name = {}) { + Q_UNUSED( name ); + QHash nodeFactories; + nodeFactories.insert( "mytag1", new MyTag1() ); + nodeFactories.insert( "mytag2", new MyTag2() ); + return nodeFactories; + } + + QHash filters( const QString &name = {} ) { + Q_UNUSED( name ); + + QHash filters; + + filters.insert( "myfilter1", new MyFilter1() ); + filters.insert( "myfilter2", new MyFilter2() ); + + return filters; + } + }; + @endcode + + @author Stephen Kelly +*/ +class TagLibraryInterface +{ +public: + virtual ~TagLibraryInterface() {} + + /** + Returns the AbstractNodeFactory implementations available in this library. + */ + virtual QHash + nodeFactories(const QString &name = {}) + { + Q_UNUSED(name); + static const QHash h; + return h; + }; + + /** + Returns the Filter implementations available in this library. + */ + virtual QHash filters(const QString &name = {}) + { + Q_UNUSED(name); + static const QHash h; + return h; + }; +}; +} + +Q_DECLARE_INTERFACE(Grantlee::TagLibraryInterface, + "org.grantlee.TagLibraryInterface/1.0") + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/template.h b/qt6-after/qt6-migrated-legatus/include/grantlee/template.h new file mode 100644 index 000000000..937c906f5 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/template.h @@ -0,0 +1,161 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_TEMPLATE_H +#define GRANTLEE_TEMPLATE_H + +#include "exception.h" +#include "grantlee_templates_export.h" +#include "node.h" + +#include +#include + +namespace Grantlee +{ +class Context; +class Engine; +class TemplateImpl; +class OutputStream; + +#ifdef Q_QDOC +#define TemplateImpl Template +#else +typedef QSharedPointer Template; +#endif + +class TemplatePrivate; + +/// @headerfile template.h grantlee/template.h + +/** + @brief The **%Template** class is a tree of nodes which may be rendered. + + All Templates are created through the Grantlee::Engine class. + A **%Template** is created by parsing some text markup passed into the Engine, + or by reading it from a file. + + Note that **%Template** is actually a typedef for a + QSharedPointer<TemplateImpl>, so all of its members should be + accessed with operator->(). + + The result of parsing is a **%Template** object which can be rendered multiple + times with multiple different Contexts. + + @code + auto engine = getEngine(); + auto t = engine->newTemplate( + "{{ name }} is aged {{ age }}", + "simple template" ); + if ( t->error() ) + { + // Tokenizing or parsing error, or couldn't find custom tags or filters. + qDebug() << t->errorString(); + return; + } + QTextStream textStream( stdout ); + OutputStream stream( textStream ); + + for ( ... ) + { + Context c; + // ... c.insert + t->render( stream, c ); + + if (t->error()) + { + // Rendering error. + qDebug() << t->errorString(); + } + } + @endcode + + If there is an error in parsing or rendering, the @ref error and @ref + errorString methods can be used to check the source of the error. + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT TemplateImpl : public QObject +{ + Q_OBJECT +public: + ~TemplateImpl() override; + + /** + Renders the **%Template** to a string given the Context @p c. + */ + QString render(Context *c) const; + + /** + Renders the **%Template** to the OutputStream @p stream given the Context c. + */ + OutputStream *render(OutputStream *stream, Context *c) const; + +#ifndef Q_QDOC + /** + @internal + */ + NodeList nodeList() const; + + /** + @internal + */ + void setNodeList(const NodeList &list); +#endif + + /** + Returns an error code for the error encountered. + */ + Error error() const; + + /** + Returns more information to developers in the form of a string. + */ + QString errorString() const; + + /** + Returns the Engine that created this **%Template**. + */ + Engine const *engine() const; + +#ifndef Q_QDOC +protected: + TemplateImpl(Engine const *engine, QObject *parent = {}); + TemplateImpl(Engine const *engine, bool smartTrim, QObject *parent = {}); + + void setContent(const QString &templateString); +#endif + +private: + // Don't allow setting the parent on a Template, which is memory managed as + // a QSharedPointer. + using QObject::setParent; + +private: + Q_DECLARE_PRIVATE(Template) + TemplatePrivate *const d_ptr; +#ifndef Q_QDOC + friend class Engine; + friend class Parser; +#endif +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/templateloader.h b/qt6-after/qt6-migrated-legatus/include/grantlee/templateloader.h new file mode 100644 index 000000000..5b09c9bf5 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/templateloader.h @@ -0,0 +1,229 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_TEMPLATELOADER_H +#define GRANTLEE_TEMPLATELOADER_H + +#include "grantlee_templates_export.h" +#include "template.h" + +#include + +namespace Grantlee +{ + +class AbstractLocalizer; + +/// @headerfile templateloader.h grantlee/templateloader.h + +/** + @brief An retrieval interface to a storage location for Template objects. + + This interface can be implemented to define new ways of retrieving the content + of Templates. + + The interface of this class should not be called directly from applications. + TemplateLoaders will typically be created, configured and added to the + Grantlee::Engine which will call the appropriate API. + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT AbstractTemplateLoader +{ +public: + /** + Destructor + */ + virtual ~AbstractTemplateLoader(); + + /** + Load a Template called @p name. Return an invalid Template if no content + by that name exists. + */ + virtual Template loadByName(const QString &name, + Engine const *engine) const = 0; + + /** + Return a complete URI for media identified by fileName. + */ + virtual QPair + getMediaUri(const QString &fileName) const = 0; + + /** + Return true if a Template identified by @p name exists and can be loaded. + */ + virtual bool canLoadTemplate(const QString &name) const = 0; +}; + +/// @headerfile templateloader.h grantlee/templateloader.h + +class FileSystemTemplateLoaderPrivate; + +/** + @brief The **%FileSystemTemplateLoader** loads Templates from the file system. + + This template loader works by traversing a list of directories to find + templates. Directories are checked in order, and the first match hit is parsed + and returned. + + @code + loader->setTemplateDirs({ + "/home/user/app/templates", + "/usr/local/share/app/templates" + }); + engine->setTemplateLoader( loader ); + + // This will try /home/user/app/templates/mytemplate.html + // followed by /usr/local/share/app/templates/mytemplate.html + engine->loadByName( "mytemplate.html" ); + @endcode + + Additionally, a themeName may be set on the template loader, which will be + appended to search paths before the template name. + + @code + loader->setTemplateDirs({ + "/home/user/app/templates" << + "/usr/local/share/app/templates" + }); + loader->setTheme( "simple_theme" ); + engine->setTemplateLoader( loader ); + + // This will try /home/user/app/templates/simple_theme/mytemplate.html + // followed by /usr/local/share/app/templates/simple_theme/mytemplate.html + engine->loadByName( "mytemplate.html" ); + @endcode + + Media URIs may be retrieved for media relative to the directories searched + queried for templates. + + @code + loader->setTemplateDirs({ + "/home/user/app/templates", + "/usr/local/share/app/templates" + }); + loader->setTheme( "simple_theme" ); + engine->setTemplateLoader( loader ); + + // This will try /home/user/app/templates/simple_theme/logo.png + // followed by /usr/local/share/app/templates/simple_theme/logo.png + // and return the first one that exists. + engine->mediaUri( "logo.png" ); + @endcode + + The template files loaded by a %**FileSystemTemplateLoader** must be UTF-8 + encoded. + + @see @ref deploying_templates + +*/ +class GRANTLEE_TEMPLATES_EXPORT FileSystemTemplateLoader + : public AbstractTemplateLoader +{ +public: + /** + Constructor + */ + FileSystemTemplateLoader(const QSharedPointer localizer + = {}); + + /** + Destructor + */ + ~FileSystemTemplateLoader() override; + + Template loadByName(const QString &name, Engine const *engine) const override; + + bool canLoadTemplate(const QString &name) const override; + + QPair getMediaUri(const QString &fileName) const override; + + /** + Sets the theme of this loader to @p themeName + */ + void setTheme(const QString &themeName); + + /** + The themeName of this TemplateLoader + */ + QString themeName() const; + + /** + Sets the directories to look for template files to @p dirs. + */ + void setTemplateDirs(const QStringList &dirs); + + /** + The directories this TemplateLoader looks in for template files. + */ + QStringList templateDirs() const; + +private: + Q_DECLARE_PRIVATE(FileSystemTemplateLoader) + FileSystemTemplateLoaderPrivate *const d_ptr; +}; + +/// @headerfile templateloader.h grantlee/templateloader.h + +/** + @brief The **%InMemoryTemplateLoader** loads Templates set dynamically in + memory + + This class is mostly used for testing purposes, but can also be used for + simple uses of %Grantlee. + + Templates can be made available using the @ref setTemplate method, and will + then be retrieved by the Grantlee::Engine as appropriate. +*/ +class GRANTLEE_TEMPLATES_EXPORT InMemoryTemplateLoader + : public AbstractTemplateLoader +{ +public: + InMemoryTemplateLoader(); + ~InMemoryTemplateLoader() override; + + Template loadByName(const QString &name, Engine const *engine) const override; + + bool canLoadTemplate(const QString &name) const override; + + QPair getMediaUri(const QString &fileName) const override; + + /** + Add a template content to this Loader. + + Example: + + @code + auto loader = QSharedPointersetTemplate( "name_template", "My name is {{ name }}" ); + loader->setTemplate( "age_template", "My age is {{ age }}" ); + engine->addTemplateLoader( loader ); + + // Both templates may now be retrieved by calling Engine::loadByName. + @endcode + */ + void setTemplate(const QString &name, const QString &content); + +private: + QHash m_namedTemplates; +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/texthtmlbuilder.h b/qt6-after/qt6-migrated-legatus/include/grantlee/texthtmlbuilder.h new file mode 100644 index 000000000..22dec91f5 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/texthtmlbuilder.h @@ -0,0 +1,238 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2008 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_TEXTHTMLBUILDER_H +#define GRANTLEE_TEXTHTMLBUILDER_H + +#ifdef Q_CC_MSVC +#pragma warning(disable : 4250) +#endif + +#include "abstractmarkupbuilder.h" +#include "grantlee_textdocument_export.h" +#include "markupdirector.h" + +namespace Grantlee +{ + +class TextHTMLBuilderPrivate; + +/// @headerfile texthtmlbuilder.h grantlee/texthtmlbuilder.h + +/** + @brief The TextHTMLBuilder creates a clean html markup output. + + This class creates html output which is as minimal as possible and restricted + to the rich text features supported in %Qt. + (https://doc.qt.io/qt-5/richtext-html-subset.html) + + The output contains only the body content, not the head element or other + metadata. + + eg: + + @code +

+ This is some formatted content in a paragraph. +

+ @endcode + + instead of the content produced by %Qt: + + @code + + +

This is some formatted content in a paragraph. +

+ @endcode + + Such tags should be created separately. For example: + + @code + auto b = new TextHTMLBuilder(); + auto md = new MarkupDirector(b); + md->constructContent(); + QString cleanHtml( + "\n%1\n\n%2\n") + .arg(document.metaInformation(QTextDocument::DocumentTitle)) + .arg(b->getOutput()); + file.write(cleanHtml); + @endcode + + Font formatting information on elements is represented by individual span + elements. + + eg: + @code + + + Blue text on red background + + + @endcode + + instead of + + @code + + Blue text on red background + + @endcode + + It my be possible to change this if necessary. + + @author Stephen Kelly +*/ +class GRANTLEE_TEXTDOCUMENT_EXPORT TextHTMLBuilder + : virtual public AbstractMarkupBuilder +{ +public: + TextHTMLBuilder(); + ~TextHTMLBuilder() override; + + void beginStrong() override; + void endStrong() override; + void beginEmph() override; + void endEmph() override; + void beginUnderline() override; + void endUnderline() override; + void beginStrikeout() override; + void endStrikeout() override; + void beginForeground(const QBrush &brush) override; + void endForeground() override; + void beginBackground(const QBrush &brush) override; + void endBackground() override; + void beginAnchor(const QString &href = {}, const QString &name = {}) override; + void endAnchor() override; + + // Maybe this stuff should just be added to a list, and then when I add + // literal text, + // add some kind of style attribute in one span instead of many. + void beginFontFamily(const QString &family) override; + void endFontFamily() override; + + /** + Begin a new font point size + @param size The new size to begin. + */ + void beginFontPointSize(int size) override; + void endFontPointSize() override; + + /** + Begin a new paragraph + @param al The new paragraph alignment + @param topMargin The new paragraph topMargin + @param bottomMargin The new paragraph bottomMargin + @param leftMargin The new paragraph leftMargin + @param rightMargin The new paragraph rightMargin + */ + void beginParagraph(Qt::Alignment al = Qt::AlignLeft, qreal topMargin = 0.0, + qreal bottomMargin = 0.0, qreal leftMargin = 0.0, + qreal rightMargin = 0.0) override; + + /** + Begin a new header element. + @param level The new level to begin. + */ + void beginHeader(int level) override; + + /** + End a header element. + @param level The new level to end. + */ + void endHeader(int level) override; + + void endParagraph() override; + void addNewline() override; + + void insertHorizontalRule(int width = -1) override; + + void insertImage(const QString &src, qreal width, qreal height) override; + + void beginList(QTextListFormat::Style type) override; + + void endList() override; + + void beginListItem() override; + void endListItem() override; + + void beginSuperscript() override; + + void endSuperscript() override; + + void beginSubscript() override; + + void endSubscript() override; + + void beginTable(qreal cellpadding, qreal cellspacing, + const QString &width) override; + + void beginTableRow() override; + void beginTableHeaderCell(const QString &width, int colspan, + int rowspan) override; + + void beginTableCell(const QString &width, int colspan, int rowspan) override; + + void endTable() override; + void endTableRow() override; + void endTableHeaderCell() override; + void endTableCell() override; + + /** + Reimplemented from AbstractMarkupBuilder. + + This implementation escapes the text before appending so that + + @verbatim + A sample bold word. + @endverbatim + + becomes + + @verbatim + A sample <b>bold</b> word. + @endverbatim + */ + void appendLiteralText(const QString &text) override; + + /** + Append @p text without escaping. + + This is useful if extending MarkupDirector + */ + void appendRawText(const QString &text) override; + + QString getResult() override; + +private: + TextHTMLBuilderPrivate *d_ptr; + Q_DECLARE_PRIVATE(TextHTMLBuilder) +}; +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/token.h b/qt6-after/qt6-migrated-legatus/include/grantlee/token.h new file mode 100644 index 000000000..685a1e9c6 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/token.h @@ -0,0 +1,57 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_TOKEN_H +#define GRANTLEE_TOKEN_H + +#include + +namespace Grantlee +{ + +/** + @internal + + The available token types. +*/ +enum TokenType { + TextToken, ///< The Token is a text fragment + VariableToken, ///< The Token is a variable node + BlockToken, ///< The Token is a block, ie, part of a tag + CommentToken ///< The Token is a comment node. +}; + +/// @headerfile token.h grantlee/token.h + +/** + A token in a parse stream for a template. + + This class is only relevant for template tag implementations. +*/ +struct Token { + int tokenType; ///< The Type of this Token + int linenumber; ///< The line number this Token starts at + QString content; ///< The content of this Token +}; +} + +Q_DECLARE_TYPEINFO(Grantlee::Token, Q_MOVABLE_TYPE); + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/typeaccessor.h b/qt6-after/qt6-migrated-legatus/include/grantlee/typeaccessor.h new file mode 100644 index 000000000..067d7f0bd --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/typeaccessor.h @@ -0,0 +1,48 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_TYPEACCESSOR_H +#define GRANTLEE_TYPEACCESSOR_H + +#include "grantlee_templates_export.h" + +#include + +/// @file + +namespace Grantlee +{ + +#ifndef Q_QDOC +template struct TypeAccessor { + static QVariant lookUp(const T object, const QString &property); +}; + +template struct TypeAccessor { + static QVariant lookUp(const T *const object, const QString &property); +}; + +template struct TypeAccessor { + static QVariant lookUp(const T &object, const QString &property); +}; +#endif +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/util.h b/qt6-after/qt6-migrated-legatus/include/grantlee/util.h new file mode 100644 index 000000000..18110e266 --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/util.h @@ -0,0 +1,111 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_UTIL_P_H +#define GRANTLEE_UTIL_P_H + +#include "context.h" +#include "grantlee_templates_export.h" +#include "safestring.h" + +#include + +/// @file util.h Utility functions used throughout %Grantlee. + +namespace Grantlee +{ + +/** + Returns whether the @p variant is evaluated to true. + + @see @ref truthiness +*/ +GRANTLEE_TEMPLATES_EXPORT bool variantIsTrue(const QVariant &variant); + +/** + Converts the @p input into its unescaped form. + + Double slashes are converted to single slashes, \\" is converted to " + etc. +*/ +GRANTLEE_TEMPLATES_EXPORT QString unescapeStringLiteral(const QString &input); + +/** + Marks the @p input as safe. +*/ +GRANTLEE_TEMPLATES_EXPORT Grantlee::SafeString +markSafe(const Grantlee::SafeString &input); + +/** + Marks the @p input as requiring escaping. +*/ +GRANTLEE_TEMPLATES_EXPORT Grantlee::SafeString +markForEscaping(const Grantlee::SafeString &input); + +/** + Retrieves and returns a SafeString from the @p input. +*/ +GRANTLEE_TEMPLATES_EXPORT Grantlee::SafeString +getSafeString(const QVariant &input); + +/** + Returns whether @p input contains a SafeString. +*/ +GRANTLEE_TEMPLATES_EXPORT bool isSafeString(const QVariant &input); + +/** + Returns true if the type of @p input can be inserted into a rendered template + directly. + + Note that lists, hashes and QObject*s can not be. +*/ +GRANTLEE_TEMPLATES_EXPORT bool supportedOutputType(const QVariant &input); + +/** + Compares @p lhs and @p rhs for equality. SafeStrings are compared as raw + QStrings. Their safeness is not part of the comparison. + + @see QVariant::operator== +*/ +GRANTLEE_TEMPLATES_EXPORT bool equals(const QVariant &lhs, const QVariant &rhs); + +/** + Converts @p size into the nearest file size unit like MB or MiB, based on the + @p unitSystem value. Use @c 2 for the @p unitSystem to get binary units, use + @c 10 to get decimal units - by default, decimal units will be returned. The + @p multiplier can be used if the input @p size is not in pure bytes. If @p + size is for example given in @a KiB, use a multiplier of @a 1024. The returned + pair will have the converted size as @a first and the unit as @a second. +*/ +GRANTLEE_TEMPLATES_EXPORT std::pair +calcFileSize(qreal size, int unitSystem = 10, qreal multiplier = 1.0); + +#ifndef Q_QDOC +/** + @internal + Returns the @p list as a formatted string. This is for debugging purposes + only. +*/ +GRANTLEE_TEMPLATES_EXPORT Grantlee::SafeString +toString(const QVariantList &list); +#endif +} + +#endif diff --git a/qt6-after/qt6-migrated-legatus/include/grantlee/variable.h b/qt6-after/qt6-migrated-legatus/include/grantlee/variable.h new file mode 100644 index 000000000..edeb6403f --- /dev/null +++ b/qt6-after/qt6-migrated-legatus/include/grantlee/variable.h @@ -0,0 +1,129 @@ +/* + This file is part of the Grantlee template system. + + Copyright (c) 2009,2010 Stephen Kelly + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either version + 2.1 of the Licence, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +*/ + +#ifndef GRANTLEE_VARIABLE_H +#define GRANTLEE_VARIABLE_H + +#include "grantlee_templates_export.h" + +#include + +namespace Grantlee +{ +class Context; + +class VariablePrivate; + +/// @headerfile variable.h grantlee/variable.h + +/** + @brief A container for static variables defined in Templates. + + This class is only relevant to Template tag authors. + + When processing a template tag in a AbstractNodeFactory implementation, it + will sometimes make sense to process arguments to the tag as + Grantlee::Variables. Note that usually they should be processed as + FilterExpression objects instead. + + Arguments to the tag can be used to construct Variables, which may then be + resolved into the objects they represent in the given Context in the render + stage. + + @author Stephen Kelly +*/ +class GRANTLEE_TEMPLATES_EXPORT Variable +{ +public: + /** + Constructs an invalid **%Variable** + */ + Variable(); + + /** + Creates a **%Variable** represented by the given @p var + */ + explicit Variable(const QString &var); + + /** + Copy constructor + */ + Variable(const Variable &other); + + /** + Destructor + */ + ~Variable(); + + /** + Assignment operator. + */ + Variable &operator=(const Variable &other); + + /** + Returns whether this **%Variable** is valid. + */ + bool isValid() const; + + /** + Returns whether this **%Variable** evaluates to true with the Context @p c. + */ + bool isTrue(Context *c) const; + + /** + Resolves this **%Variable** with the Context @p c. + */ + QVariant resolve(Context *c) const; + + /** + Returns whether this **%Variable** is a constant in the Template. A constant + is represented as a static string in the template + + @code + Text content + {% some_tag "constant" variable %} + @endcode + */ + bool isConstant() const; + + /** + Returns whether this variable is localized, that is, if it is wrapped with + _(). @see @ref i18n_l10n + */ + bool isLocalized() const; + + /** + Returns whether this variable is a literal string or number. A + literal **%Variable** does not have any lookup components. + */ + QVariant literal() const; + + /** + Returns the lookup components of this **%Variable**. + */ + QStringList lookups() const; + +private: + Q_DECLARE_PRIVATE(Variable) + VariablePrivate *const d_ptr; +}; +} + +#endif