Messagelib

ktexttemplateextension.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "ktexttemplateextension.h"
8
9#include <KTextTemplate/Exception>
10#include <KTextTemplate/Parser>
11
12using namespace MessageViewer;
13
14CallbackTag::CallbackTag(const QString &name, QObject *parent)
15 : KTextTemplate::Node(parent)
16 , m_name(name)
17{
18}
19
20void CallbackTag::render(KTextTemplate::OutputStream *stream, KTextTemplate::Context *context) const
21{
22 auto cb = context->lookup(m_name).value<KTextTemplateCallback>();
23 if (cb) {
24 cb(stream);
25 }
26}
27
28KTextTemplate::Node *CallbackTagFactory::getNode(const QString &tagContent, KTextTemplate::Parser *parser) const
29{
30 auto expr = tagContent.split(QLatin1Char(' '), Qt::SkipEmptyParts);
31 if (expr.size() != 2) {
32 return nullptr;
33 }
34
35 return new CallbackTag(expr.at(1), parser);
36}
37
38KTextTemplateTagLibrary::KTextTemplateTagLibrary(QObject *parent)
39 : QObject(parent)
40{
41}
42
43QHash<QString, KTextTemplate::AbstractNodeFactory *> KTextTemplateTagLibrary::nodeFactories(const QString &name)
44{
45 Q_UNUSED(name)
47 nodeFactories.insert(QStringLiteral("callback"), new CallbackTagFactory());
48 return nodeFactories;
49}
50
51#include "moc_ktexttemplateextension.cpp"
QVariant lookup(const QString &str) const
QString name(StandardAction id)
iterator insert(const Key &key, const T &value)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
SkipEmptyParts
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.