File indexing completed on 2025-02-09 04:28:41
0001 /* 0002 This file is part of the KTextTemplate library 0003 0004 SPDX-FileCopyrightText: 2009, 2010 Stephen Kelly <steveire@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 0008 */ 0009 0010 #ifndef KTEXTTEMPLATE_VARIABLE_H 0011 #define KTEXTTEMPLATE_VARIABLE_H 0012 0013 #include "ktexttemplate_export.h" 0014 0015 #include <QVariant> 0016 0017 namespace KTextTemplate 0018 { 0019 class Context; 0020 0021 class VariablePrivate; 0022 0023 /// @headerfile variable.h <KTextTemplate/Variable> 0024 0025 /** 0026 @brief A container for static variables defined in Templates. 0027 0028 This class is only relevant to Template tag authors. 0029 0030 When processing a template tag in a AbstractNodeFactory implementation, it 0031 will sometimes make sense to process arguments to the tag as 0032 KTextTemplate::Variables. Note that usually they should be processed as 0033 FilterExpression objects instead. 0034 0035 Arguments to the tag can be used to construct Variables, which may then be 0036 resolved into the objects they represent in the given Context in the render 0037 stage. 0038 0039 @author Stephen Kelly <steveire@gmail.com> 0040 */ 0041 class KTEXTTEMPLATE_EXPORT Variable 0042 { 0043 public: 0044 /** 0045 Constructs an invalid **%Variable** 0046 */ 0047 Variable(); 0048 0049 /** 0050 Creates a **%Variable** represented by the given @p var 0051 */ 0052 explicit Variable(const QString &var); 0053 0054 /** 0055 Copy constructor 0056 */ 0057 Variable(const Variable &other); 0058 0059 /** 0060 Destructor 0061 */ 0062 ~Variable(); 0063 0064 /** 0065 Assignment operator. 0066 */ 0067 Variable &operator=(const Variable &other); 0068 0069 /** 0070 Returns whether this **%Variable** is valid. 0071 */ 0072 bool isValid() const; 0073 0074 /** 0075 Returns whether this **%Variable** evaluates to true with the Context @p c. 0076 */ 0077 bool isTrue(Context *c) const; 0078 0079 /** 0080 Resolves this **%Variable** with the Context @p c. 0081 */ 0082 QVariant resolve(Context *c) const; 0083 0084 /** 0085 Returns whether this **%Variable** is a constant in the Template. A constant 0086 is represented as a static string in the template 0087 0088 @code 0089 Text content 0090 {% some_tag "constant" variable %} 0091 @endcode 0092 */ 0093 bool isConstant() const; 0094 0095 /** 0096 Returns whether this variable is localized, that is, if it is wrapped with 0097 _(). @see @ref i18n_l10n 0098 */ 0099 bool isLocalized() const; 0100 0101 /** 0102 Returns whether this variable is a literal string or number. A 0103 literal **%Variable** does not have any lookup components. 0104 */ 0105 QVariant literal() const; 0106 0107 /** 0108 Returns the lookup components of this **%Variable**. 0109 */ 0110 QStringList lookups() const; 0111 0112 private: 0113 Q_DECLARE_PRIVATE(Variable) 0114 VariablePrivate *const d_ptr; 0115 }; 0116 } 0117 0118 #endif