Grantlee 5.3.0
|
A FilterExpression object represents a filter expression in a template. More...
#include <grantlee/filterexpression.h>
Public Member Functions | |
FilterExpression () | |
FilterExpression (const FilterExpression &other) | |
FilterExpression (const QString &varString, Grantlee::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 |
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:
Definition at line 119 of file filterexpression.h.
Grantlee::FilterExpression::FilterExpression | ( | ) |
Constructs an invalid FilterExpression.
Referenced by FilterExpression(), isValid(), and operator=().
Grantlee::FilterExpression::FilterExpression | ( | const QString & | varString, |
Grantlee::Parser * | parser ) |
Constructs a filter expression from the string varString
. The Parser parser
is used to retrieve filters.
Grantlee::FilterExpression::FilterExpression | ( | const FilterExpression & | other | ) |
Copy constructor.
References FilterExpression().
Grantlee::FilterExpression::~FilterExpression | ( | ) |
Destructor.
bool Grantlee::FilterExpression::isTrue | ( | Context * | c | ) | const |
Returns whether the Filter resolves to true in the Context c
.
bool Grantlee::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.
References FilterExpression().
FilterExpression & Grantlee::FilterExpression::operator= | ( | const FilterExpression & | other | ) |
Assignment operator.
References FilterExpression().
QVariant Grantlee::FilterExpression::resolve | ( | Context * | c | ) | const |
Resolves the FilterExpression in the Context c
.
QVariant Grantlee::FilterExpression::resolve | ( | OutputStream * | stream, |
Context * | c ) const |
Resolves the FilterExpression in the Context c
and writes it to the stream stream
.
QVariantList Grantlee::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.
Variable Grantlee::FilterExpression::variable | ( | ) | const |
Returns the initial variable in the FilterExpression.