QGIS API Documentation
2.8.2-Wien
|
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 | BinaryOperator { boOr, boAnd, boEQ, boNE, boLE, boGE, boLT, boGT, boRegexp, boLike, boNotLike, boILike, boNotILike, boIs, boIsNot, boPlus, boMinus, boMul, boDiv, boIntDiv, boMod, boPow, boConcat } |
list of binary operators More... | |
typedef QVariant(* | FcnEval )(const QVariantList &values, const QgsFeature *f, QgsExpression *parent) |
enum | NodeType { ntUnaryOperator, ntBinaryOperator, ntInOperator, ntFunction, ntLiteral, ntColumnRef, ntCondition } |
enum | SpatialOperator { soBbox, soIntersects, soContains, soCrosses, soEquals, soDisjoint, soOverlaps, soTouches, soWithin } |
enum | UnaryOperator { uoNot, uoMinus } |
list of unary operators More... | |
typedef QList< WhenThen * > | WhenThenList |
Public Member Functions | |
QgsExpression (const QString &expr) | |
~QgsExpression () | |
void | acceptVisitor (Visitor &v) const |
entry function for the visitor pattern | |
int | currentRowNumber () |
Return the number used for $rownum special column. | |
QString | dump () const |
Return the expression string that represents this QgsExpression. | |
QString | evalErrorString () const |
Returns evaluation error. | |
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. | |
const QString | expression () const |
Alias for dump() | |
QgsDistanceArea * | geomCalculator () |
Return calculator used for distance and area calculations (used by internal functions) | |
bool | hasEvalError () const |
Returns true if an error occurred when evaluating last input. | |
bool | hasParserError () const |
Returns true if an error occurred when parsing the input expression. | |
bool | needsGeometry () const |
Returns true if the expression uses feature geometry for some computation. | |
QString | parserErrorString () const |
Returns parser error. | |
bool | prepare (const QgsFields &fields) |
Get the expression ready for evaluation - find out column indexes. | |
QStringList | referencedColumns () const |
Get list of columns referenced by the expression. | |
const Node * | rootNode () const |
Returns root node of the expression. Root node is null is parsing has failed. | |
double | scale () |
void | setCurrentRowNumber (int rowNumber) |
Set the number for $rownum special column. | |
void | setEvalErrorString (QString str) |
Set evaluation error (used internally by evaluation functions) | |
void | setGeomCalculator (const QgsDistanceArea &calc) |
Sets the geometry calculator used in evaluation of expressions,. | |
void | setScale (double scale) |
Static Public Member Functions | |
static const QStringList & | BuiltinFunctions () |
static double | evaluateToDouble (const QString &text, const double fallbackValue) |
Attempts to evaluate a text string as an expression to a resultant double value. | |
static int | functionCount () |
Returns the number of functions defined in the parser. | |
static int | functionIndex (QString name) |
static const QList< Function * > & | Functions () |
static QString | group (QString group) |
static bool | hasSpecialColumn (const QString &name) |
Check whether a special column exists. | |
static QString | helptext (QString name) |
static bool | isFunctionName (QString name) |
static bool | isValid (const QString &text, const QgsFields &fields, QString &errorMessage) |
static QString | quotedColumnRef (QString name) |
return quoted column reference (in double quotes) | |
static QString | quotedString (QString text) |
return quoted string (in single quotes) | |
static bool | registerFunction (Function *function) |
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 void | setSpecialColumn (const QString &name, QVariant value) |
Assign a special column. | |
static QVariant | specialColumn (const QString &name) |
Return the value of the given special column or a null QVariant if undefined. | |
static QList< Function * > | specialColumns () |
Returns a list of special Column definitions. | |
static bool | unregisterFunction (QString name) |
static void | unsetSpecialColumn (const QString &name) |
Unset a special column. |
Static Public Attributes | |
static const char * | BinaryOperatorText [] |
static QStringList | gmBuiltinFunctions |
static QList< Function * > | gmFunctions |
static const char * | UnaryOperatorText [] |
Protected Member Functions | |
QgsExpression () | |
Used by QgsOgcUtils to create an empty. | |
void | initGeomCalculator () |
Static Protected Member Functions | |
static void | initFunctionHelp () |
Protected Attributes | |
QgsDistanceArea * | mCalc |
QString | mEvalErrorString |
QString | mExp |
QString | mParserErrorString |
Node * | mRootNode |
int | mRowNumber |
double | mScale |
Static Protected Attributes | |
static QHash< QString, QString > | gFunctionHelpTexts |
static QHash< QString, QString > | gGroups |
static QMap< QString, QString > | gmSpecialColumnGroups |
static QMap< QString, QVariant > | gmSpecialColumns |
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.
Definition at line 87 of file qgsexpression.h.
typedef QVariant( * QgsExpression::FcnEval)(const QVariantList &values, const QgsFeature *f, QgsExpression *parent) |
Definition at line 276 of file qgsexpression.h.
typedef QList<WhenThen*> QgsExpression::WhenThenList |
Definition at line 610 of file qgsexpression.h.
list of binary operators
boOr | |
boAnd | |
boEQ | |
boNE | |
boLE | |
boGE | |
boLT | |
boGT | |
boRegexp | |
boLike | |
boNotLike | |
boILike | |
boNotILike | |
boIs | |
boIsNot | |
boPlus | |
boMinus | |
boMul | |
boDiv | |
boIntDiv | |
boMod | |
boPow | |
boConcat |
Definition at line 227 of file qgsexpression.h.
ntUnaryOperator | |
ntBinaryOperator | |
ntInOperator | |
ntFunction | |
ntLiteral | |
ntColumnRef | |
ntCondition |
Definition at line 375 of file qgsexpression.h.
soBbox | |
soIntersects | |
soContains | |
soCrosses | |
soEquals | |
soDisjoint | |
soOverlaps | |
soTouches | |
soWithin |
Definition at line 260 of file qgsexpression.h.
list of unary operators
Definition at line 217 of file qgsexpression.h.
QgsExpression::QgsExpression | ( | const QString & | expr | ) |
Definition at line 1953 of file qgsexpression.cpp.
QgsExpression::~QgsExpression | ( | ) |
Definition at line 1965 of file qgsexpression.cpp.
|
inlineprotected |
Used by QgsOgcUtils to create an empty.
Definition at line 659 of file qgsexpression.h.
void QgsExpression::acceptVisitor | ( | QgsExpression::Visitor & | v | ) | const |
entry function for the visitor pattern
Definition at line 2061 of file qgsexpression.cpp.
|
static |
Definition at line 1660 of file qgsexpression.cpp.
|
inline |
Return the number used for $rownum special column.
Definition at line 147 of file qgsexpression.h.
QString QgsExpression::dump | ( | ) | const |
Return the expression string that represents this QgsExpression.
Definition at line 2053 of file qgsexpression.cpp.
|
inline |
Returns evaluation error.
Definition at line 140 of file qgsexpression.h.
QVariant QgsExpression::evaluate | ( | const QgsFeature * | f = NULL | ) |
Evaluate the feature and return the result.
Definition at line 2030 of file qgsexpression.cpp.
|
inline |
Evaluate the feature and return the result.
Definition at line 126 of file qgsexpression.h.
QVariant QgsExpression::evaluate | ( | const QgsFeature * | f, |
const QgsFields & | fields | ||
) |
Evaluate the feature and return the result.
Definition at line 2042 of file qgsexpression.cpp.
|
inline |
Evaluate the feature and return the result.
Definition at line 135 of file qgsexpression.h.
|
static |
Attempts to evaluate a text string as an expression to a resultant double value.
text | text to evaluate as expression |
fallbackValue | value to return if text can not be evaluated as a double |
Definition at line 2147 of file qgsexpression.cpp.
|
inline |
Alias for dump()
Definition at line 166 of file qgsexpression.h.
|
static |
Returns the number of functions defined in the parser.
Definition at line 1947 of file qgsexpression.cpp.
|
static |
Definition at line 1936 of file qgsexpression.cpp.
|
static |
Definition at line 1692 of file qgsexpression.cpp.
|
inline |
Return calculator used for distance and area calculations (used by internal functions)
Definition at line 179 of file qgsexpression.h.
|
static |
Definition at line 2832 of file qgsexpression.cpp.
|
inline |
Returns true if an error occurred when evaluating last input.
Definition at line 138 of file qgsexpression.h.
|
inline |
Returns true if an error occurred when parsing the input expression.
Definition at line 94 of file qgsexpression.h.
|
static |
Check whether a special column exists.
Definition at line 1862 of file qgsexpression.cpp.
|
static |
Definition at line 2824 of file qgsexpression.cpp.
|
staticprotected |
Definition at line 6 of file qgsexpression_texts.cpp.
|
protected |
Definition at line 2002 of file qgsexpression.cpp.
|
static |
Definition at line 1931 of file qgsexpression.cpp.
|
static |
Definition at line 1897 of file qgsexpression.cpp.
bool QgsExpression::needsGeometry | ( | ) | const |
Returns true if the expression uses feature geometry for some computation.
Definition at line 1995 of file qgsexpression.cpp.
|
inline |
Returns parser error.
Definition at line 96 of file qgsexpression.h.
bool QgsExpression::prepare | ( | const QgsFields & | fields | ) |
Get the expression ready for evaluation - find out column indexes.
Definition at line 2018 of file qgsexpression.cpp.
|
static |
return quoted column reference (in double quotes)
Definition at line 1917 of file qgsexpression.cpp.
|
static |
return quoted string (in single quotes)
Definition at line 1922 of file qgsexpression.cpp.
QStringList QgsExpression::referencedColumns | ( | ) | const |
Get list of columns referenced by the expression.
Definition at line 1971 of file qgsexpression.cpp.
|
static |
Definition at line 1629 of file qgsexpression.cpp.
|
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 |
Definition at line 2067 of file qgsexpression.cpp.
|
inline |
Returns root node of the expression. Root node is null is parsing has failed.
Definition at line 101 of file qgsexpression.h.
|
inline |
Definition at line 163 of file qgsexpression.h.
|
inline |
Set the number for $rownum special column.
Definition at line 145 of file qgsexpression.h.
|
inline |
Set evaluation error (used internally by evaluation functions)
Definition at line 142 of file qgsexpression.h.
void QgsExpression::setGeomCalculator | ( | const QgsDistanceArea & | calc | ) |
Sets the geometry calculator used in evaluation of expressions,.
Definition at line 2012 of file qgsexpression.cpp.
|
inline |
Definition at line 161 of file qgsexpression.h.
|
static |
Assign a special column.
Definition at line 1826 of file qgsexpression.cpp.
|
static |
Return the value of the given special column or a null QVariant if undefined.
Definition at line 1846 of file qgsexpression.cpp.
|
static |
Returns a list of special Column definitions.
Definition at line 1905 of file qgsexpression.cpp.
|
static |
Definition at line 1640 of file qgsexpression.cpp.
|
static |
Unset a special column.
Definition at line 1837 of file qgsexpression.cpp.
|
friend |
Definition at line 682 of file qgsexpression.h.
|
static |
Definition at line 273 of file qgsexpression.h.
|
staticprotected |
Definition at line 677 of file qgsexpression.h.
|
staticprotected |
Definition at line 678 of file qgsexpression.h.
|
static |
Definition at line 344 of file qgsexpression.h.
|
static |
Definition at line 342 of file qgsexpression.h.
|
staticprotected |
Definition at line 675 of file qgsexpression.h.
|
staticprotected |
Definition at line 674 of file qgsexpression.h.
|
protected |
Definition at line 672 of file qgsexpression.h.
|
protected |
Definition at line 666 of file qgsexpression.h.
|
protected |
Definition at line 670 of file qgsexpression.h.
|
protected |
Definition at line 665 of file qgsexpression.h.
|
protected |
Definition at line 663 of file qgsexpression.h.
|
protected |
Definition at line 668 of file qgsexpression.h.
|
protected |
Definition at line 669 of file qgsexpression.h.
|
static |
Definition at line 274 of file qgsexpression.h.