Messagelib

grantleeextension.h
1 /*
2  SPDX-FileCopyrightText: 2017 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 #include <QObject>
9 
10 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
11 #include <grantlee/node.h>
12 #include <grantlee/taglibraryinterface.h>
13 #else
14 #include <KTextTemplate/Node>
15 #include <KTextTemplate/TagLibraryInterface>
16 #endif
17 
18 #include <functional>
19 
20 namespace MessageViewer
21 {
22 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
23 using GrantleeCallback = std::function<void(Grantlee::OutputStream *)>;
24 #else
25 using GrantleeCallback = std::function<void(KTextTemplate::OutputStream *)>;
26 #endif
27 
28 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
29 class CallbackTag : public Grantlee::Node
30 #else
31 class CallbackTag : public KTextTemplate::Node
32 #endif
33 {
34  Q_OBJECT
35 public:
36  explicit CallbackTag(const QString &name, QObject *parent = nullptr);
37 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
38  void render(Grantlee::OutputStream *stream, Grantlee::Context *context) const override;
39 #else
40  void render(KTextTemplate::OutputStream *stream, KTextTemplate::Context *context) const override;
41 #endif
42 
43 private:
44  const QString m_name;
45 };
46 
47 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
48 class CallbackTagFactory : public Grantlee::AbstractNodeFactory
49 #else
50 class CallbackTagFactory : public KTextTemplate::AbstractNodeFactory
51 #endif
52 {
53  Q_OBJECT
54 public:
55 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
56  Grantlee::Node *getNode(const QString &tagContent, Grantlee::Parser *parser) const override;
57 #else
58  KTextTemplate::Node *getNode(const QString &tagContent, KTextTemplate::Parser *parser) const override;
59 #endif
60 };
61 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
62 class GrantleeTagLibrary : public QObject, public Grantlee::TagLibraryInterface
63 #else
64 class GrantleeTagLibrary : public QObject, public KTextTemplate::TagLibraryInterface
65 #endif
66 {
67  Q_OBJECT
68 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
69  Q_INTERFACES(Grantlee::TagLibraryInterface)
70 #else
72 #endif
73  Q_PLUGIN_METADATA(IID "org.grantlee.TagLibraryInterface")
74 public:
75  explicit GrantleeTagLibrary(QObject *parent = nullptr);
76 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
77  Q_REQUIRED_RESULT QHash<QString, Grantlee::AbstractNodeFactory *> nodeFactories(const QString &name) override;
78 #else
79  Q_REQUIRED_RESULT QHash<QString, KTextTemplate::AbstractNodeFactory *> nodeFactories(const QString &name) override;
80 #endif
81 };
82 }
83 
84 Q_DECLARE_METATYPE(MessageViewer::GrantleeCallback)
Q_OBJECTQ_OBJECT
Q_INTERFACES(...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Mar 22 2023 04:07:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.