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
QStringList lookups() const
Returns the lookup components of this Variable.
Definition variable.cpp:148
QVariant literal() const
Returns whether this variable is a literal string or number.
Definition variable.cpp:142
QVariant resolve(Context *c) const
Resolves this Variable with the Context c.
Definition variable.cpp:163
Variable()
Constructs an invalid Variable
Definition variable.cpp:51
bool isTrue(Context *c) const
Returns whether this Variable evaluates to true with the Context c.
Definition variable.cpp:131
bool isConstant() const
Returns whether this Variable is a constant in the Template.
Definition variable.cpp:125
Variable & operator=(const Variable &other)
Assignment operator.
Definition variable.cpp:61
bool isLocalized() const
Returns whether this variable is localized, that is, if it is wrapped with _().
Definition variable.cpp:136
bool isValid() const
Returns whether this Variable is valid.
Definition variable.cpp:119
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:54:59 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.