36 if (expr.size() < 2) {
39 QStringLiteral(
"%1 expects at least one argument").arg(expr.first()));
42 if (expr.at(1).contains(QLatin1Char(
','))) {
43 auto csvlist = expr.at(1).split(QLatin1Char(
','));
45 for (
auto i = 0; i < csvlist.size(); ++i) {
46 expr.insert(i + 1, QChar::fromLatin1(
'"') + csvlist.at(i)
47 + QChar::fromLatin1(
'"'));
51 if (expr.size() == 2) {
53 auto name = expr.at(1);
54 auto cycleNodes = p->property(_namedCycleNodes);
55 if (cycleNodes.userType() != qMetaTypeId<QVariantHash>()) {
58 QStringLiteral(
"No named cycles in template. '%1' is not defined")
61 auto hash = cycleNodes.value<QVariantHash>();
62 if (!hash.contains(name)) {
64 QStringLiteral(
"Node not found: %1").arg(name));
66 auto nodeVariant = hash.value(name);
67 Q_ASSERT(nodeVariant.canConvert<
Node *>());
68 return nodeVariant.value<
Node *>();
71 auto exprSize = expr.size();
72 if (exprSize > 4 && expr.at(exprSize - 2) == QStringLiteral(
"as")) {
74 auto name = expr.at(exprSize - 1);
75 auto list = expr.mid(1, exprSize - 3);
77 auto hashVariant = p->property(_namedCycleNodes);
79 if (hashVariant.userType() == qMetaTypeId<QVariantHash>()) {
80 hash = hashVariant.value<QVariantHash>();
82 hash.insert(name, QVariant::fromValue(node));
83 p->setProperty(_namedCycleNodes,
QVariant(hash));
86 auto list = expr.mid(1, exprSize - 1);
93 :
Node(parent), m_list(list), m_variableIterator(list), m_name(name)
The Context class holds the context to render a Template with.
RenderContext * renderContext() const
void insert(const QString &name, QObject *object)
QVariant & data(const Node *const scopeNode)