25#include <QtCore/QDateTime>
27IfChangedNodeFactory::IfChangedNodeFactory() {}
37 = p->
parse(n, {QStringLiteral(
"else"), QStringLiteral(
"endifchanged")});
38 n->setTrueList(trueList);
42 falseList = p->
parse(n, QStringLiteral(
"endifchanged"));
43 n->setFalseList(falseList);
52 :
Node(parent), m_filterExpressions(feList)
58void IfChangedNode::setTrueList(
const NodeList &trueList)
60 m_trueList = trueList;
63void IfChangedNode::setFalseList(
const NodeList &falseList)
65 m_falseList = falseList;
70 if (c->
lookup(QStringLiteral(
"forloop")).isValid()
71 && (!c->
lookup(QStringLiteral(
"forloop"))
72 .value<QVariantHash>()
75 auto hash = c->
lookup(QStringLiteral(
"forloop")).
value<QVariantHash>();
77 c->
insert(QStringLiteral(
"forloop"), hash);
82 auto watchedStream = stream->
clone(&watchedTextStream);
83 if (m_filterExpressions.isEmpty()) {
84 m_trueList.render(watchedStream.get(), c);
86 QVariantList watchedVars;
87 for (
auto &i : m_filterExpressions) {
88 auto var = i.resolve(c);
93 watchedVars.append(var);
99 QVariantList lastSeenVarList;
100 if (m_lastSeen.userType() != qMetaTypeId<QString>()) {
101 lastSeenVarList = m_lastSeen.value<QVariantList>();
107 if ((watchedVars != lastSeenVarList)
109 && (watchedString != m_lastSeen.value<
QString>()))) {
110 auto firstLoop = !m_lastSeen.isValid();
112 m_lastSeen = watchedString;
114 m_lastSeen = watchedVars;
118 hash.insert(QStringLiteral(
"firstloop"), firstLoop);
119 c->
insert(QStringLiteral(
"ifchanged"), hash);
120 m_trueList.render(stream, c);
122 }
else if (!m_falseList.isEmpty()) {
123 m_falseList.render(stream, c);
QList< FilterExpression > getFilterExpressionList(const QStringList &list, Parser *p) const
The Context class holds the context to render a Template with.
void insert(const QString &name, QObject *object)
virtual QVariant lookup(const QString &str) const
A list of Nodes with some convenience API for rendering them.
Base class for all nodes.
The OutputStream class is used to render templates to a QTextStream.
virtual std::shared_ptr< OutputStream > clone(QTextStream *stream) const
The Parser class processes a string template into a tree of nodes.
NodeList parse(Node *parent, const QStringList &stopAt={})
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override
bool isEmpty() const const
QString number(double n, char format, int precision)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString content
The content of this Token.