QGIS API Documentation
2.6.0-Brighton
|
Class for parsing and evaluation of expressions (formerly called "search strings"). More...
#include <qgsexpression.h>
Classes | |
class | Function |
A abstract base class for defining QgsExpression functions. More... | |
class | Interval |
class | Node |
class | NodeBinaryOperator |
class | NodeColumnRef |
class | NodeCondition |
class | NodeFunction |
class | NodeInOperator |
class | NodeList |
class | NodeLiteral |
class | NodeUnaryOperator |
class | StaticFunction |
class | Visitor |
support for visitor pattern - algorithms dealing with the expressions may be implemented without modifying the Node classes More... | |
class | WhenThen |
Public Types | |
enum | UnaryOperator { uoNot, uoMinus } |
enum | BinaryOperator { boOr, boAnd, boEQ, boNE, boLE, boGE, boLT, boGT, boRegexp, boLike, boNotLike, boILike, boNotILike, boIs, boIsNot, boPlus, boMinus, boMul, boDiv, boMod, boPow, boConcat } |
enum | SpatialOperator { soBbox, soIntersects, soContains, soCrosses, soEquals, soDisjoint, soOverlaps, soTouches, soWithin } |
enum | NodeType { ntUnaryOperator, ntBinaryOperator, ntInOperator, ntFunction, ntLiteral, ntColumnRef, ntCondition } |
typedef QVariant(* | FcnEval )(const QVariantList &values, const QgsFeature *f, QgsExpression *parent) |
typedef QList< WhenThen * > | WhenThenList |
Public Member Functions | |
QgsExpression (const QString &expr) | |
~QgsExpression () | |
bool | hasParserError () const |
Returns true if an error occurred when parsing the input expression. | |
QString | parserErrorString () const |
Returns parser error. | |
const Node * | rootNode () const |
Returns root node of the expression. Root node is null is parsing has failed. | |
bool | prepare (const QgsFields &fields) |
Get the expression ready for evaluation - find out column indexes. | |
QStringList | referencedColumns () |
Get list of columns referenced by the expression. | |
bool | needsGeometry () |
Returns true if the expression uses feature geometry for some computation. | |
QVariant | evaluate (const QgsFeature *f=NULL) |
Evaluate the feature and return the result. | |
QVariant | evaluate (const QgsFeature &f) |
Evaluate the feature and return the result. | |
QVariant | evaluate (const QgsFeature *f, const QgsFields &fields) |
Evaluate the feature and return the result. | |
QVariant | evaluate (const QgsFeature &f, const QgsFields &fields) |
Evaluate the feature and return the result. | |
bool | hasEvalError () const |
Returns true if an error occurred when evaluating last input. | |
QString | evalErrorString () const |
Returns evaluation error. | |
void | setEvalErrorString (QString str) |
Set evaluation error (used internally by evaluation functions) | |
void | setCurrentRowNumber (int rowNumber) |
Set the number for $rownum special column. | |
int | currentRowNumber () |
Return the number used for $rownum special column. | |
void | setScale (double scale) |
double | scale () |
const QString | expression () const |
Alias for dump() | |
QString | dump () const |
Return the expression string that represents this QgsExpression. | |
QgsDistanceArea * | geomCalculator () |
Return calculator used for distance and area calculations (used by internal functions) | |
void | setGeomCalculator (const QgsDistanceArea &calc) |
Sets the geometry calculator used in evaluation of expressions,. | |
void | acceptVisitor (Visitor &v) const |
entry function for the visitor pattern |
Static Public Member Functions | |
static void | setSpecialColumn (const QString &name, QVariant value) |
Assign a special column. | |
static void | unsetSpecialColumn (const QString &name) |
Unset a special column. | |
static QVariant | specialColumn (const QString &name) |
Return the value of the given special column or a null QVariant if undefined. | |
static bool | hasSpecialColumn (const QString &name) |
Check whether a special column exists. | |
static bool | isValid (const QString &text, const QgsFields &fields, QString &errorMessage) |
static QString | replaceExpressionText (const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=0, const QgsDistanceArea *distanceArea=0) |
This function currently replaces each expression between [% and %] in the string with the result of its evaluation on the feature passed as argument. | |
static const QList< Function * > & | Functions () |
static const QStringList & | BuiltinFunctions () |
static bool | registerFunction (Function *function) |
static bool | unregisterFunction (QString name) |
static bool | isFunctionName (QString name) |
static int | functionIndex (QString name) |
static int | functionCount () |
Returns the number of functions defined in the parser. | |
static QList< Function * > | specialColumns () |
Returns a list of special Column definitions. | |
static QString | quotedColumnRef (QString name) |
return quoted column reference (in double quotes) | |
static QString | quotedString (QString text) |
return quoted string (in single quotes) | |
static QString | helptext (QString name) |
static QString | group (QString group) |
Static Public Attributes | |
static const char * | BinaryOperatorText [] |
static const char * | UnaryOperatorText [] |
static QList< Function * > | gmFunctions |
static QStringList | gmBuiltinFunctions |
Protected Member Functions | |
QgsExpression () | |
void | initGeomCalculator () |
Static Protected Member Functions | |
static void | initFunctionHelp () |
Protected Attributes | |
Node * | mRootNode |
QString | mParserErrorString |
QString | mEvalErrorString |
int | mRowNumber |
double | mScale |
QString | mExp |
QgsDistanceArea * | mCalc |
Static Protected Attributes | |
static QMap< QString, QVariant > | gmSpecialColumns |
static QMap< QString, QString > | gmSpecialColumnGroups |
static QHash< QString, QString > | gFunctionHelpTexts |
static QHash< QString, QString > | gGroups |
Friends | |
class | QgsOgcUtils |
Class for parsing and evaluation of expressions (formerly called "search strings").
The expressions try to follow both syntax and semantics of SQL expressions.
Usage:
Possible QVariant value types:
Similarly to SQL, this class supports three-value logic: true/false/unknown. Unknown value may be a result of operations with missing data (NULL). Please note that NULL is different value than zero or an empty string. For example 3 > NULL returns unknown.
There is no special (three-value) 'boolean' type: true/false is represented as 1/0 integer, unknown value is represented the same way as NULL values: invalid QVariant.
For better performance with many evaluations you may first call prepare(fields) function to find out indices of columns and then repeatedly call evaluate(feature).
Type conversion: operators and functions that expect arguments to be of particular type automatically convert the arguments to that type, e.g. sin('2.1') will convert the argument to a double, length(123) will first convert the number to a string. Explicit conversion can be achieved with toint, toreal, tostring functions. If implicit or explicit conversion is invalid, the evaluation returns an error. Comparison operators do numeric comparison in case both operators are numeric (int/double) or they can be converted to numeric types.
Arithmetic operators do integer arithmetics if both operands are integer. That is 2+2 yields integer 4, but 2.0+2 returns real number 4.0. There are also two versions of division and modulo operators: 1.0/2 returns 0.5 while 1/2 returns 0.
typedef QVariant( * QgsExpression::FcnEval)(const QVariantList &values, const QgsFeature *f, QgsExpression *parent) |
typedef QList<WhenThen*> QgsExpression::WhenThenList |
QgsExpression::QgsExpression | ( | const QString & | expr | ) |
QgsExpression::~QgsExpression | ( | ) |
|
inlineprotected |
void QgsExpression::acceptVisitor | ( | QgsExpression::Visitor & | v | ) | const |
entry function for the visitor pattern
|
static |
|
inline |
Return the number used for $rownum special column.
QString QgsExpression::dump | ( | ) | const |
Return the expression string that represents this QgsExpression.
|
inline |
Returns evaluation error.
QVariant QgsExpression::evaluate | ( | const QgsFeature * | f = NULL | ) |
Evaluate the feature and return the result.
|
inline |
Evaluate the feature and return the result.
QVariant QgsExpression::evaluate | ( | const QgsFeature * | f, |
const QgsFields & | fields | ||
) |
Evaluate the feature and return the result.
|
inline |
Evaluate the feature and return the result.
|
inline |
Alias for dump()
|
static |
Returns the number of functions defined in the parser.
|
static |
|
static |
|
inline |
Return calculator used for distance and area calculations (used by internal functions)
|
static |
|
inline |
Returns true if an error occurred when evaluating last input.
|
inline |
Returns true if an error occurred when parsing the input expression.
|
static |
Check whether a special column exists.
|
static |
|
staticprotected |
|
protected |
|
static |
|
static |
bool QgsExpression::needsGeometry | ( | ) |
Returns true if the expression uses feature geometry for some computation.
|
inline |
Returns parser error.
bool QgsExpression::prepare | ( | const QgsFields & | fields | ) |
Get the expression ready for evaluation - find out column indexes.
|
static |
return quoted column reference (in double quotes)
|
static |
return quoted string (in single quotes)
QStringList QgsExpression::referencedColumns | ( | ) |
Get list of columns referenced by the expression.
|
static |
|
static |
This function currently replaces each expression between [% and %] in the string with the result of its evaluation on the feature passed as argument.
Additional substitutions can be passed through the substitutionMap parameter
action | |
feat | |
layer | |
substitutionMap | |
distanceArea | optional QgsDistanceArea. If specified, the QgsDistanceArea is used for distance and area conversion |
|
inline |
Returns root node of the expression. Root node is null is parsing has failed.
|
inline |
|
inline |
Set the number for $rownum special column.
|
inline |
Set evaluation error (used internally by evaluation functions)
void QgsExpression::setGeomCalculator | ( | const QgsDistanceArea & | calc | ) |
Sets the geometry calculator used in evaluation of expressions,.
|
inline |
|
static |
Assign a special column.
|
static |
Return the value of the given special column or a null QVariant if undefined.
|
static |
Returns a list of special Column definitions.
|
static |
|
static |
Unset a special column.
|
friend |
|
static |
|
staticprotected |
|
staticprotected |
|
static |
|
static |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
static |