KTextTemplate

variable.h
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10#ifndef KTEXTTEMPLATE_VARIABLE_H
11#define KTEXTTEMPLATE_VARIABLE_H
12
13#include "ktexttemplate_export.h"
14
15#include <QVariant>
16
17namespace KTextTemplate
18{
19class Context;
20
21class VariablePrivate;
22
23/// @headerfile variable.h <KTextTemplate/Variable>
24
25/**
26 @brief A container for static variables defined in Templates.
27
28 This class is only relevant to Template tag authors.
29
30 When processing a template tag in a AbstractNodeFactory implementation, it
31 will sometimes make sense to process arguments to the tag as
32 KTextTemplate::Variables. Note that usually they should be processed as
33 FilterExpression objects instead.
34
35 Arguments to the tag can be used to construct Variables, which may then be
36 resolved into the objects they represent in the given Context in the render
37 stage.
38
39 @author Stephen Kelly <steveire@gmail.com>
40*/
41class KTEXTTEMPLATE_EXPORT Variable
42{
43public:
44 /**
45 Constructs an invalid **%Variable**
46 */
47 Variable();
48
49 /**
50 Creates a **%Variable** represented by the given @p var
51 */
52 explicit Variable(const QString &var);
53
54 /**
55 Copy constructor
56 */
57 Variable(const Variable &other);
58
59 /**
60 Destructor
61 */
62 ~Variable();
63
64 /**
65 Assignment operator.
66 */
67 Variable &operator=(const Variable &other);
68
69 /**
70 Returns whether this **%Variable** is valid.
71 */
72 bool isValid() const;
73
74 /**
75 Returns whether this **%Variable** evaluates to true with the Context @p c.
76 */
77 bool isTrue(Context *c) const;
78
79 /**
80 Resolves this **%Variable** with the Context @p c.
81 */
82 QVariant resolve(Context *c) const;
83
84 /**
85 Returns whether this **%Variable** is a constant in the Template. A constant
86 is represented as a static string in the template
87
88 @code
89 Text content
90 {% some_tag "constant" variable %}
91 @endcode
92 */
93 bool isConstant() const;
94
95 /**
96 Returns whether this variable is localized, that is, if it is wrapped with
97 _(). @see @ref i18n_l10n
98 */
99 bool isLocalized() const;
100
101 /**
102 Returns whether this variable is a literal string or number. A
103 literal **%Variable** does not have any lookup components.
104 */
105 QVariant literal() const;
106
107 /**
108 Returns the lookup components of this **%Variable**.
109 */
110 QStringList lookups() const;
111
112private:
113 Q_DECLARE_PRIVATE(Variable)
114 VariablePrivate *const d_ptr;
115};
116}
117
118#endif
The Context class holds the context to render a Template with.
Definition context.h:107
A container for static variables defined in Templates.
Definition variable.h:42
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:59:16 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.