23 #include "../lib/exception.h"
27 RegroupNodeFactory::RegroupNodeFactory() {}
31 auto expr = tagContent.split(QLatin1Char(
' '));
33 if (expr.size() != 6) {
35 TagSyntaxError, QStringLiteral(
"widthratio takes five arguments"));
38 if (expr.at(2) != QStringLiteral(
"by")) {
40 QStringLiteral(
"second argument must be 'by'"));
43 if (expr.at(4) != QStringLiteral(
"as")) {
45 QStringLiteral(
"fourth argument must be 'as'"));
49 QStringLiteral(
"\"") + expr.at(3) + QStringLiteral(
"\""), p);
51 auto name = expr.at(5);
53 return new RegroupNode(target, expression, name, p);
58 const QString &varName, QObject *parent)
59 :
Node(parent), m_target(target), m_expression(expression),
67 auto objList = m_target.
toList(c);
68 if (objList.isEmpty()) {
69 c->
insert(m_varName, QVariantHash());
91 QVariantList contextList;
93 for (
auto &var : objList) {
95 c->
insert(QStringLiteral(
"var"), var);
100 if (!contextList.isEmpty()) {
101 auto hashVar = contextList.last();
102 hash = hashVar.value<QVariantHash>();
105 const auto it = hash.constFind(QStringLiteral(
"grouper"));
106 if (it == hash.constEnd() || it.value() != key) {
107 contextList.append(QVariantHash{
108 {QStringLiteral(
"grouper"), key},
109 {QStringLiteral(
"list"), QVariantList{ var }},
113 auto itList = hash.find(QStringLiteral(
"list"));
114 if (itList != hash.end()) {
115 list = itList.value().value<QVariantList>();
120 hash.insert(QStringLiteral(
"list"), list);
122 contextList[contextList.size() - 1] = hash;
125 c->
insert(m_varName, contextList);
The Context class holds the context to render a Template with.
void insert(const QString &name, QObject *object)
An exception for use when implementing template tags.
A FilterExpression object represents a filter expression in a template.
QVariantList toList(Context *c) const
QVariant resolve(OutputStream *stream, Context *c) const
Base class for all nodes.
The OutputStream class is used to render templates to a QTextStream.
The Parser class processes a string template into a tree of nodes.
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override
Cutelee::SafeString getSafeString(const QVariant &input)
Utility functions used throughout Cutelee.