71 Commits

Author SHA1 Message Date
Nyall Dawson
77f8b83ac0 Minor optimisations to QgsExpressionNodeFunction construction 2023-08-04 11:59:37 +10:00
Nyall Dawson
08b8c6d7be Improve cost of QgsExpression::functionIndex
This is called a LOT! Optimise the function by avoiding multiple
list copies and by caching previous found function indexes
2023-08-04 11:59:37 +10:00
Denis Rouzaud
5bccd556e2
move QgsTolerance::UnitType to Qgis::MapUnitType (#53347)
* move QgsTolerance::UnitType to Qgis::MapUnitType

* missing forward declaration

* forward declaration

* use MapToolUnit

* forward declaration

* sipify

* fix tests

* Apply suggestions from code review

Co-authored-by: Nyall Dawson <nyall.dawson@gmail.com>

* forward declaration

* forward declaration

* forward declaration

* sipify

* fix missing parenthesis

---------

Co-authored-by: Nyall Dawson <nyall.dawson@gmail.com>
2023-06-06 18:33:50 +02:00
Nyall Dawson
2ef0734913 Add test to ensure help examples are valid expressions 2023-04-12 09:51:36 +10:00
Nyall Dawson
f9c3da1e06 Move unit enums to Qgis, promote to enum class 2023-02-19 13:29:06 +10:00
Nyall Dawson
f88c0c3a4c Sipify 2023-01-09 14:35:50 +10:00
Nyall Dawson
b23eb1d250 [feature] New function "load_layer"
This function (available only in Processing expressions for now),
allows loading a map layer via a source string and provider name.

It is designed to allow use of the expression functions which
directly reference map layers (such as the aggregate functions)
with a hardcoded layer path, eg. then permitting these functions
to be used outside of a project (such as via the qgis_process tool)
2023-01-09 14:35:50 +10:00
Alessandro Pasotti
669fa47bc0 Doxy 2022-11-10 12:46:34 +01:00
Alessandro Pasotti
f040c260bd Raster maptips 2022-11-09 09:48:02 +01:00
Alessandro Pasotti
34f0e59735 Address PR review comments and handle NULLS
Refactor the evaluation code, handle NULLs to
return a boolean when it is possible.
2022-03-15 12:13:42 +01:00
Alessandro Pasotti
ba28631d33 NULL between tests 2022-03-14 14:19:53 +01:00
Alessandro Pasotti
7601250a54 SQL expression compiler and more tests for BETWEEN 2022-03-14 14:19:52 +01:00
Alessandro Pasotti
c8d55607ea BETWEEN expression
TODO: type casting, SQL compiler, help text
2022-03-14 14:19:52 +01:00
Nyall Dawson
2f74a24eeb Fix typo 2022-02-01 08:23:29 +10:00
Alex
73e036ebdb Correctly handle sort field as field in atlas sorting
Fixes #40332
2022-02-01 08:23:29 +10:00
Denis Rouzaud
4b3c50d59e add optional type parameter to QgsExpression::createFieldEqualityExpression 2021-11-08 09:18:19 +01:00
Juergen E. Fischer
c6008b7ee1 fix MSVC build: reverts fee62e4, dff05dd and e3a77b9484c effectivly
reverting 3fb0f66 (followup #45348)

Using --no-public-is-protected (default on Windows) also works on Linux
and fixes #45331 too
2021-10-21 23:03:48 +02:00
Etienne Trimaille
4284beb004 Add API in expression to set help string on a variable 2021-10-16 06:36:15 +10:00
nirvn
ef84e48a09 Run sipify_all.sh 2021-10-12 16:34:05 +10:00
Denis Rouzaud
ec16736306 run sipify 2021-10-12 16:34:05 +10:00
Vincent Cloarec
45e07dd72f
Select mesh elements by expression UI (#44835)
[mesh] [feature] Select mesh elements by expression
2021-09-09 08:29:45 +02:00
Vincent Cloarec
bc192a60b2
Mesh expressions: add $vertex_as_point and $vertex_z functions (#44786)
* mesh expression $vertex_as_point $vertex_Z_value

* functions help

* SIP, doc and indentation

* fix SIP

* fix help file

* change function name and add Meshes group description

* fix typo

* fix strings and docs

* typo
2021-08-24 20:56:16 +02:00
Nyall Dawson
4d5014deae Add QgsExpression utility function to match an expression or field name string to a layer's field index 2021-08-12 03:26:46 +10:00
Nyall Dawson
76c7d11ba9 More dox fixes 2021-06-10 05:57:26 +10:00
Nyall Dawson
e262f1456c Fix layout checks 2021-06-10 05:57:26 +10:00
Nyall Dawson
0a4b9a62cf [optimization][expressions] Simplify "CASE WHEN..." expressions
during preparation wherever possible

In many situations we are able to optimize a case when expression
and replace it with a simpler expression node during the preparation
stage. Specifically, if the WHEN conditions are known to be
static values (such as those coming from certain expression context
variables) then we can often replace the whole condition node
with the THEN node of the first static true condition.

E.g.

    CASE
        WHEN @variable=1 THEN "first_field"
        WHEN @variable=2 THEN "second_field"
        ELSE "third_field"
    END

If @variable is static and '1', then the whole expression node will ALWAYS
be identical to "first_field". Similiarly if @variable='2', then the
whole expression will ALWAYS be "second_field".

If we're able to apply this optimization, then we use the simplified
effective node which represents the whole node during evaluation
time and save a bunch of unnecessary work.

TODO: If we use the effective node during expression compilation
for providers we would be able to handoff more expressions involving
QGIS-side variables and other components to the backend, resulting
in increased use of backend provider indices, etc....
2021-06-10 05:57:26 +10:00
Nyall Dawson
1bcb09abe6 __repr__ for some QgsExpressionNode subclasses 2021-06-10 05:57:26 +10:00
Denis Rouzaud
35c557a234 run sipify 2021-05-26 14:30:54 +02:00
Nyall Dawson
ffa99b7b64 Fix doxygen blocks which don't use the * prefix on all lines, which
prevents the auto format and sipify scripts from doing their full
formatting magic
2021-04-19 12:54:13 +10:00
Denis Rouzaud
ba8a445850 run sipify 2021-03-22 21:13:52 +01:00
Nyall Dawson
14f2ab53b1 When attempting to precalculated nodes during an expression prepare
stage, be more intelligent about compiling AND or OR nodes

We can take advantage of the fact that and AND node will ALWAYS
be false if either input node is static and evaluates to FALSE,
and that OR nodes will always be true if either input is static
and evaluates to TRUE.

In some cases this allows us the shortcut and cut out non-static
nodes during preparation, resulting in faster evaluation and
more easily compiled expressions...
2021-02-24 12:39:36 +10:00
Nyall Dawson
48ce042c84 Take advantage of pre-computed static expression nodes when determining
the referenced fields of an expression

Avoids some cases where use of various expression functions which
normally trigger all attributes to be requested, yet can be pre-computed
during prepare stages, cause non-provider fields to be listed in
the referenced columns and accordingly prevent expression compilation.

Notably this can occur when using an expression like:

   aggregate( .... , filter:=
"some_child_field"=attribute(@atlas_feature, 'some_atlas_field_name') )

where the whole attribute(@atlas_feature....) part is a constant
static value and can be compiled down to a trivial, index-friendly
"some_child_field"=### filter for the aggregate provider request.
Ultimately giving a big performance boost to the atlas!
2021-02-15 12:12:00 +10:00
Nyall Dawson
8fa29ac6d2 When we are compiling expressions to handoff to backend providers,
check if a node has already been determined to evaluate to a static,
precalculated value, and if so, use this value for the node instead
of attempting to compile the actual contents of the node itself

If we are certain that a node is static and will never change,
the this potentially allows us to short-cut a large part of the
filter expressions content. We already use this short-cut when
evaluating expressions on the QGIS side since years, and its
proven to be stable and reliable. By respecting this during
expression compilation we can offer a huge speed up to certain
filter expressions, especially those which utilise QGIS variables
which are known to be static (such as atlas variables, map scales,
etc). Previously ANY use of a qgis variable would always cause
expression compilation to fail and require a full set of feature
fetching from the provider.

(Resulted in orders of magnitude faster atlas export for a complex
atlas.)
2021-02-12 06:05:56 +10:00
Nyall Dawson
50b9beaad6 [sipify] Catch more class references and insert :py:class: annotations 2021-01-31 05:41:22 +10:00
Denis Rouzaud
e071f31a58 add an argument to configure preview length in QgsExpression::formatPreviewString 2021-01-28 15:18:32 +01:00
Nyall Dawson
44c2a26074 Add utility functions to determine if a QgsExpression is a simple
"field=value" type expression, and for condensing a list of similar
expressions to an equivalent "field IN (value, value2,...)" expression
wherever possible
2021-01-12 12:16:50 +10:00
Harrissou Sant-anna
d4e60173bc Fix after review 2020-07-21 10:13:45 +10:00
Harrissou Sant-anna
140425b1e3 Fix file formatting for better output rendering 2020-07-21 10:13:45 +10:00
Harrissou Sant-anna
5c83cd07cc Move some cpp code samples to python 2020-07-21 10:13:45 +10:00
Nyall Dawson
81a9db9f57 [sipify] Fix creation of cross references 2020-06-15 13:43:58 +10:00
Alessandro Pasotti
195efa42a1 Final touches to the parent form API 2020-03-04 08:52:52 +01:00
signedav
20ac7e3c22 Update python/core/auto_generated/expression/qgsexpression.sip.in
Co-Authored-By: Matthias Kuhn <matthias@opengis.ch>

and

set parameter to const
2019-12-03 15:29:17 +01:00
David Signer
7fbf2c867d tags helping to find the correct function are integrated into the help of the expression
defined in the json files and used by the expression builder to find the function (not using as alias)
2019-12-03 15:29:16 +01:00
David Signer
161af6ad26 search tags in expression function to look up the functionality in the expression builder 2019-11-28 16:47:48 +01:00
Matthias Kuhn
65fe231ee9 Q_GLOBAL_STATIC for expressions 2019-11-02 15:01:59 +01:00
Nyall Dawson
ffc71c4f57 Remove const_cast 2019-09-18 07:55:46 +10:00
Nyall Dawson
8f6f04885b [FEATURE] Add @scale_value expression variable for use when evaluating
data defined text format properties while rendering scale bar text

Allows for per-label customisation of the text format inside scale bars
2019-07-22 11:34:32 +10:00
Nyall Dawson
ef97fefbaa [layouts] Add API to set expression variables at a multiframe level 2019-06-28 07:12:40 +10:00
Nyall Dawson
16a64ed84d Deprecate some methods, dox++ 2019-03-22 12:16:22 +10:00
Nyall Dawson
107b48a430 Add NULLPTR macro for use in doxygen comments
For the c++ api dox this expands to "\c nullptr" (the
\c directive indicates a code literal value), and for sipify/Python
it expands to ``None`` (`` is sphinx annotation for literal values)

Makes for nicer dox for both c++ and Python!
2019-02-27 09:41:11 +10:00