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
|
|
|
/** \ingroup core
|
|
|
|
* \class QgsScopedExpressionFunction
|
|
|
|
* \brief Expression function for use within a QgsExpressionContextScope. This differs from a
|
|
|
|
* standard QgsExpression::Function in that it requires an implemented
|
|
|
|
* clone() method.
|
|
|
|
* \note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
|
|
|
|
class QgsScopedExpressionFunction : QgsExpression::Function
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsexpressioncontext.h>
|
|
|
|
%End
|
|
|
|
public:
|
2015-10-07 11:55:34 +11:00
|
|
|
QgsScopedExpressionFunction( const QString& fnname,
|
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
|
|
|
int params,
|
2015-10-07 11:55:34 +11:00
|
|
|
const QString& group,
|
|
|
|
const QString& helpText = QString(),
|
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 usesGeometry = false,
|
2015-10-07 11:55:34 +11:00
|
|
|
const QStringList& referencedColumns = QStringList(),
|
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 lazyEval = false,
|
2015-08-20 15:06:09 +10:00
|
|
|
bool handlesNull = false,
|
|
|
|
bool isContextual = true );
|
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 ~QgsScopedExpressionFunction();
|
|
|
|
|
|
|
|
virtual QVariant func( const QVariantList& values, const QgsExpressionContext* context, QgsExpression* parent ) = 0;
|
|
|
|
|
|
|
|
/** Returns a clone of the function.
|
|
|
|
*/
|
|
|
|
virtual QgsScopedExpressionFunction* clone() const = 0 /Factory/;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
|
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
|
|
|
/** \ingroup core
|
|
|
|
* \class QgsExpressionContextScope
|
|
|
|
* \brief Single scope for storing variables and functions for use within a QgsExpressionContext.
|
|
|
|
* Examples include a project's scope, which could contain information about the current project such as
|
|
|
|
* the project file's location. QgsExpressionContextScope can encapsulate both variables (static values)
|
|
|
|
* and functions(which are calculated only when an expression is evaluated).
|
|
|
|
* \note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
|
|
|
|
class QgsExpressionContextScope
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsexpressioncontext.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Single variable definition for use within a QgsExpressionContextScope.
|
|
|
|
*/
|
|
|
|
struct StaticVariable
|
|
|
|
{
|
|
|
|
/** Constructor for StaticVariable.
|
|
|
|
* @param name variable name (should be unique within the QgsExpressionContextScope)
|
|
|
|
* @param value intial variable value
|
|
|
|
* @param readOnly true if variable should not be editable by users
|
|
|
|
*/
|
|
|
|
StaticVariable( const QString& name = QString(), const QVariant& value = QVariant(), bool readOnly = false );
|
|
|
|
|
|
|
|
/** Variable name */
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
/** Variable value */
|
|
|
|
QVariant value;
|
|
|
|
|
|
|
|
/** True if variable should not be editable by users */
|
|
|
|
bool readOnly;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Constructor for QgsExpressionContextScope
|
|
|
|
* @param name friendly display name for the context scope
|
|
|
|
*/
|
|
|
|
QgsExpressionContextScope( const QString& name = QString() );
|
|
|
|
|
2015-08-21 06:59:57 +10:00
|
|
|
/** Copy constructor
|
|
|
|
*/
|
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
|
|
|
QgsExpressionContextScope( const QgsExpressionContextScope& other );
|
|
|
|
|
|
|
|
~QgsExpressionContextScope();
|
|
|
|
|
|
|
|
/** Returns the friendly display name of the context scope.
|
|
|
|
*/
|
|
|
|
QString name() const;
|
|
|
|
|
|
|
|
/** Convenience method for setting a variable in the context scope by name and value. If a variable
|
|
|
|
* with the same name is already set then its value is overwritten, otherwise a new variable is added to the scope.
|
|
|
|
* @param name variable name
|
|
|
|
* @param value variable value
|
|
|
|
* @see addVariable()
|
|
|
|
*/
|
|
|
|
void setVariable( const QString& name, const QVariant& value );
|
|
|
|
|
|
|
|
/** Adds a variable into the context scope. If a variable with the same name is already set then its
|
|
|
|
* value is overwritten, otherwise a new variable is added to the scope.
|
|
|
|
* @param variable definition of variable to insert
|
|
|
|
* @see setVariable()
|
|
|
|
* @see addFunction()
|
|
|
|
*/
|
|
|
|
void addVariable( const QgsExpressionContextScope::StaticVariable& variable );
|
|
|
|
|
|
|
|
/** Removes a variable from the context scope, if found.
|
|
|
|
* @param name name of variable to remove
|
|
|
|
* @returns true if variable was removed from the scope, false if matching variable was not
|
|
|
|
* found within the scope
|
|
|
|
*/
|
|
|
|
bool removeVariable( const QString& name );
|
|
|
|
|
|
|
|
/** Tests whether a variable with the specified name exists in the scope.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns true if matching variable was found in the scope
|
|
|
|
* @see variable()
|
|
|
|
* @see hasFunction()
|
|
|
|
*/
|
|
|
|
bool hasVariable( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Retrieves a variable's value from the scope.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns variable value, or invalid QVariant if matching variable could not be found
|
|
|
|
* @see hasVariable()
|
|
|
|
* @see function()
|
|
|
|
*/
|
|
|
|
QVariant variable( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Returns a list of variable names contained within the scope.
|
2015-08-19 16:14:32 +10:00
|
|
|
* @see functionNames()
|
2015-09-11 17:11:48 +10:00
|
|
|
* @see filteredVariableNames()
|
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
|
|
|
*/
|
|
|
|
QStringList variableNames() const;
|
|
|
|
|
2015-09-11 17:11:48 +10:00
|
|
|
/** Returns a fitlered and sorted list of variable names contained within the scope.
|
|
|
|
* Hidden variable names will be excluded, and the list will be sorted so that
|
|
|
|
* read only variables are listed first.
|
|
|
|
* @see variableNames()
|
|
|
|
*/
|
|
|
|
QStringList filteredVariableNames() 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
|
|
|
/** Tests whether the specified variable is read only and should not be editable
|
|
|
|
* by users.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns true if variable is read only
|
|
|
|
*/
|
|
|
|
bool isReadOnly( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Returns the count of variables contained within the scope.
|
|
|
|
*/
|
|
|
|
int variableCount() const;
|
|
|
|
|
|
|
|
/** Tests whether a function with the specified name exists in the scope.
|
|
|
|
* @param name function name
|
|
|
|
* @returns true if matching function was found in the scope
|
|
|
|
* @see function()
|
|
|
|
* @see hasFunction()
|
|
|
|
*/
|
|
|
|
bool hasFunction( const QString &name ) const;
|
|
|
|
|
|
|
|
/** Retrieves a function from the scope.
|
|
|
|
* @param name function name
|
|
|
|
* @returns function, or null if matching function could not be found
|
|
|
|
* @see hasFunction()
|
2015-08-19 16:14:32 +10:00
|
|
|
* @see functionNames()
|
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
|
|
|
* @see variable()
|
|
|
|
*/
|
|
|
|
QgsExpression::Function* function( const QString &name ) const;
|
|
|
|
|
2015-08-19 16:14:32 +10:00
|
|
|
/** Retrieves a list of names of functions contained in the scope.
|
|
|
|
* @see function()
|
|
|
|
* @see variableNames()
|
|
|
|
*/
|
|
|
|
QStringList functionNames() 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
|
|
|
/** Adds a function to the scope.
|
|
|
|
* @param name function name
|
|
|
|
* @param function function to insert. Ownership is transferred to the scope.
|
|
|
|
* @see addVariable()
|
|
|
|
*/
|
|
|
|
void addFunction( const QString& name, QgsScopedExpressionFunction* function /Transfer/ );
|
|
|
|
|
|
|
|
/** Convenience function for setting a feature for the scope. Any existing
|
|
|
|
* feature set by the scope will be overwritten.
|
|
|
|
* @param feature feature for scope
|
|
|
|
*/
|
|
|
|
void setFeature( const QgsFeature& feature );
|
2015-08-19 16:14:32 +10:00
|
|
|
|
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
|
|
|
/** Convenience function for setting a fields for the scope. Any existing
|
|
|
|
* fields set by the scope will be overwritten.
|
|
|
|
* @param fields fields for scope
|
|
|
|
*/
|
|
|
|
void setFields( const QgsFields& fields );
|
|
|
|
};
|
|
|
|
|
|
|
|
/** \ingroup core
|
|
|
|
* \class QgsExpressionContext
|
|
|
|
* \brief Expression contexts are used to encapsulate the parameters around which a QgsExpression should
|
|
|
|
* be evaluated. QgsExpressions can then utilise the information stored within a context to contextualise
|
|
|
|
* their evaluated result. A QgsExpressionContext consists of a stack of QgsExpressionContextScope objects,
|
|
|
|
* where scopes added later to the stack will override conflicting variables and functions from scopes
|
|
|
|
* lower in the stack.
|
|
|
|
* \note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
|
|
|
|
class QgsExpressionContext
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsexpressioncontext.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
QgsExpressionContext();
|
2015-08-21 06:59:57 +10:00
|
|
|
|
|
|
|
/** Copy constructor
|
|
|
|
*/
|
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
|
|
|
QgsExpressionContext( const QgsExpressionContext& other );
|
|
|
|
|
|
|
|
~QgsExpressionContext();
|
|
|
|
|
|
|
|
/** Check whether a variable is specified by any scope within the context.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns true if variable is set
|
|
|
|
* @see variable()
|
|
|
|
* @see variableNames()
|
|
|
|
*/
|
|
|
|
bool hasVariable( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Fetches a matching variable from the context. The variable will be fetched
|
|
|
|
* from the last scope contained within the context which has a matching
|
|
|
|
* variable set.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns variable value if matching variable exists in the context, otherwise an invalid QVariant
|
|
|
|
* @see hasVariable()
|
|
|
|
* @see variableNames()
|
|
|
|
*/
|
|
|
|
QVariant variable( const QString& name ) const;
|
|
|
|
|
2015-08-20 16:06:34 +10:00
|
|
|
/** Returns true if the specified variable name is intended to be highlighted to the
|
|
|
|
* user. This is used by the expression builder to more prominently display the
|
|
|
|
* variable.
|
|
|
|
* @param name variable name
|
|
|
|
* @see setHighlightedVariables()
|
|
|
|
*/
|
|
|
|
bool isHighlightedVariable( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Sets the list of variable names within the context intended to be highlighted to the user. This
|
|
|
|
* is used by the expression builder to more prominently display these variables.
|
|
|
|
* @param variableNames variable names to highlight
|
|
|
|
* @see isHighlightedVariable()
|
|
|
|
*/
|
|
|
|
void setHighlightedVariables( const QStringList& variableNames );
|
|
|
|
|
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
|
|
|
/** Returns the currently active scope from the context for a specified variable name.
|
|
|
|
* As scopes later in the stack override earlier contexts, this will be the last matching
|
|
|
|
* scope which contains a matching variable.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns matching scope containing variable, or null if none found
|
|
|
|
*/
|
|
|
|
QgsExpressionContextScope* activeScopeForVariable( const QString& name );
|
|
|
|
|
|
|
|
/** Returns the currently active scope from the context for a specified variable name.
|
|
|
|
* As scopes later in the stack override earlier contexts, this will be the last matching
|
|
|
|
* scope which contains a matching variable.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns matching scope containing variable, or null if none found
|
2016-02-14 03:50:23 +01:00
|
|
|
* @note not available in python bindings
|
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
|
|
|
*/
|
|
|
|
//const QgsExpressionContextScope* activeScopeForVariable( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Returns the scope at the specified index within the context.
|
|
|
|
* @param index index of scope
|
|
|
|
* @returns matching scope, or null if none found
|
|
|
|
* @see lastScope()
|
|
|
|
*/
|
|
|
|
QgsExpressionContextScope* scope( int index );
|
|
|
|
|
|
|
|
/** Returns the last scope added to the context.
|
|
|
|
* @see scope()
|
|
|
|
*/
|
|
|
|
QgsExpressionContextScope* lastScope();
|
|
|
|
|
|
|
|
/** Returns a list of scopes contained within the stack.
|
|
|
|
* @returns list of pointers to scopes
|
|
|
|
*/
|
|
|
|
QList< QgsExpressionContextScope* > scopes();
|
|
|
|
|
|
|
|
/** Returns the index of the specified scope if it exists within the context.
|
|
|
|
* @param scope scope to find
|
|
|
|
* @returns index of scope, or -1 if scope was not found within the context.
|
|
|
|
*/
|
|
|
|
int indexOfScope( QgsExpressionContextScope* scope ) const;
|
|
|
|
|
|
|
|
/** Returns a list of variables names set by all scopes in the context.
|
|
|
|
* @returns list of unique variable names
|
2015-08-19 16:14:32 +10:00
|
|
|
* @see filteredVariableNames
|
|
|
|
* @see functionNames
|
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
|
|
|
* @see hasVariable
|
|
|
|
* @see variable
|
|
|
|
*/
|
|
|
|
QStringList variableNames() const;
|
|
|
|
|
2015-08-19 16:14:32 +10:00
|
|
|
/** Returns a filtered list of variables names set by all scopes in the context. The included
|
|
|
|
* variables are those which should be seen by users.
|
|
|
|
* @returns filtered list of unique variable names
|
|
|
|
* @see variableNames
|
|
|
|
*/
|
|
|
|
QStringList filteredVariableNames() 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
|
|
|
/** Returns whether a variable is read only, and should not be modifiable by users.
|
|
|
|
* @param name variable name
|
|
|
|
* @returns true if variable is read only. Read only status will be taken from last
|
|
|
|
* matching scope which contains a matching variable.
|
|
|
|
*/
|
|
|
|
bool isReadOnly( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Checks whether a specified function is contained in the context.
|
|
|
|
* @param name function name
|
|
|
|
* @returns true if context provides a matching function
|
|
|
|
* @see function
|
|
|
|
*/
|
|
|
|
bool hasFunction( const QString& name ) const;
|
|
|
|
|
2015-08-19 16:14:32 +10:00
|
|
|
/** Retrieves a list of function names contained in the context.
|
|
|
|
* @see function()
|
|
|
|
* @see variableNames()
|
|
|
|
*/
|
|
|
|
QStringList functionNames() 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
|
|
|
/** Fetches a matching function from the context. The function will be fetched
|
|
|
|
* from the last scope contained within the context which has a matching
|
|
|
|
* function set.
|
|
|
|
* @param name function name
|
|
|
|
* @returns function if contained by the context, otherwise null.
|
|
|
|
* @see hasFunction
|
|
|
|
*/
|
|
|
|
QgsExpression::Function* function( const QString& name ) const;
|
|
|
|
|
|
|
|
/** Returns the number of scopes contained in the context.
|
|
|
|
*/
|
|
|
|
int scopeCount() const;
|
|
|
|
|
|
|
|
/** Appends a scope to the end of the context. This scope will override
|
|
|
|
* any matching variables or functions provided by existing scopes within the
|
|
|
|
* context. Ownership of the scope is transferred to the stack.
|
|
|
|
* @param scope expression context to append to context
|
|
|
|
*/
|
|
|
|
void appendScope( QgsExpressionContextScope* scope /Transfer/ );
|
|
|
|
|
2016-01-08 13:42:53 +01:00
|
|
|
/**
|
2016-01-24 15:15:29 +11:00
|
|
|
* Removes the last scope from the expression context and return it.
|
2016-01-08 13:42:53 +01:00
|
|
|
*/
|
2016-01-24 15:15:29 +11:00
|
|
|
QgsExpressionContextScope* popScope();
|
2016-01-08 13:42:53 +01:00
|
|
|
|
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
|
|
|
/** Appends a scope to the end of the context. This scope will override
|
|
|
|
* any matching variables or functions provided by existing scopes within the
|
|
|
|
* context. Ownership of the scope is transferred to the stack.
|
|
|
|
*/
|
|
|
|
QgsExpressionContext& operator<< ( QgsExpressionContextScope* scope /Transfer/ );
|
2015-08-19 16:14:32 +10:00
|
|
|
|
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
|
|
|
/** Convenience function for setting a feature for the context. The feature
|
|
|
|
* will be set within the last scope of the context, so will override any
|
|
|
|
* existing features within the context.
|
|
|
|
* @param feature feature for context
|
2015-09-05 22:03:16 +10:00
|
|
|
* @see feature()
|
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
|
|
|
*/
|
2015-08-19 16:14:32 +10:00
|
|
|
void setFeature( const QgsFeature& feature );
|
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
|
|
|
|
2015-09-05 22:03:16 +10:00
|
|
|
/** Convenience function for retrieving the feature for the context, if set.
|
|
|
|
* @see setFeature
|
|
|
|
*/
|
|
|
|
QgsFeature feature() 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
|
|
|
/** Convenience function for setting a fields for the context. The fields
|
|
|
|
* will be set within the last scope of the context, so will override any
|
|
|
|
* existing fields within the context.
|
|
|
|
* @param fields fields for context
|
2015-09-05 22:03:16 +10:00
|
|
|
* @see 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
|
|
|
*/
|
|
|
|
void setFields( const QgsFields& fields );
|
2015-08-19 16:14:32 +10:00
|
|
|
|
2015-09-05 22:03:16 +10:00
|
|
|
/** Convenience function for retrieving the fields for the context, if set.
|
|
|
|
* @see setFields
|
|
|
|
*/
|
|
|
|
QgsFields fields() const;
|
|
|
|
|
2015-10-01 15:41:19 +10:00
|
|
|
/** Sets the original value variable value for the context.
|
|
|
|
* @param value value for original value variable. This usually represents the an original widget
|
|
|
|
* value before any data defined overrides have been applied.
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void setOriginalValueVariable( const QVariant& value );
|
|
|
|
|
2016-01-27 13:58:32 +11:00
|
|
|
//! Inbuilt variable name for fields storage
|
2016-01-04 22:51:18 +11:00
|
|
|
static const QString EXPR_FIELDS;
|
2016-01-27 13:58:32 +11:00
|
|
|
//! Inbuilt variable name for feature storage
|
2016-01-04 22:51:18 +11:00
|
|
|
static const QString EXPR_FEATURE;
|
2016-01-27 14:40:51 +11:00
|
|
|
//! Inbuilt variable name for value original value variable
|
2016-01-04 22:51:18 +11:00
|
|
|
static const QString EXPR_ORIGINAL_VALUE;
|
2016-01-27 13:58:32 +11:00
|
|
|
//! Inbuilt variable name for symbol color variable
|
2016-01-20 08:21:32 +01:00
|
|
|
static const QString EXPR_SYMBOL_COLOR;
|
2016-01-27 13:58:32 +11:00
|
|
|
//! Inbuilt variable name for symbol angle variable
|
2016-01-20 08:21:32 +01:00
|
|
|
static const QString EXPR_SYMBOL_ANGLE;
|
2016-01-27 13:58:32 +11:00
|
|
|
//! Inbuilt variable name for geometry part count variable
|
|
|
|
static const QString EXPR_GEOMETRY_PART_COUNT;
|
|
|
|
//! Inbuilt variable name for geometry part number variable
|
|
|
|
static const QString EXPR_GEOMETRY_PART_NUM;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/** \ingroup core
|
|
|
|
* \class QgsExpressionContextUtils
|
|
|
|
* \brief Contains utilities for working with QgsExpressionContext objects, including methods
|
|
|
|
* for creating scopes for specific uses (eg project scopes, layer scopes).
|
|
|
|
* \note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
|
|
|
|
class QgsExpressionContextUtils
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsexpressioncontext.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Creates a new scope which contains variables and functions relating to the global QGIS context.
|
|
|
|
* For instance, QGIS version numbers and variables specified through QGIS options.
|
|
|
|
* @see setGlobalVariable()
|
|
|
|
*/
|
|
|
|
static QgsExpressionContextScope* globalScope() /Factory/;
|
|
|
|
|
|
|
|
/** Sets a global context variable. This variable will be contained within scopes retrieved via
|
|
|
|
* globalScope().
|
|
|
|
* @param name variable name
|
|
|
|
* @param value variable value
|
|
|
|
* @see setGlobalVariable()
|
|
|
|
* @see globalScope()
|
|
|
|
*/
|
|
|
|
static void setGlobalVariable( const QString& name, const QVariant& value );
|
|
|
|
|
|
|
|
/** Sets all global context variables. Existing global variables will be removed and replaced
|
|
|
|
* with the variables specified.
|
|
|
|
* @param variables new set of global variables
|
|
|
|
* @see setGlobalVariable()
|
|
|
|
* @see globalScope()
|
|
|
|
*/
|
|
|
|
static void setGlobalVariables( const QgsStringMap& variables );
|
|
|
|
|
|
|
|
/** Creates a new scope which contains variables and functions relating to the current QGIS project.
|
|
|
|
* For instance, project path and title, and variables specified through the project properties.
|
|
|
|
* @see setProjectVariable()
|
|
|
|
*/
|
|
|
|
static QgsExpressionContextScope* projectScope() /Factory/;
|
|
|
|
|
|
|
|
/** Sets a project context variable. This variable will be contained within scopes retrieved via
|
|
|
|
* projectScope().
|
|
|
|
* @param name variable name
|
|
|
|
* @param value variable value
|
|
|
|
* @see setProjectVariables()
|
|
|
|
* @see projectScope()
|
|
|
|
*/
|
|
|
|
static void setProjectVariable( const QString& name, const QVariant& value );
|
|
|
|
|
|
|
|
/** Sets all project context variables. Existing project variables will be removed and replaced
|
|
|
|
* with the variables specified.
|
|
|
|
* @param variables new set of project variables
|
|
|
|
* @see setProjectVariable()
|
|
|
|
* @see projectScope()
|
|
|
|
*/
|
|
|
|
static void setProjectVariables( const QgsStringMap& variables );
|
|
|
|
|
|
|
|
/** Creates a new scope which contains variables and functions relating to a QgsMapLayer.
|
|
|
|
* For instance, layer name, id and fields.
|
|
|
|
*/
|
2016-02-14 03:50:23 +01:00
|
|
|
static QgsExpressionContextScope* layerScope( const QgsMapLayer *layer ) /Factory/;
|
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
|
|
|
|
2015-08-10 07:42:34 +10:00
|
|
|
/** Sets a layer context variable. This variable will be contained within scopes retrieved via
|
|
|
|
* layerScope().
|
|
|
|
* @param layer map layer
|
|
|
|
* @param name variable name
|
|
|
|
* @param value variable value
|
|
|
|
* @see setLayerVariables()
|
|
|
|
* @see layerScope()
|
|
|
|
*/
|
|
|
|
static void setLayerVariable( QgsMapLayer* layer, const QString& name, const QVariant& value );
|
|
|
|
|
|
|
|
/** Sets all layer context variables. Existing layer variables will be removed and replaced
|
|
|
|
* with the variables specified.
|
|
|
|
* @param layer map layer
|
|
|
|
* @param variables new set of layer variables
|
|
|
|
* @see setLayerVariable()
|
|
|
|
* @see layerScope()
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
static void setLayerVariables( QgsMapLayer* layer, const QgsStringMap& variables );
|
2015-08-10 07:42:34 +10:00
|
|
|
|
2015-09-07 19:18:44 +10:00
|
|
|
/** Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
|
|
|
|
* For instance, map scale and rotation.
|
|
|
|
*/
|
|
|
|
static QgsExpressionContextScope* mapSettingsScope( const QgsMapSettings &mapSettings ) /Factory/;
|
|
|
|
|
2016-01-20 08:21:32 +01:00
|
|
|
/**
|
2016-01-24 15:15:29 +11:00
|
|
|
* Updates a symbol scope related to a QgsSymbolV2 to an expression context.
|
2016-01-20 08:21:32 +01:00
|
|
|
* @param symbol symbol to extract properties from
|
2016-01-24 15:15:29 +11:00
|
|
|
* @param symbolScope pointer to an existing scope to update
|
2016-01-20 08:21:32 +01:00
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
2016-01-24 15:15:29 +11:00
|
|
|
static QgsExpressionContextScope* updateSymbolScope( const QgsSymbolV2* symbol, QgsExpressionContextScope* symbolScope = nullptr );
|
2016-01-20 08:21:32 +01:00
|
|
|
|
2015-08-13 09:42:51 +10:00
|
|
|
/** Creates a new scope which contains variables and functions relating to a QgsComposition.
|
|
|
|
* For instance, number of pages and page sizes.
|
|
|
|
* @param composition source composition
|
|
|
|
*/
|
|
|
|
static QgsExpressionContextScope* compositionScope( const QgsComposition *composition ) /Factory/;
|
|
|
|
|
|
|
|
/** Sets a composition context variable. This variable will be contained within scopes retrieved via
|
|
|
|
* compositionScope().
|
|
|
|
* @param composition target composition
|
|
|
|
* @param name variable name
|
|
|
|
* @param value variable value
|
|
|
|
* @see setCompositionVariables()
|
|
|
|
* @see compositionScope()
|
|
|
|
*/
|
|
|
|
static void setCompositionVariable( QgsComposition* composition, const QString& name, const QVariant& value );
|
|
|
|
|
|
|
|
/** Sets all composition context variables. Existing composition variables will be removed and replaced
|
|
|
|
* with the variables specified.
|
|
|
|
* @param composition target composition
|
|
|
|
* @param variables new set of layer variables
|
|
|
|
* @see setCompositionVariable()
|
|
|
|
* @see compositionScope()
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
static void setCompositionVariables( QgsComposition* composition, const QgsStringMap& variables );
|
2015-08-13 09:42:51 +10:00
|
|
|
|
2015-09-08 17:31:52 +10:00
|
|
|
/** Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
|
|
|
|
* For instance, current page name and number.
|
|
|
|
* @param atlas source atlas. If null, a set of default atlas variables will be added to the scope.
|
|
|
|
*/
|
|
|
|
static QgsExpressionContextScope* atlasScope( const QgsAtlasComposition* atlas ) /Factory/;
|
|
|
|
|
2015-08-13 09:42:51 +10:00
|
|
|
/** Creates a new scope which contains variables and functions relating to a QgsComposerItem.
|
|
|
|
* For instance, item size and position.
|
|
|
|
* @param composerItem source composer item
|
|
|
|
*/
|
|
|
|
static QgsExpressionContextScope* composerItemScope( const QgsComposerItem *composerItem ) /Factory/;
|
|
|
|
|
|
|
|
/** Sets a composer item context variable. This variable will be contained within scopes retrieved via
|
|
|
|
* composerItemScope().
|
|
|
|
* @param composerItem target composer item
|
|
|
|
* @param name variable name
|
|
|
|
* @param value variable value
|
|
|
|
* @see setComposerItemVariables()
|
|
|
|
* @see composerItemScope()
|
|
|
|
*/
|
|
|
|
static void setComposerItemVariable( QgsComposerItem* composerItem, const QString& name, const QVariant& value );
|
|
|
|
|
|
|
|
/** Sets all composition context variables. Existing compositoin variables will be removed and replaced
|
|
|
|
* with the variables specified.
|
|
|
|
* @param composerItem target composer item
|
|
|
|
* @param variables new set of layer variables
|
|
|
|
* @see setComposerItemVariable()
|
|
|
|
* @see composerItemScope()
|
|
|
|
*/
|
2015-10-07 11:55:34 +11:00
|
|
|
static void setComposerItemVariables( QgsComposerItem* composerItem, const QgsStringMap& variables );
|
2015-08-13 09:42:51 +10:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
/** Helper function for creating an expression context which contains just a feature and fields
|
|
|
|
* collection. Generally this method should not be used as the created context does not include
|
|
|
|
* standard scopes such as the global and project scopes.
|
|
|
|
*/
|
|
|
|
static QgsExpressionContext createFeatureBasedContext( const QgsFeature& feature, const QgsFields& 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
|
|
|
/** Registers all known core functions provided by QgsExpressionContextScope objects.
|
|
|
|
*/
|
|
|
|
static void registerContextFunctions();
|
2016-02-14 03:50:23 +01:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|