73 Commits

Author SHA1 Message Date
Nyall Dawson
ae00eb965c [FEATURE] Allow expression functions to use named parameters
This commit sets the framework for allowing expression functions to
use named parameters. Ie, instead of:

clamp(1,2,3)

you can use:

clamp( min:=1, value:=2, max:=3)

This also allows arguments to be switched, eg:

clamp( value:=2, max:=3, min:=1)

Additionally, it allows for a more structured definition of function
parameters to handle optional arguments and default values for
parameters. These are currently being done using a hacky infinite
argument list.

I've utilised the postgres ':=' syntax for specifying named arguments
to avoid potential collisions which may arise with the equality test
if we re-used just the '=' operator alone.

Sponsored by North Road
2016-04-04 13:59:13 +10:00
Nyall Dawson
59b216be74 Add missing sip bindings 2016-02-15 19:02:34 +11:00
Juergen E. Fischer
a90be95f7b sip sync 2016-02-14 03:50:49 +01:00
Nyall Dawson
9f772bce29 Add API call for setting preferred distance unit for QgsExpression
(refs #13209, #12939, #4857)
2016-02-13 11:36:51 +11:00
Nyall Dawson
229ef29170 If no geomCalculator is set for QgsExpression, perform cartesian
calculations for $length, $area, $perimeter (refs #13209)

ie, the default is now to use planimeteric calculations unless
a geomCalculator has been explicitly set
2016-02-12 20:54:25 +11:00
Nyall Dawson
c3a57434d9 Fix clazy 'pass small and trivially-copyable type by value' warnings 2016-02-02 19:47:21 +11:00
Nyall Dawson
39f0035246 Improve preview of current variable value in expression builder 2016-01-27 11:36:56 +11:00
Nyall Dawson
24d9c65494 Fix more classes which violate the rule-of-three
Also remove some empty destructors
2016-01-26 14:24:45 +11:00
Nyall Dawson
752f6bd150 Fix classes which violate rule of three, by implementing required
copy/= operators or making them private

This revealed (and fixes) some issues, including a potential crash
using server access control (refs #13919), and a potential crash with
diagrams
2016-01-22 18:45:45 +11:00
Nyall Dawson
881074b194 Boost coverage of SIP bindings
Now all classes and members are either exposed to bindings or marked
as "not available in Python bindings" in the docs.

Drop test thresholds to 0. Now it should be much easier to determine
what missing members have been added which are causing test
failures.
2016-01-05 11:16:15 +11:00
Matthias Kuhn
de1c319bf6 Implicit sharing for QgsExpression 2015-12-15 13:39:07 +01:00
Nyall Dawson
9cc9d424ce Add extra check for deprecations to documentation test
This check tests that if a function has been declared deprecated
with either Q_DECL_DEPRECATED or has a @deprecated Doxygen note
then it MUST have both the Q_DECL_DEPRECATD and @deprecated note.

It's important that both are used, as Q_DECL_DEPRECATED allows
throwing a warning if that method is used in code, while the
@deprecated doxygen note gives an indication to devs/PyQGIS users
of why it's deprecated and what should be used instead.

Ideally we'd also test for SIP /Deprecated/ tags, but I can't
find any reliable way to do this.
2015-12-07 21:55:36 +11:00
Nyall Dawson
48e4d1c977 Add a method for getting a quoted string value for use as a literal
in expressions
2015-12-01 19:33:27 +11:00
Matthias Kuhn
56ccb2b858 sipClass_Klass is deprecated for a long time: replace with sipType_Klass 2015-11-11 23:22:51 +01:00
Nyall Dawson
c49b5b777f Change a lot of arguments to const references in core/gui
Rationale:
- there was a lot of large objects passed by value, so potentially
there's a speed bump from this
- even for implicitly shared classes like QString/QList there's still
a (small) cost for copying the objects when there's no reason to
- it's the right thing to do!
2015-10-07 12:02:04 +11:00
Nyall Dawson
97096e2d6b Deprecate QgsExpression special column methods 2015-09-07 20:24:57 +10:00
Nyall Dawson
1c079ead02 Expression context fixes:
- Fix python API break in QgsExpression::Function
- Add convenience methods for retrieving feature/fields from a
context
2015-09-05 22:03:16 +10:00
Nyall Dawson
24b8405d58 Ensure standard expressions functions are deleted on exit
(Avoids a lot of LeakSanitiser noise)
2015-08-25 21:40:32 +10:00
Nyall Dawson
f74db81b9a Hide contextual functions from builder unless provided by context 2015-08-22 19:01:42 +10:00
Nyall Dawson
6487f1716c Add help text for variables 2015-08-22 19:01:42 +10:00
Nyall Dawson
c1adf623af Port field calculator to contexts 2015-08-22 19:01:39 +10:00
Nyall Dawson
f6e0ce788e 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-22 19:01:39 +10:00
Juergen E. Fischer
9752c468c1 indentation update 2015-07-29 11:52:14 +02:00
Jürgen Fischer
6e3a1fa057 Merge pull request #2118 from jef-n/postgres-like-concat
expressions: let concat handle NULL like empty string (like in postgres; fixes #1927)
2015-06-26 01:14:20 +02:00
Matthias Kuhn
8342739b37 Expressions: preserve brackets for right-associative operators
Fixes #11475
2015-06-16 19:46:26 +02:00
Denis Rouzaud
a518e9f639 [fix #11475] expressions: add left and right associavity for dump of binary operators
complete test for left associativity
2015-06-16 19:07:45 +02:00
Juergen E. Fischer
3387d6f632 expression: let concat handle NULL like empty string (like in postgres) 2015-06-06 11:29:44 +02:00
Juergen E. Fischer
dd53fda846 indentation update 2015-05-29 08:57:54 +02:00
Nyall Dawson
ec01d7698e More Coverity memory leak fixes 2015-05-27 23:03:00 +10:00
Matthias Kuhn
a2ae8b4e38 Add unit tests for postgres provider
basically to get a framework to test the expression compiler
2015-05-22 11:57:16 +02:00
Matthias Kuhn
9b6e23d3af Add convenience method QgsVectorLayer::getFeatures( expression ) 2015-05-22 11:57:16 +02:00
Martin Dobias
56ada166c4 PyQGIS: add conversion from QgsExpression::Node to subclasses
This makes it possible to investigate expression node tree within Python
2015-05-12 17:24:57 +01:00
Juergen E. Fischer
edeafa95ac indentation and minor sip updates 2015-05-03 17:10:32 +02:00
Nyall Dawson
bd9e02be95 Add alias support for expression functions
Standardise naming of all internal functions to lowercase with
underscore convention. Add aliases for old names to avoid
breakage.
2015-05-03 20:57:36 +10:00
vmora
d4319621a5 Add an isField test for QgsExpression
Checks whether expression consists of solely a field reference
2015-04-27 18:22:18 +10:00
Juergen E. Fischer
abd4a04399 sip update 2015-02-03 02:21:52 +01:00
Nyall Dawson
232aaaca66 [expressions] Make int/int return double results.
Also add a new "//" operator to perform integer division.
(fix #5153)
2014-12-06 16:36:42 +11:00
Nyall Dawson
7400106e41 [FEATURE] Evaluate expressions entered in QgsDoubleSpinBox
Allows entry of QGIS expressions into the spin box. The expression
is evaluated on enter or loss of focus and then discarded.

(refs #10544)
2014-12-05 20:39:09 +11:00
Matthias Kuhn
a92d1a6e31 QgsExpression: some const fixes 2014-11-30 10:34:19 +01:00
Juergen E. Fischer
d4f64d9bde indentation update and typo fixes 2014-11-13 23:13:13 +01:00
Martin Dobias
37ba8e4187 Fix #9319 (copy of QgsExpression crashes)
Disabled the copy constructor for now (later we may introduce implicit sharing)
2014-10-22 23:03:53 +07:00
Nyall Dawson
0cb985465b [composer] Fix area calculation in expressions with OTF (fix #9791)
Adds an argument to QgsExpression::replaceExpressionText to allow
passing an optional QgsDistanceArea to use during calculations.
Ensure that html and label composer items correctly specify this
argument.
2014-10-19 11:04:57 +11:00
Nyall Dawson
1e39db6a0f [FEATURE] New expression functions for $currentfeature (returns current feature) and 'attribute' (returns value stored in specified field within a feature) 2014-07-10 14:10:44 +10:00
Juergen E. Fischer
03475be523 fix build error and update sips 2014-06-14 11:47:05 +02:00
Juergen E. Fischer
c1f50db1ac fix warnings 2014-05-29 01:43:04 +02:00
Juergen E. Fischer
c4c131ef75 sip sync 2014-05-27 23:32:42 +02:00
Martin Dobias
684dd890a3 Fix #9459 (layer fails to render when rule-based symbology make use of $atlasfeatureid) 2014-02-11 23:57:02 +07:00
Juergen E. Fischer
d647354a52 sip fixes 2014-01-28 00:26:13 +01:00
Juergen E. Fischer
74e7314c36 update sip bindings II 2014-01-27 09:22:53 +01:00
Juergen E. Fischer
d4e369414b update sip bindings 2014-01-26 18:36:29 +01:00