Please sign in to comment.
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.
- Loading branch information
Showing with 2,525 additions and 252 deletions.
- +1 −0 python/core/core.sip
- +89 −25 python/core/qgsexpression.sip
- +392 −0 python/core/qgsexpressioncontext.sip
- +5 −0 python/core/qgsproject.sip
- +2 −0 src/core/CMakeLists.txt
- +340 −190 src/core/qgsexpression.cpp
- +139 −34 src/core/qgsexpression.h
- +523 −0 src/core/qgsexpressioncontext.cpp
- +426 −0 src/core/qgsexpressioncontext.h
- +3 −0 src/core/qgsexpressionlexer.ll
- +12 −1 src/core/qgsexpressionparser.yy
- +7 −2 src/core/qgsproject.cpp
- +6 −0 src/core/qgsproject.h
- +1 −0 tests/src/core/CMakeLists.txt
- +579 −0 tests/src/core/testqgsexpressioncontext.cpp
Oops, something went wrong.