KTextTemplate::FilterExpression
#include <KTextTemplate/FilterExpression>
Public Member Functions | |
FilterExpression () | |
FilterExpression (const FilterExpression &other) | |
FilterExpression (const QString &varString, KTextTemplate::Parser *parser) | |
~FilterExpression () | |
bool | isTrue (Context *c) const |
bool | isValid () const |
FilterExpression & | operator= (const FilterExpression &other) |
QVariant | resolve (Context *c) const |
QVariant | resolve (OutputStream *stream, Context *c) const |
QVariantList | toList (Context *c) const |
Variable | variable () const |
Detailed Description
A FilterExpression object represents a filter expression in a template.
This class is only relevant if implementing custom tags or filters. Most of the API here is internal. Usually when implementing tags or filters, filter expressions will just be created and resolved.
In template markup, a filter expression is a variable followed by one or more filters separated by pipes:
Filter expressions may appear in variable nodes:
Or as arguments to tags
The FilterExpression class would be used in the getNode implementation of the AbstractNodeFactory implementation for the some_tag
tag.
When implementing the Node::render method, the resolve method may be used to process the filter expression.
For example, if our SomeTagNode
was to concatenate the resolved values given as arguments:
Because Filters are highly generic, they do not all write data to the stream. For example, a Filter might take as input a string, and return a list by splitting the string on commas, or a Filter might compare an input to its argument and return whether they are the same, but not write anything to the stream. For that reason, the resolve method writes data to the given stream, and returns the same data in its returned QVariant.
The suitability of either of the resolve methods will depend on the implementation and requirements of your custom tag. For example if the SomeTagNode
ran a comparison of the arguments:
- See also
- Tags with end tags
Definition at line 108 of file filterexpression.h.
Constructor & Destructor Documentation
◆ FilterExpression() [1/3]
FilterExpression::FilterExpression | ( | ) |
Constructs an invalid FilterExpression.
Definition at line 144 of file filterexpression.cpp.
◆ FilterExpression() [2/3]
FilterExpression::FilterExpression | ( | const QString & | varString, |
KTextTemplate::Parser * | parser ) |
Constructs a filter expression from the string varString
.
The Parser parser
is used to retrieve filters.
Definition at line 72 of file filterexpression.cpp.
◆ FilterExpression() [3/3]
FilterExpression::FilterExpression | ( | const FilterExpression & | other | ) |
Copy constructor.
Definition at line 138 of file filterexpression.cpp.
◆ ~FilterExpression()
FilterExpression::~FilterExpression | ( | ) |
Destructor.
Definition at line 155 of file filterexpression.cpp.
Member Function Documentation
◆ isTrue()
bool FilterExpression::isTrue | ( | Context * | c | ) | const |
Returns whether the Filter resolves to true in the Context c
.
- See also
- Truthiness
Definition at line 236 of file filterexpression.cpp.
◆ isValid()
bool FilterExpression::isValid | ( | ) | const |
Returns whether a filter expression is valid.
A FilterExpression is valid if all filters in the expression exist and the initial variable being filtered is valid.
Definition at line 149 of file filterexpression.cpp.
◆ operator=()
FilterExpression & FilterExpression::operator= | ( | const FilterExpression & | other | ) |
Assignment operator.
Definition at line 166 of file filterexpression.cpp.
◆ resolve() [1/2]
Resolves the FilterExpression in the Context c
.
Definition at line 222 of file filterexpression.cpp.
◆ resolve() [2/2]
QVariant FilterExpression::resolve | ( | OutputStream * | stream, |
Context * | c ) const |
Resolves the FilterExpression in the Context c
and writes it to the stream stream
.
Definition at line 176 of file filterexpression.cpp.
◆ toList()
QVariantList FilterExpression::toList | ( | Context * | c | ) | const |
Returns a list for the FilterExpression.
If the FilterExpression can not be resolved to a list, an empty list will be returned.
Definition at line 228 of file filterexpression.cpp.
◆ variable()
Variable FilterExpression::variable | ( | ) | const |
Returns the initial variable in the FilterExpression.
Definition at line 160 of file filterexpression.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.