53 Commits

Author SHA1 Message Date
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
Nathan Woodrow
2cd89388b6 Use const pointer for QgsExpression:replaceExpressionText() 2013-10-10 13:37:53 +10:00
Matthias Kuhn
75896d922d QgsExpression takes const QgsFeature as pointer and by reference 2013-05-22 17:01:55 +02:00
Martin Dobias
b513674fa8 Moved expression to OGC filter code to QgsOgcUtils 2013-03-15 00:44:32 +01:00
Martin Dobias
16ec226d97 Moved visitor-based expression -> OGC filter code to QgsOgcUtils 2013-03-15 00:44:31 +01:00
Martin Dobias
837ac4de5c Moved creation of expression from OGC filter to QgsOgcUtils 2013-03-15 00:44:31 +01:00
Martin Dobias
9317ffd89a Merge remote-tracking branch 'origin/master' into new_vector_api
Also disabled mapserver until compilation is fixed.
Fixed tests.

Conflicts:
	src/app/legend/qgslegendlayer.cpp
	src/app/qgsattributedialog.cpp
	src/app/qgsattributedialog.h
	src/app/qgslabelpropertydialog.cpp
	src/app/qgsmaptoollabel.cpp
	src/app/qgsvectorlayerproperties.cpp
	src/core/CMakeLists.txt
	src/core/composer/qgsatlascomposition.cpp
	src/core/qgsexpression.cpp
	src/core/qgspallabeling.cpp
	src/core/qgsvectorlayer.cpp
	src/core/qgsvectorlayer.h
	src/core/qgsvectorlayerimport.cpp
	src/mapserver/qgsprojectparser.cpp
	src/mapserver/qgswfsserver.cpp
	src/mapserver/qgswfsserver.h
	src/mapserver/qgswmsserver.cpp
	src/providers/postgres/qgspostgresprovider.cpp
	src/providers/spatialite/qgsspatialiteprovider.h
	tests/src/core/testqgsexpression.cpp
	tests/src/python/test_qgsmemoryprovider.py
2012-12-18 01:35:06 +01:00
Magnus Homann
e063c237d0 Update from master 2012-11-23 21:01:04 +01:00
Nathan Woodrow
a7699e2696 [FEATURE] Add ability to create user defined Python (and C++) expression functions 2012-11-10 11:20:26 +10:00
Martin Dobias
51122d263a Store attributes and fields in vectors instead of maps 2012-10-20 22:19:55 +02:00
Hugo Mercier
45593bf4b5 Revert "Revert "Merge pull request #245 from Oslandia/atlas_integration""
This reverts commit 8a1953b9e710ea25dac502b32eab9e0e8d652b10.
2012-10-04 11:18:17 +02:00
Tim Sutton
8a1953b9e7 Revert "Merge pull request #245 from Oslandia/atlas_integration"
This reverts commit fe8385e7f5735507adf1acfcce81a399fa6bc6f5, reversing
changes made to 23352ce0d66855a4a9c403a81feaa1884415e45c.
2012-10-01 11:04:04 +02:00
Hugo Mercier
ff6b04b672 Fix QgsExpression SIP 2012-09-27 11:06:03 +02:00
Hugo Mercier
ff41bec29b Merge branch 'master' of https://github.com/qgis/Quantum-GIS into atlas
Conflicts:
	python/core/qgsexpression.sip

Add a missing function to QgsExpression
2012-09-26 17:51:44 +02:00
Hugo Mercier
e70b1524f9 Update QgsExpression's SIP 2012-09-26 16:40:22 +02:00
Hugo Mercier
9a671f98a0 Add support for user-defined special columns in expressions 2012-09-26 16:39:18 +02:00
Juergen E. Fischer
f3cb57b1eb SIP bindings update:
- update methods of existing classes
- add comment to methods missing in the sip bindings
- split up collective sip files into single files and use
  same directory structure in python/ as in src/
- add a lot of missing classes (some might not make sense because of
  missing python methods in those classes)
- remove some non-existing methods from the header files
- add scripts/sipdiff
- replace some usages of std::vector and std::set with QVector/QSet
2012-09-24 02:42:57 +02:00
Magnus Homann
6b26c4a9f8 Made qgsexpression be DA-aware 2012-09-04 12:10:03 +02:00
Nathan Woodrow
a61a15bb1e Move expression text replace to QgsExpression
- Update actions, html map tips, and annotations
2012-09-02 22:46:19 +10:00
Nathan Woodrow
c467e79f3c Add expression functions for handling date/time:
- year,month,day,hour,minute,second extraction
    - new QgsInterval objects - handles time amounts
    - age() function returns the difference between two  datetimes
    - $now returns the current date and time
    - support for datetime - interval = new datetime
    - tointerval, todate, totime functions
    - tests ;)
2012-06-30 20:40:54 +10:00
Martin Dobias
bf86521d49 Fixes for refinement of rules.
- quoting of columns (#5536 and #5542)
- quoting of string
- do not quote of numbers (avoids type cast during evaluation)
- use at least 4 floating point digits for doubles
2012-06-02 00:08:26 +02:00