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 
12 using namespace MessageViewer;
13 
14 CallbackTag::CallbackTag(const QString &name, QObject *parent)
15  : KTextTemplate::Node(parent)
16  , m_name(name)
17 {
18 }
19 
20 void 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 
28 KTextTemplate::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 
38 KTextTemplateTagLibrary::KTextTemplateTagLibrary(QObject *parent)
39  : QObject(parent)
40 {
41 }
42 
43 QHash<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
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
T value() const const
QHash::iterator insert(const Key &key, const T &value)
SkipEmptyParts
QString name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:55:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.