2011-08-09 20:48:13 +02:00
|
|
|
class QgsExpression
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include "qgsexpression.h"
|
|
|
|
%End
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Creates a new expression based on the provided string.
|
|
|
|
* The string will immediately be parsed. For optimization
|
|
|
|
* {@link prepare()} should alwys be called before every
|
|
|
|
* loop in which this expression is used.
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsExpression( const QString& expr );
|
|
|
|
~QgsExpression();
|
|
|
|
|
|
|
|
//! Returns true if an error occurred when parsing the input expression
|
|
|
|
bool hasParserError() const;
|
|
|
|
//! Returns parser error
|
|
|
|
QString parserErrorString() const;
|
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
//! Returns root node of the expression. Root node is null is parsing has failed
|
|
|
|
const QgsExpression::Node* rootNode() const;
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Get the expression ready for evaluation - find out column indexes.
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use prepare( const QgsExpressionContext *context ) instead
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
bool prepare( const QgsFields &fields ) /Deprecated/;
|
|
|
|
|
|
|
|
/** Get the expression ready for evaluation - find out column indexes.
|
|
|
|
* @param context context for preparing expression
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
bool prepare( const QgsExpressionContext *context );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-02-03 02:21:52 +01:00
|
|
|
/**
|
|
|
|
* Get list of columns referenced by the expression.
|
2014-07-09 21:29:20 +10:00
|
|
|
* @note if the returned list contains the QgsFeatureRequest::AllAttributes constant then
|
|
|
|
* all attributes from the layer are required for evaluation of the expression.
|
|
|
|
* QgsFeatureRequest::setSubsetOfAttributes automatically handles this case.
|
2016-02-14 03:50:23 +01:00
|
|
|
*
|
|
|
|
* TODO QGIS3: Return QSet<QString>
|
2014-07-09 21:29:20 +10:00
|
|
|
*/
|
2014-11-26 14:06:56 +01:00
|
|
|
QStringList referencedColumns() const;
|
2014-07-09 21:29:20 +10:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Returns true if the expression uses feature geometry for some computation
|
2014-11-26 14:06:56 +01:00
|
|
|
bool needsGeometry() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
// evaluation
|
|
|
|
|
|
|
|
//! Evaluate the feature and return the result
|
|
|
|
//! @note prepare() should be called before calling this method
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use evaluate( const QgsExpressionContext* context ) instead
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
QVariant evaluate( const QgsFeature* f ) /Deprecated/;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
//! Evaluate the feature and return the result
|
|
|
|
//! @note prepare() should be called before calling this method
|
|
|
|
//! @note available in python bindings as evaluatePrepared
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use evaluate( const QgsExpressionContext* context ) instead
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
QVariant evaluate( const QgsFeature& f ) /PyName=evaluatePrepared,Deprecated/;
|
2014-01-26 18:35:21 +01:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Evaluate the feature and return the result
|
|
|
|
//! @note this method does not expect that prepare() has been called on this instance
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use evaluate( const QgsExpressionContext* context ) instead
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
QVariant evaluate( const QgsFeature* f, const QgsFields& fields ) /Deprecated/;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-05-29 01:42:53 +02:00
|
|
|
//! Evaluate the feature and return the result
|
|
|
|
//! @note this method does not expect that prepare() has been called on this instance
|
|
|
|
//! @note not available in python bindings
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use evaluate( const QgsExpressionContext* context ) instead
|
2014-05-29 01:42:53 +02:00
|
|
|
// inline QVariant evaluate( const QgsFeature& f, const QgsFields& fields ) { return evaluate( &f, fields ); }
|
|
|
|
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
/** Evaluate the feature and return the result.
|
2016-02-14 03:50:23 +01:00
|
|
|
* @note this method does not expect that prepare() has been called on this instance
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
QVariant evaluate();
|
|
|
|
|
|
|
|
/** Evaluate the expression against the specified context and return the result.
|
|
|
|
* @param context context for evaluating expression
|
|
|
|
* @note prepare() should be called before calling this method.
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
QVariant evaluate( const QgsExpressionContext* context );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Returns true if an error occurred when evaluating last input
|
|
|
|
bool hasEvalError() const;
|
|
|
|
//! Returns evaluation error
|
|
|
|
QString evalErrorString() const;
|
|
|
|
//! Set evaluation error (used internally by evaluation functions)
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
void setEvalErrorString( const QString& str );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! Set the number for $rownum special column
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use QgsExpressionContext to set row number instead
|
2015-08-12 22:51:02 +10:00
|
|
|
void setCurrentRowNumber( int rowNumber ) /Deprecated/;
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Return the number used for $rownum special column
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use QgsExpressionContext to retrieve row number instead
|
2016-02-14 03:50:23 +01:00
|
|
|
int currentRowNumber() /Deprecated/; //TODO QGIS 3.0: make the following methods private. They are still required for replaceExpressionText
|
|
|
|
//but should not be publicly used
|
2015-09-07 19:19:24 +10:00
|
|
|
/** Assign a special column
|
|
|
|
* @deprecated use global or project QgsExpressionContext variables instead
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
static void setSpecialColumn( const QString& name, const QVariant& value ) /Deprecated/;
|
2015-09-07 19:19:24 +10:00
|
|
|
/** Unset a special column
|
|
|
|
* @deprecated use global or project QgsExpressionContext variables instead
|
|
|
|
*/
|
|
|
|
static void unsetSpecialColumn( const QString& name ) /Deprecated/;
|
|
|
|
/** Return the value of the given special column or a null QVariant if undefined
|
|
|
|
* @deprecated use global or project QgsExpressionContext variables instead
|
|
|
|
*/
|
|
|
|
static QVariant specialColumn( const QString& name ) /Deprecated/;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/** Check whether a special column exists
|
|
|
|
* @note added in 2.2
|
|
|
|
*/
|
2014-02-11 23:55:11 +07:00
|
|
|
static bool hasSpecialColumn( const QString& name );
|
2012-10-04 11:18:17 +02:00
|
|
|
|
2015-04-27 09:10:59 +10:00
|
|
|
/** Checks whether an expression consists only of a single field reference
|
|
|
|
* @note added in 2.9
|
|
|
|
*/
|
|
|
|
bool isField() const;
|
|
|
|
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use QgsExpressionContext variant instead
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
static bool isValid( const QString& text, const QgsFields& fields, QString &errorMessage ) /Deprecated/;
|
|
|
|
|
|
|
|
/** Tests whether a string is a valid expression.
|
|
|
|
* @param text string to test
|
|
|
|
* @param context optional expression context
|
|
|
|
* @param errorMessage will be filled with any error message from the validation
|
|
|
|
* @returns true if string is a valid expression
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
static bool isValid( const QString& text, const QgsExpressionContext* context, QString &errorMessage );
|
2014-06-14 11:47:05 +02:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
void setScale( double scale );
|
|
|
|
|
2014-05-29 01:42:53 +02:00
|
|
|
double scale();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-12-09 15:44:56 +01:00
|
|
|
//! Return the original, unmodified expression string.
|
|
|
|
//! If there was none supplied because it was constructed by sole
|
|
|
|
//! API calls, dump() will be used to create one instead.
|
|
|
|
QString expression() const;
|
|
|
|
|
|
|
|
//! Return an expression string, constructed from the internal
|
|
|
|
//! abstract syntax tree. This does not contain any nice whitespace
|
|
|
|
//! formatting or comments. In general it is preferrable to use
|
|
|
|
//! expression() instead.
|
2012-09-24 02:28:15 +02:00
|
|
|
QString dump() const;
|
|
|
|
|
2016-02-12 19:24:52 +11:00
|
|
|
/** Return calculator used for distance and area calculations
|
|
|
|
* (used by $length, $area and $perimeter functions only)
|
|
|
|
* @see setGeomCalculator()
|
2016-02-13 11:23:58 +11:00
|
|
|
* @see distanceUnits()
|
2016-02-12 19:24:52 +11:00
|
|
|
*/
|
2014-01-26 18:35:21 +01:00
|
|
|
QgsDistanceArea *geomCalculator();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-02-12 19:24:52 +11:00
|
|
|
/** Sets the geometry calculator used for distance and area calculations in expressions.
|
|
|
|
* (used by $length, $area and $perimeter functions only). By default, no geometry
|
|
|
|
* calculator is set and all distance and area calculations are performed using simple
|
|
|
|
* cartesian methods (ie no ellipsoidal calculations).
|
|
|
|
* @see geomCalculator()
|
|
|
|
*/
|
2016-02-14 03:50:23 +01:00
|
|
|
//TODO QGIS 3.0 change calc to a pointer, so that calculator can be cleared by passing nullptr
|
2014-01-26 18:35:21 +01:00
|
|
|
void setGeomCalculator( const QgsDistanceArea &calc );
|
2014-11-13 23:13:13 +01:00
|
|
|
|
2016-02-13 11:23:58 +11:00
|
|
|
/** Returns the desired distance units for calculations involving geomCalculator(), eg "$length" and "$perimeter".
|
|
|
|
* @note distances are only converted when a geomCalculator() has been set
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see setDistanceUnits()
|
|
|
|
*/
|
|
|
|
QGis::UnitType distanceUnits() const;
|
|
|
|
|
|
|
|
/** Sets the desired distance units for calculations involving geomCalculator(), eg "$length" and "$perimeter".
|
|
|
|
* @note distances are only converted when a geomCalculator() has been set
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see distanceUnits()
|
|
|
|
*/
|
|
|
|
void setDistanceUnits( QGis::UnitType unit );
|
|
|
|
|
2016-02-15 19:02:19 +11:00
|
|
|
/** Returns the desired areal units for calculations involving geomCalculator(), eg "$area".
|
|
|
|
* @note areas are only converted when a geomCalculator() has been set
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see setAreaUnits()
|
|
|
|
* @see distanceUnits()
|
|
|
|
*/
|
|
|
|
QgsUnitTypes::AreaUnit areaUnits() const;
|
|
|
|
|
|
|
|
/** Sets the desired areal units for calculations involving geomCalculator(), eg "$area".
|
|
|
|
* @note areas are only converted when a geomCalculator() has been set
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see areaUnits()
|
|
|
|
* @see setDistanceUnits()
|
|
|
|
*/
|
|
|
|
void setAreaUnits( QgsUnitTypes::AreaUnit unit );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/** This function currently replaces each expression between [% and %]
|
2016-02-14 03:50:23 +01:00
|
|
|
* in the string with the result of its evaluation on the feature
|
|
|
|
* passed as argument.
|
|
|
|
*
|
|
|
|
* Additional substitutions can be passed through the substitutionMap
|
|
|
|
* parameter
|
|
|
|
* @param action
|
|
|
|
* @param feat
|
|
|
|
* @param layer
|
|
|
|
* @param substitutionMap
|
|
|
|
* @param distanceArea optional QgsDistanceArea. If specified, the QgsDistanceArea is used for distance and area conversion
|
|
|
|
* @deprecated use QgsExpressionContext variant instead
|
|
|
|
*/
|
2014-01-26 18:35:21 +01:00
|
|
|
static QString replaceExpressionText( const QString &action, const QgsFeature *feat,
|
|
|
|
QgsVectorLayer *layer,
|
2014-10-19 11:02:16 +11:00
|
|
|
const QMap<QString, QVariant> *substitutionMap = 0,
|
2016-02-14 03:50:23 +01:00
|
|
|
const QgsDistanceArea* distanceArea = 0 ) /Deprecated/;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
|
|
|
|
/** This function replaces each expression between [% and %]
|
2016-02-14 03:50:23 +01:00
|
|
|
* in the string with the result of its evaluation with the specified context
|
|
|
|
*
|
|
|
|
* Additional substitutions can be passed through the substitutionMap parameter
|
|
|
|
* @param action
|
|
|
|
* @param context expression context
|
|
|
|
* @param substitutionMap
|
|
|
|
* @param distanceArea optional QgsDistanceArea. If specified, the QgsDistanceArea is used for distance
|
|
|
|
* and area conversion
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
static QString replaceExpressionText( const QString &action, const QgsExpressionContext* context,
|
2016-02-14 03:50:23 +01:00
|
|
|
const QMap<QString, QVariant> *substitutionMap = 0,
|
|
|
|
const QgsDistanceArea* distanceArea = 0 );
|
2014-10-19 11:02:16 +11:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Attempts to evaluate a text string as an expression to a resultant double
|
2014-12-04 23:07:27 +11:00
|
|
|
* value.
|
|
|
|
* @param text text to evaluate as expression
|
|
|
|
* @param fallbackValue value to return if text can not be evaluated as a double
|
|
|
|
* @returns evaluated double value, or fallback value
|
|
|
|
* @note added in QGIS 2.7
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
* @note this method is inefficient for bulk evaluation of expressions, it is intended
|
|
|
|
* for one-off evaluations only.
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2014-12-04 23:07:27 +11:00
|
|
|
static double evaluateToDouble( const QString& text, const double fallbackValue );
|
|
|
|
|
2015-02-03 02:21:52 +01:00
|
|
|
/**
|
|
|
|
* @brief list of unary operators
|
|
|
|
* @note if any change is made here, the definition of QgsExpression::UnaryOperatorText[] must be adapted.
|
|
|
|
*/
|
2012-01-06 19:25:04 +01:00
|
|
|
enum UnaryOperator
|
|
|
|
{
|
|
|
|
uoNot,
|
|
|
|
uoMinus,
|
|
|
|
};
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief list of binary operators
|
|
|
|
* @note if any change is made here, the definition of QgsExpression::BinaryOperatorText[] must be adapted.
|
|
|
|
*/
|
2012-01-06 19:25:04 +01:00
|
|
|
enum BinaryOperator
|
|
|
|
{
|
|
|
|
// logical
|
|
|
|
boOr,
|
|
|
|
boAnd,
|
2011-08-09 20:48:13 +02:00
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
// comparison
|
|
|
|
boEQ, // =
|
|
|
|
boNE, // <>
|
|
|
|
boLE, // <=
|
|
|
|
boGE, // >=
|
|
|
|
boLT, // <
|
|
|
|
boGT, // >
|
|
|
|
boRegexp,
|
|
|
|
boLike,
|
2012-09-24 02:28:15 +02:00
|
|
|
boNotLike,
|
2012-01-06 19:25:04 +01:00
|
|
|
boILike,
|
2012-09-24 02:28:15 +02:00
|
|
|
boNotILike,
|
2012-01-06 19:25:04 +01:00
|
|
|
boIs,
|
|
|
|
boIsNot,
|
|
|
|
|
|
|
|
// math
|
|
|
|
boPlus,
|
|
|
|
boMinus,
|
|
|
|
boMul,
|
|
|
|
boDiv,
|
2014-12-06 16:35:06 +11:00
|
|
|
boIntDiv,
|
2012-01-06 19:25:04 +01:00
|
|
|
boMod,
|
|
|
|
boPow,
|
|
|
|
|
|
|
|
// strings
|
|
|
|
boConcat,
|
|
|
|
};
|
2016-02-14 03:50:23 +01:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
enum SpatialOperator
|
|
|
|
{
|
|
|
|
soBbox,
|
|
|
|
soIntersects,
|
|
|
|
soContains,
|
|
|
|
soCrosses,
|
|
|
|
soEquals,
|
|
|
|
soDisjoint,
|
|
|
|
soOverlaps,
|
|
|
|
soTouches,
|
|
|
|
soWithin,
|
|
|
|
};
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
//! @note not available in Python bindings
|
2012-09-24 02:28:15 +02:00
|
|
|
// static const char* BinaryOperatorText[];
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
//! @note not available in Python bindings
|
2012-09-24 02:28:15 +02:00
|
|
|
// static const char* UnaryOperatorText[];
|
|
|
|
|
2016-03-29 16:22:04 +11:00
|
|
|
/**
|
|
|
|
* Represents a single parameter passed to a function.
|
|
|
|
* \note added in QGIS 2.16
|
|
|
|
*/
|
|
|
|
class Parameter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Constructor for Parameter.
|
|
|
|
* @param name parameter name, used when named parameter are specified in an expression
|
|
|
|
* @param optional set to true if parameter should be optional
|
|
|
|
* @param defaultValue default value to use for optional parameters
|
|
|
|
*/
|
|
|
|
Parameter( const QString& name,
|
|
|
|
bool optional = false,
|
|
|
|
const QVariant& defaultValue = QVariant() );
|
|
|
|
|
|
|
|
//! Returns the name of the parameter.
|
|
|
|
QString name() const;
|
|
|
|
|
|
|
|
//! Returns true if the parameter is optional.
|
|
|
|
bool optional() const;
|
|
|
|
|
|
|
|
//! Returns the default value for the parameter.
|
|
|
|
QVariant defaultValue() const;
|
|
|
|
|
|
|
|
bool operator==( const QgsExpression::Parameter& other ) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//! List of parameters, used for function definition
|
|
|
|
typedef QList< QgsExpression::Parameter > ParameterList;
|
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/**
|
2016-02-14 03:50:23 +01:00
|
|
|
* A abstract base class for defining QgsExpression functions.
|
|
|
|
*/
|
2012-11-04 21:56:49 +10:00
|
|
|
class Function
|
2012-01-06 19:25:04 +01:00
|
|
|
{
|
2012-11-04 21:56:49 +10:00
|
|
|
public:
|
2016-03-29 16:22:04 +11:00
|
|
|
|
|
|
|
//! Constructor for function which uses unnamed parameters
|
2015-06-06 10:42:55 +02:00
|
|
|
Function( const QString& fnname,
|
|
|
|
int params,
|
2015-10-07 11:55:34 +11:00
|
|
|
const QString& group,
|
|
|
|
const QString& helpText = QString(),
|
2015-06-06 10:42:55 +02:00
|
|
|
bool usesGeometry = false,
|
2015-10-07 11:55:34 +11:00
|
|
|
const QStringList& referencedColumns = QStringList(),
|
2015-06-06 10:42:55 +02:00
|
|
|
bool lazyEval = false,
|
2015-08-20 15:06:09 +10:00
|
|
|
bool handlesNull = false,
|
|
|
|
bool isContextual = false );
|
2015-05-29 08:57:54 +02:00
|
|
|
|
2016-03-29 16:22:04 +11:00
|
|
|
/** Constructor for function which uses named parameter list.
|
|
|
|
* @note added in QGIS 2.16
|
|
|
|
*/
|
|
|
|
Function( const QString& fnname,
|
|
|
|
const QgsExpression::ParameterList& params,
|
|
|
|
const QString& group,
|
|
|
|
const QString& helpText = QString(),
|
|
|
|
bool usesGeometry = false,
|
|
|
|
const QStringList& referencedColumns = QStringList(),
|
|
|
|
bool lazyEval = false,
|
|
|
|
bool handlesNull = false,
|
|
|
|
bool isContextual = false );
|
|
|
|
|
2015-05-27 22:39:23 +10:00
|
|
|
virtual ~Function();
|
2015-05-29 08:57:54 +02:00
|
|
|
|
2012-11-04 21:56:49 +10:00
|
|
|
/** The name of the function. */
|
2016-03-29 16:22:04 +11:00
|
|
|
QString name() const;
|
2012-11-04 21:56:49 +10:00
|
|
|
/** The number of parameters this function takes. */
|
2016-03-29 16:22:04 +11:00
|
|
|
int params() const;
|
|
|
|
|
|
|
|
/** The mininum number of parameters this function takes. */
|
|
|
|
int minParams() const;
|
|
|
|
|
|
|
|
/** Returns the list of named parameters for the function, if set.
|
|
|
|
* @note added in QGIS 2.16
|
|
|
|
*/
|
|
|
|
const QgsExpression::ParameterList& parameters() const;
|
|
|
|
|
2012-11-04 21:56:49 +10:00
|
|
|
/** Does this function use a geometry object. */
|
2016-03-29 16:22:04 +11:00
|
|
|
bool usesgeometry() const;
|
2014-07-09 21:29:20 +10:00
|
|
|
|
2015-05-03 18:40:09 +10:00
|
|
|
/** Returns a list of possible aliases for the function. These include
|
|
|
|
* other permissible names for the function, eg deprecated names.
|
|
|
|
* @return list of known aliases
|
|
|
|
* @note added in QGIS 2.9
|
|
|
|
*/
|
|
|
|
virtual QStringList aliases() const;
|
|
|
|
|
2015-02-03 02:21:52 +01:00
|
|
|
/** True if this function should use lazy evaluation. Lazy evaluation functions take QgsExpression::Node objects
|
|
|
|
* rather than the node results when called. You can use node->eval(parent, feature) to evaluate the node and return the result
|
2016-02-14 03:50:23 +01:00
|
|
|
* Functions are non lazy default and will be given the node return value when called
|
|
|
|
*/
|
2016-03-29 16:22:04 +11:00
|
|
|
bool lazyEval() const;
|
2015-02-03 02:21:52 +01:00
|
|
|
|
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
|
2015-08-20 15:06:09 +10:00
|
|
|
/** Returns whether the function is only available if provided by a QgsExpressionContext object.
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
bool isContextual() const;
|
|
|
|
|
2012-11-04 21:56:49 +10:00
|
|
|
/** The group the function belongs to. */
|
2016-03-29 16:22:04 +11:00
|
|
|
QString group() const;
|
2012-11-04 21:56:49 +10:00
|
|
|
/** The help text for the function. */
|
2016-03-29 16:22:04 +11:00
|
|
|
const QString helptext() const;
|
2012-11-04 21:56:49 +10:00
|
|
|
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated Use QgsExpressionContext variant instead
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual QVariant func( const QVariantList& values, const QgsFeature* f, QgsExpression* parent ) /Deprecated/;
|
|
|
|
|
|
|
|
/** Returns result of evaluating the function.
|
|
|
|
* @param values list of values passed to the function
|
|
|
|
* @param context context expression is being evaluated against
|
|
|
|
* @param parent parent expression
|
|
|
|
* @returns result of function
|
2015-09-05 22:03:16 +10:00
|
|
|
* @note named funcV2 in Python bindings. Will be renamed to func to replace deprecated method in QGIS 3.0.
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
*/
|
2016-02-14 03:50:23 +01:00
|
|
|
//TODO QGIS 3.0 - rename python method
|
|
|
|
virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) /PyName=funcV2/;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2015-06-06 10:42:55 +02:00
|
|
|
virtual bool handlesNull() const;
|
|
|
|
};
|
2014-01-26 18:35:21 +01:00
|
|
|
|
2015-04-23 16:10:54 +02:00
|
|
|
static const QList<QgsExpression::Function *>& Functions();
|
|
|
|
static const QStringList& BuiltinFunctions();
|
2012-11-04 21:56:49 +10:00
|
|
|
|
2015-08-25 21:37:57 +10:00
|
|
|
/** Registers a function to the expression engine. This is required to allow expressions to utilise the function.
|
|
|
|
* @param function function to register
|
2016-02-14 03:50:23 +01:00
|
|
|
* @param transferOwnership set to true to transfer ownership of function to expression engine
|
2015-08-25 21:37:57 +10:00
|
|
|
* @returns true on successful registration
|
|
|
|
* @see unregisterFunction
|
|
|
|
*/
|
2014-01-26 18:35:21 +01:00
|
|
|
static bool registerFunction( Function* function );
|
2015-08-25 21:37:57 +10:00
|
|
|
|
|
|
|
/** Unregisters a function from the expression engine. The function will no longer be usable in expressions.
|
|
|
|
* @param name function name
|
|
|
|
* @see registerFunction
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
static bool unregisterFunction( const QString& name );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2015-08-25 21:37:57 +10:00
|
|
|
/** Deletes all registered functions whose ownership have been transferred to the expression engine.
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
static void cleanRegisteredFunctions();
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
//! tells whether the identifier is a name of existing function
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
static bool isFunctionName( const QString& name );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
//! return index of the function in Functions array
|
2015-05-03 18:40:09 +10:00
|
|
|
static int functionIndex( const QString& name );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the number of functions defined in the parser
|
2016-02-14 03:50:23 +01:00
|
|
|
* @return The number of function defined in the parser.
|
|
|
|
*/
|
2012-01-06 19:25:04 +01:00
|
|
|
static int functionCount();
|
|
|
|
|
2012-10-04 11:18:17 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of special Column definitions
|
|
|
|
*/
|
2012-11-04 21:56:49 +10:00
|
|
|
static QList<QgsExpression::Function *> specialColumns();
|
2012-10-04 11:18:17 +02:00
|
|
|
|
2015-12-01 19:33:27 +11:00
|
|
|
/** Returns a quoted column reference (in double quotes)
|
|
|
|
* @see quotedString()
|
|
|
|
* @see quotedValue()
|
|
|
|
*/
|
2012-01-06 19:25:04 +01:00
|
|
|
static QString quotedColumnRef( QString name );
|
2015-12-01 19:33:27 +11:00
|
|
|
|
|
|
|
/** Returns a quoted version of a string (in single quotes)
|
|
|
|
* @see quotedValue()
|
|
|
|
* @see quotedColumnRef()
|
|
|
|
*/
|
2012-06-02 00:04:01 +02:00
|
|
|
static QString quotedString( QString text );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2015-12-01 19:33:27 +11:00
|
|
|
/** Returns a string representation of a literal value, including appropriate
|
|
|
|
* quotations where required.
|
|
|
|
* @param value value to convert to a string representation
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see quotedString()
|
|
|
|
* @see quotedColumnRef()
|
|
|
|
*/
|
|
|
|
static QString quotedValue( const QVariant& value );
|
|
|
|
|
|
|
|
/** Returns a string representation of a literal value, including appropriate
|
|
|
|
* quotations where required.
|
|
|
|
* @param value value to convert to a string representation
|
|
|
|
* @param type value type
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see quotedString()
|
|
|
|
* @see quotedColumnRef()
|
|
|
|
*/
|
|
|
|
static QString quotedValue( const QVariant& value, QVariant::Type type );
|
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
//////
|
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
enum NodeType
|
|
|
|
{
|
|
|
|
ntUnaryOperator,
|
|
|
|
ntBinaryOperator,
|
|
|
|
ntInOperator,
|
|
|
|
ntFunction,
|
|
|
|
ntLiteral,
|
|
|
|
ntColumnRef,
|
|
|
|
ntCondition
|
|
|
|
};
|
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
class Node
|
|
|
|
{
|
2015-05-12 17:24:57 +01:00
|
|
|
%ConvertToSubClassCode
|
|
|
|
switch (sipCpp->nodeType())
|
|
|
|
{
|
2015-10-20 18:09:33 +02:00
|
|
|
case QgsExpression::ntUnaryOperator: sipType = sipType_QgsExpression_NodeUnaryOperator; break;
|
|
|
|
case QgsExpression::ntBinaryOperator: sipType = sipType_QgsExpression_NodeBinaryOperator; break;
|
|
|
|
case QgsExpression::ntInOperator: sipType = sipType_QgsExpression_NodeInOperator; break;
|
|
|
|
case QgsExpression::ntFunction: sipType = sipType_QgsExpression_NodeFunction; break;
|
|
|
|
case QgsExpression::ntLiteral: sipType = sipType_QgsExpression_NodeLiteral; break;
|
|
|
|
case QgsExpression::ntColumnRef: sipType = sipType_QgsExpression_NodeColumnRef; break;
|
|
|
|
case QgsExpression::ntCondition: sipType = sipType_QgsExpression_NodeCondition; break;
|
|
|
|
default: sipType = 0; break;
|
2015-05-12 17:24:57 +01:00
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
public:
|
|
|
|
virtual ~Node();
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract virtual that returns the type of this node.
|
|
|
|
*
|
|
|
|
* @return The type of this node
|
|
|
|
*/
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const = 0;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract virtual eval method
|
|
|
|
* Errors are reported to the parent
|
|
|
|
* @deprecated use QgsExpressionContext variant instead
|
|
|
|
*/
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsFeature* f ) /Deprecated/;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Abstract virtual eval method
|
|
|
|
* Errors are reported to the parent
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
2016-02-14 03:50:23 +01:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Abstract virtual preparation method
|
|
|
|
* Errors are reported to the parent
|
|
|
|
* @deprecated use QgsExpressionContext variant instead
|
|
|
|
*/
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsFields &fields ) /Deprecated/;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Abstract virtual preparation method
|
|
|
|
* Errors are reported to the parent
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Abstract virtual dump method
|
|
|
|
*
|
|
|
|
* @return An expression which represents this node as string
|
|
|
|
*/
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QString dump() const = 0;
|
|
|
|
|
2015-12-09 15:44:56 +01:00
|
|
|
/**
|
|
|
|
* Generate a clone of this node.
|
|
|
|
* Make sure that the clone does not contain any information which is
|
|
|
|
* generated in prepare and context related.
|
|
|
|
* Ownership is transferred to the caller.
|
|
|
|
*
|
|
|
|
* @return a deep copy of this node.
|
|
|
|
*/
|
|
|
|
virtual QgsExpression::Node* clone() const = 0;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract virtual method which returns a list of columns required to
|
|
|
|
* evaluate this node.
|
|
|
|
*
|
|
|
|
* When reimplementing this, you need to return any column that is required to
|
|
|
|
* evaluate this node and in addition recursively collect all the columns required
|
|
|
|
* to evaluate child nodes.
|
|
|
|
*
|
|
|
|
* @return A list of columns required to evaluate this expression
|
|
|
|
*/
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QStringList referencedColumns() const = 0;
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract virtual method which returns if the geometry is required to evaluate
|
|
|
|
* this expression.
|
|
|
|
*
|
|
|
|
* This needs to call `needsGeometry()` recursively on any child nodes.
|
|
|
|
*
|
|
|
|
* @return true if a geometry is required to evaluate this expression
|
|
|
|
*/
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual bool needsGeometry() const = 0;
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/**
|
|
|
|
* Support the visitor pattern.
|
|
|
|
*
|
|
|
|
* For any implementation this should look like
|
|
|
|
*
|
|
|
|
* C++:
|
|
|
|
*
|
|
|
|
* v.visit( *this );
|
|
|
|
*
|
|
|
|
* Python:
|
|
|
|
*
|
|
|
|
* v.visit( self)
|
|
|
|
*
|
|
|
|
* @param v A visitor that visits this node.
|
|
|
|
*/
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const = 0;
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
2016-03-29 16:22:04 +11:00
|
|
|
//! Named node
|
|
|
|
//! @note added in QGIS 2.16
|
|
|
|
class NamedNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Constructor for NamedNode
|
|
|
|
* @param name node name
|
|
|
|
* @param node node
|
|
|
|
*/
|
|
|
|
NamedNode( const QString& name, QgsExpression::Node* node );
|
|
|
|
|
|
|
|
//! Node name
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
//! Node
|
|
|
|
QgsExpression::Node* node;
|
|
|
|
};
|
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
class NodeList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NodeList();
|
|
|
|
~NodeList();
|
2015-06-06 10:42:55 +02:00
|
|
|
/** Takes ownership of the provided node */
|
2014-01-26 18:35:21 +01:00
|
|
|
void append( QgsExpression::Node* node /Transfer/ );
|
2016-03-29 16:22:04 +11:00
|
|
|
|
|
|
|
/** Adds a named node. Takes ownership of the provided node.
|
|
|
|
* @note added in QGIS 2.16
|
|
|
|
*/
|
|
|
|
void append( QgsExpression::NamedNode* node /Transfer/ );
|
|
|
|
|
|
|
|
/** Returns the number of nodes in the list.
|
|
|
|
*/
|
|
|
|
int count() const;
|
|
|
|
|
|
|
|
//! Returns true if list contains any named nodes
|
|
|
|
//! @note added in QGIS 2.16
|
|
|
|
bool hasNamedNodes() const;
|
|
|
|
|
2015-04-23 18:36:41 +02:00
|
|
|
const QList<QgsExpression::Node*>& list();
|
2016-03-29 16:22:04 +11:00
|
|
|
|
|
|
|
//! Returns a list of names for nodes. Unnamed nodes will be indicated by an empty string in the list.
|
|
|
|
//! @note added in QGIS 2.16
|
|
|
|
QStringList names() const;
|
|
|
|
|
2015-12-09 15:44:56 +01:00
|
|
|
/** Creates a deep copy of this list. Ownership is transferred to the caller */
|
|
|
|
QgsExpression::NodeList* clone() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
|
|
|
virtual QString dump() const;
|
|
|
|
};
|
|
|
|
|
2016-05-10 12:27:54 +10:00
|
|
|
//TODO QGIS 3.0 - remove
|
|
|
|
//! @deprecated use QgsInterval instead
|
2012-09-24 02:28:15 +02:00
|
|
|
class Interval
|
2016-05-10 12:27:54 +10:00
|
|
|
{
|
2014-01-26 18:35:21 +01:00
|
|
|
public:
|
|
|
|
Interval( int seconds = 0 );
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
//! interval length in years
|
2016-05-10 12:27:54 +10:00
|
|
|
double years() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! interval length in months
|
2016-05-10 12:27:54 +10:00
|
|
|
double months() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! interval length in weeks
|
2016-05-10 12:27:54 +10:00
|
|
|
double weeks() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! interval length in days
|
2016-05-10 12:27:54 +10:00
|
|
|
double days() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! interval length in hours
|
2016-05-10 12:27:54 +10:00
|
|
|
double hours() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! interval length in minutus
|
2016-05-10 12:27:54 +10:00
|
|
|
double minutes() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! interval length in seconds
|
2016-05-10 12:27:54 +10:00
|
|
|
double seconds() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! getter interval validity
|
2016-05-10 12:27:54 +10:00
|
|
|
bool isValid() const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! setter interval validity
|
2014-01-26 18:35:21 +01:00
|
|
|
void setValid( bool valid );
|
2016-02-14 03:50:23 +01:00
|
|
|
//! compare two intervals
|
2016-02-02 19:46:18 +11:00
|
|
|
bool operator==( QgsExpression::Interval other ) const;
|
2016-02-14 03:50:23 +01:00
|
|
|
//! convert a string to an interval
|
2015-10-07 11:55:34 +11:00
|
|
|
static QgsExpression::Interval fromString( const QString& string );
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeUnaryOperator : QgsExpression::Node
|
|
|
|
{
|
|
|
|
public:
|
2014-01-26 18:35:21 +01:00
|
|
|
NodeUnaryOperator( QgsExpression::UnaryOperator op, QgsExpression::Node* operand /Transfer/ );
|
2012-01-06 19:25:04 +01:00
|
|
|
~NodeUnaryOperator();
|
|
|
|
|
2013-03-13 23:03:10 +01:00
|
|
|
QgsExpression::UnaryOperator op() const;
|
|
|
|
QgsExpression::Node* operand() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2016-02-14 03:50:23 +01:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QString dump() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
virtual bool needsGeometry() const;
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const;
|
2015-12-09 15:44:56 +01:00
|
|
|
virtual QgsExpression::Node* clone() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeBinaryOperator : QgsExpression::Node
|
|
|
|
{
|
|
|
|
public:
|
2014-01-26 18:35:21 +01:00
|
|
|
NodeBinaryOperator( QgsExpression::BinaryOperator op, QgsExpression::Node* opLeft /Transfer/, QgsExpression::Node* opRight /Transfer/ );
|
2012-01-06 19:25:04 +01:00
|
|
|
~NodeBinaryOperator();
|
|
|
|
|
2013-03-13 23:03:10 +01:00
|
|
|
QgsExpression::BinaryOperator op() const;
|
|
|
|
QgsExpression::Node* opLeft() const;
|
|
|
|
QgsExpression::Node* opRight() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2016-02-14 03:50:23 +01:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QString dump() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
virtual bool needsGeometry() const;
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const;
|
2015-12-09 15:44:56 +01:00
|
|
|
virtual QgsExpression::Node* clone() const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
|
|
|
int precedence() const;
|
2014-12-11 14:04:44 +01:00
|
|
|
bool leftAssociative() const;
|
2016-01-04 22:51:18 +11:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool compare( double diff );
|
|
|
|
int computeInt( int x, int y );
|
|
|
|
double computeDouble( double x, double y );
|
2016-05-10 12:27:54 +10:00
|
|
|
|
|
|
|
/** Computes the result date time calculation from a start datetime and an interval
|
|
|
|
* @param d start datetime
|
|
|
|
* @param i interval to add or subtract (depending on mOp)
|
|
|
|
*/
|
|
|
|
QDateTime computeDateTimeFromInterval( const QDateTime& d, QgsInterval *i );
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeInOperator : QgsExpression::Node
|
|
|
|
{
|
|
|
|
public:
|
2014-01-26 18:35:21 +01:00
|
|
|
NodeInOperator( QgsExpression::Node* node /Transfer/, QgsExpression::NodeList* list /Transfer/, bool notin = false );
|
2012-01-06 19:25:04 +01:00
|
|
|
~NodeInOperator();
|
|
|
|
|
2013-03-13 23:03:10 +01:00
|
|
|
QgsExpression::Node* node() const;
|
|
|
|
bool isNotIn() const;
|
|
|
|
QgsExpression::NodeList* list() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2016-02-14 03:50:23 +01:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QString dump() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
virtual bool needsGeometry() const;
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const;
|
2015-12-09 15:44:56 +01:00
|
|
|
virtual QgsExpression::Node* clone() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeFunction : QgsExpression::Node
|
|
|
|
{
|
|
|
|
public:
|
2014-01-26 18:35:21 +01:00
|
|
|
NodeFunction( int fnIndex, QgsExpression::NodeList* args /Transfer/ );
|
2012-01-06 19:25:04 +01:00
|
|
|
//NodeFunction( QString name, QgsExpression::NodeList* args );
|
|
|
|
~NodeFunction();
|
|
|
|
|
2013-03-13 23:03:10 +01:00
|
|
|
int fnIndex() const;
|
|
|
|
QgsExpression::NodeList* args() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2016-02-14 03:50:23 +01:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QString dump() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
virtual bool needsGeometry() const;
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const;
|
2015-12-09 15:44:56 +01:00
|
|
|
virtual QgsExpression::Node* clone() const;
|
2016-03-29 16:22:04 +11:00
|
|
|
|
|
|
|
//! Tests whether the provided argument list is valid for the matching function
|
|
|
|
static bool validateParams( int fnIndex, QgsExpression::NodeList* args, QString& error );
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeLiteral : QgsExpression::Node
|
|
|
|
{
|
|
|
|
public:
|
2015-04-23 18:36:41 +02:00
|
|
|
NodeLiteral( const QVariant& value );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** The value of the literal. */
|
2015-04-23 18:36:41 +02:00
|
|
|
const QVariant& value() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2016-02-14 03:50:23 +01:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QString dump() const;
|
2015-12-09 15:44:56 +01:00
|
|
|
virtual QgsExpression::Node* clone() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
virtual bool needsGeometry() const;
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const;
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeColumnRef : QgsExpression::Node
|
|
|
|
{
|
|
|
|
public:
|
2015-04-23 18:36:41 +02:00
|
|
|
NodeColumnRef( const QString& name );
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** The name of the column. */
|
2013-03-13 23:03:10 +01:00
|
|
|
QString name() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2016-02-14 03:50:23 +01:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QString dump() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
virtual bool needsGeometry() const;
|
2014-01-26 18:35:21 +01:00
|
|
|
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const;
|
2015-12-09 15:44:56 +01:00
|
|
|
virtual QgsExpression::Node* clone() const;
|
2012-01-06 19:25:04 +01:00
|
|
|
};
|
|
|
|
|
2012-01-07 01:20:03 +01:00
|
|
|
class WhenThen
|
|
|
|
{
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
2014-01-26 18:35:21 +01:00
|
|
|
WhenThen( QgsExpression::Node* whenExp /Transfer/, QgsExpression::Node* thenExp /Transfer/ );
|
2012-09-24 02:28:15 +02:00
|
|
|
~WhenThen();
|
2012-01-07 01:20:03 +01:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//protected:
|
|
|
|
QgsExpression::Node* mWhenExp;
|
|
|
|
QgsExpression::Node* mThenExp;
|
2016-01-22 18:45:45 +11:00
|
|
|
|
|
|
|
private:
|
|
|
|
WhenThen( const QgsExpression::WhenThen& rh );
|
|
|
|
|
2012-01-07 01:20:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NodeCondition : QgsExpression::Node
|
|
|
|
{
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
2014-01-26 18:35:21 +01:00
|
|
|
NodeCondition( QList<QgsExpression::WhenThen*> *conditions, QgsExpression::Node* elseExp = 0 );
|
2012-09-24 02:28:15 +02:00
|
|
|
~NodeCondition();
|
|
|
|
|
2013-03-15 00:43:07 +01:00
|
|
|
virtual QgsExpression::NodeType nodeType() const;
|
New framework for context based expressions
This commit adds the ability for expressions to be evaluated against
specific contexts. It replaces the previous behaviour where
expressions were evaluated against a specific feature and could
utilise fragile global "special columns".
Now, expressions are instead evaluated using a context designed for
each individual expression. This is done via QgsExpressionContext
and QgsExpressionContextScope objects.
A QgsExpressionContextScope encapsulates the variables and functions
relating to a specific context. For instance, scopes can be created
for "global" variables (such as QGIS version, platform, and user-set
variables specified within the QGIS options dialog. Think things
like user name, work department, etc), or for "project" variables
(eg project path, title, filename, and user-set variables set
through the project properties dialog. Project version, reference
number, that kind of thing). Many more scopes are planned, including
map layer scopes (variables for layer name, id, user-set variables
through the layer properties dialog), composer scopes, etc...
QgsExpressionContextScopes are 'stacked' into a QgsExpressionContext
object. Scopes added later to a QgsExpressionContext will override
any variables or functions provided by earlier scopes, so for
instance a user could override their global 'author' variable set
within QGIS options with a different 'author' set via the project
properties dialog.
The intended use is that a QgsExpressionContext is created before
a batch set of QgsExpression evaluations. Scopes are then added to
the context based on what makes sense for that particular
expression. Eg, almost all contexts will consist of the global
scope and project scope, and then additional scopes as required.
So a composer label would be evaluated against a context
consisting of the global scope, project scope, composition scope
and finally composer item scope. The batch set of expression
evaluations would then be performed using this context, after which
the context is discarded. In other words, a context is designed
for use for one specific set of expression evaluations only.
2015-08-07 15:29:51 +10:00
|
|
|
virtual QVariant eval( QgsExpression* parent, const QgsExpressionContext* context );
|
|
|
|
virtual bool prepare( QgsExpression* parent, const QgsExpressionContext* context );
|
2012-09-24 02:28:15 +02:00
|
|
|
virtual QString dump() const;
|
|
|
|
|
|
|
|
virtual QStringList referencedColumns() const;
|
|
|
|
virtual bool needsGeometry() const;
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void accept( QgsExpression::Visitor& v ) const;
|
2015-12-09 15:44:56 +01:00
|
|
|
virtual QgsExpression::Node* clone() const;
|
2012-01-07 01:20:03 +01:00
|
|
|
};
|
|
|
|
|
2012-01-06 19:25:04 +01:00
|
|
|
//////
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Support for visitor pattern - algorithms dealing with the expressions
|
2012-01-06 19:25:04 +01:00
|
|
|
may be implemented without modifying the Node classes */
|
|
|
|
class Visitor
|
|
|
|
{
|
2012-09-24 02:28:15 +02:00
|
|
|
public:
|
|
|
|
virtual ~Visitor();
|
2013-03-13 23:03:10 +01:00
|
|
|
virtual void visit( const QgsExpression::NodeUnaryOperator& n ) = 0;
|
|
|
|
virtual void visit( const QgsExpression::NodeBinaryOperator& n ) = 0;
|
|
|
|
virtual void visit( const QgsExpression::NodeInOperator& n ) = 0;
|
|
|
|
virtual void visit( const QgsExpression::NodeFunction& n ) = 0;
|
|
|
|
virtual void visit( const QgsExpression::NodeLiteral& n ) = 0;
|
|
|
|
virtual void visit( const QgsExpression::NodeColumnRef& n ) = 0;
|
|
|
|
virtual void visit( const QgsExpression::NodeCondition& n ) = 0;
|
2012-06-30 19:29:07 +10:00
|
|
|
};
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Entry function for the visitor pattern */
|
2013-03-13 23:03:10 +01:00
|
|
|
void acceptVisitor( QgsExpression::Visitor& v ) const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-08-20 13:41:45 +10:00
|
|
|
/** Returns the help text for a specified function.
|
|
|
|
* @param name function name
|
|
|
|
* @see variableHelpText()
|
|
|
|
*/
|
2014-01-26 18:35:21 +01:00
|
|
|
static QString helptext( QString name );
|
2015-08-20 13:41:45 +10:00
|
|
|
|
|
|
|
/** Returns the help text for a specified variable.
|
|
|
|
* @param variableName name of variable
|
2016-02-14 03:50:23 +01:00
|
|
|
* @param showValue set to true to include current value of variable in help text
|
|
|
|
* @param value current value of variable to show in help text
|
2015-08-20 13:41:45 +10:00
|
|
|
* @see helptext()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
2016-02-14 03:50:23 +01:00
|
|
|
static QString variableHelpText( const QString& variableName, bool showValue = true, const QVariant& value = QVariant() );
|
2015-08-20 13:41:45 +10:00
|
|
|
|
|
|
|
/** Returns the translated name for a function group.
|
|
|
|
* @param group untranslated group name
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
static QString group( const QString& group );
|
2014-01-26 18:35:21 +01:00
|
|
|
|
2016-01-27 11:19:58 +11:00
|
|
|
/** Formats an expression result for friendly display to the user. Truncates the result to a sensible
|
|
|
|
* length, and presents text representations of non numeric/text types (eg geometries and features).
|
|
|
|
* @param value expression result to format
|
|
|
|
* @returns formatted string, may contain HTML formatting characters
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
static QString formatPreviewString( const QVariant& value );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
protected:
|
|
|
|
void initGeomCalculator();
|
2011-08-09 20:48:13 +02:00
|
|
|
};
|