Grantlee: templates/lib/node.h Source File

Grantlee 5.3.0

node.h
1/*
2 This file is part of the Grantlee template system.
3
4 Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either version
9 2.1 of the Licence, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library. If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#ifndef GRANTLEE_NODE_H
22#define GRANTLEE_NODE_H
23
24// krazy:excludeall=dpointer
25
26#include "context.h"
27#include "filterexpression.h"
28#include "grantlee_templates_export.h"
29#include "outputstream.h"
30#include "safestring.h"
31
32#include <QtCore/QStringList>
33
34// Need these for inheriting from QList<T> to work
35// http://lists.trolltech.com/qt-interest/2008-01/thread00578-0.html
36#include <QtCore/QSet>
37#include <QtCore/QVector>
38
39namespace Grantlee
40{
41
42class Engine;
43class NodeList;
44class TemplateImpl;
45
46class NodePrivate;
47
49
82 class GRANTLEE_TEMPLATES_EXPORT Node : public QObject
83{
84 Q_OBJECT
85public:
91 explicit Node(QObject *parent = {});
92
96 ~Node() override;
97
103 virtual void render(OutputStream *stream, Context *c) const = 0;
104
105#ifndef Q_QDOC
109 virtual bool mustBeFirst()
110 { // krazy:exclude:inline
111 return false;
112 }
113#endif
114
115protected:
122 void streamValueInContext(OutputStream *stream, const QVariant &input,
123 Grantlee::Context *c) const;
124
128 TemplateImpl *containerTemplate() const;
129
130private:
131 Q_DECLARE_PRIVATE(Node)
132 NodePrivate *const d_ptr;
133};
134
136
152 class GRANTLEE_TEMPLATES_EXPORT NodeList : public QList<Grantlee::Node *>
153{
154public:
158 NodeList();
159
163 NodeList(const NodeList &list);
164
165 NodeList &operator=(const NodeList &list);
166
170 /* implicit */ NodeList(const QList<Grantlee::Node *> &list);
171
175 ~NodeList();
176
180 void append(Grantlee::Node *node);
181
185 void append(QList<Grantlee::Node *> nodeList);
186
190 bool containsNonText() const;
191
195 template <typename T> QList<T> findChildren()
196 {
197 QList<T> children;
198 QList<Grantlee::Node *>::const_iterator it;
199 const QList<Grantlee::Node *>::const_iterator first = constBegin();
200 const QList<Grantlee::Node *>::const_iterator last = constEnd();
201 for (it = first; it != last; ++it) {
202 T object = qobject_cast<T>(*it);
203 if (object) {
204 children << object;
205 }
206 children << (*it)->findChildren<T>();
207 }
208 return children;
209 }
210
214 void render(OutputStream *stream, Context *c) const;
215
216private:
217 bool m_containsNonText;
218};
219
220class AbstractNodeFactoryPrivate;
221
223
304 class GRANTLEE_TEMPLATES_EXPORT AbstractNodeFactory : public QObject
305{
306 Q_OBJECT
307public:
313 explicit AbstractNodeFactory(QObject *parent = {});
314
318 ~AbstractNodeFactory() override;
319
334 virtual Node *getNode(const QString &tagContent, Parser *p) const = 0;
335
336#ifndef Q_QDOC
343 virtual void setEngine(Engine *) {}
344#endif
345
346protected:
362 Q_INVOKABLE QStringList smartSplit(const QString &str) const;
363
364protected:
371 QList<FilterExpression> getFilterExpressionList(const QStringList &list,
372 Parser *p) const;
373
374private:
375 Q_DECLARE_PRIVATE(AbstractNodeFactory)
376 AbstractNodeFactoryPrivate *const d_ptr;
377};
378}
379
380#endif
Grantlee::AbstractNodeFactory
Base class for all NodeFactories.
Definition node.h:305
Grantlee::AbstractNodeFactory::getNode
virtual Node * getNode(const QString &tagContent, Parser *p) const =0
Grantlee::AbstractNodeFactory::getFilterExpressionList
QList< FilterExpression > getFilterExpressionList(const QStringList &list, Parser *p) const
Grantlee::AbstractNodeFactory::smartSplit
Q_INVOKABLE QStringList smartSplit(const QString &str) const
Grantlee::AbstractNodeFactory::AbstractNodeFactory
AbstractNodeFactory(QObject *parent={})
Grantlee::AbstractNodeFactory::~AbstractNodeFactory
~AbstractNodeFactory() override
Grantlee::Context
The Context class holds the context to render a Template with.
Definition context.h:118
Grantlee::Engine
Grantlee::Engine is the main entry point for creating Grantlee Templates.
Definition engine.h:121
Grantlee::NodeList
A list of Nodes with some convenience API for rendering them.
Definition node.h:153
Grantlee::NodeList::append
void append(Grantlee::Node *node)
Grantlee::NodeList::~NodeList
~NodeList()
Grantlee::NodeList::render
void render(OutputStream *stream, Context *c) const
Grantlee::NodeList::findChildren
QList< T > findChildren()
Definition node.h:195
Grantlee::NodeList::containsNonText
bool containsNonText() const
Grantlee::NodeList::NodeList
NodeList(const NodeList &list)
Grantlee::NodeList::append
void append(QList< Grantlee::Node * > nodeList)
Grantlee::NodeList::NodeList
NodeList()
Grantlee::NodeList::NodeList
NodeList(const QList< Grantlee::Node * > &list)
Grantlee::Node
Base class for all nodes.
Definition node.h:83
Grantlee::Node::render
virtual void render(OutputStream *stream, Context *c) const =0
Grantlee::Node::~Node
~Node() override
Grantlee::Node::containerTemplate
TemplateImpl * containerTemplate() const
Grantlee::Node::streamValueInContext
void streamValueInContext(OutputStream *stream, const QVariant &input, Grantlee::Context *c) const
Grantlee::Node::Node
Node(QObject *parent={})
Grantlee::OutputStream
The OutputStream class is used to render templates to a QTextStream.
Definition outputstream.h:81
Grantlee::Parser
The Parser class processes a string template into a tree of nodes.
Definition parser.h:49
Grantlee
The Grantlee namespace holds all public Grantlee API.
Definition Mainpage.dox:8
Grantlee::registerMetaType
int registerMetaType()
Registers the type RealType with the metatype system.
Definition metatype.h:182