@@ -161,7 +161,7 @@ Returns root node of the expression. Root node is null is parsing has failed
161
161
all attributes from the layer are required for evaluation of the expression.
162
162
QgsFeatureRequest.setSubsetOfAttributes automatically handles this case.
163
163
164
- \see referencedAttributeIndexes()
164
+ .. seealso:: referencedAttributeIndexes()
165
165
:rtype: set of str
166
166
%End
167
167
@@ -267,9 +267,9 @@ expression() instead.
267
267
%Docstring
268
268
Return calculator used for distance and area calculations
269
269
(used by $length, $area and $perimeter functions only)
270
- \see setGeomCalculator()
271
- \see distanceUnits()
272
- \see areaUnits()
270
+ .. seealso:: setGeomCalculator()
271
+ .. seealso:: distanceUnits()
272
+ .. seealso:: areaUnits()
273
273
:rtype: QgsDistanceArea
274
274
%End
275
275
@@ -281,7 +281,7 @@ expression() instead.
281
281
cartesian methods (ie no ellipsoidal calculations).
282
282
\param calc geometry calculator. Ownership is not transferred. Set to a None to force
283
283
cartesian calculations.
284
- \see geomCalculator()
284
+ .. seealso:: geomCalculator()
285
285
%End
286
286
287
287
QgsUnitTypes::DistanceUnit distanceUnits() const;
@@ -291,8 +291,8 @@ expression() instead.
291
291
292
292
distances are only converted when a geomCalculator() has been set
293
293
.. versionadded:: 2.14
294
- \see setDistanceUnits()
295
- \see areaUnits()
294
+ .. seealso:: setDistanceUnits()
295
+ .. seealso:: areaUnits()
296
296
:rtype: QgsUnitTypes.DistanceUnit
297
297
%End
298
298
@@ -303,8 +303,8 @@ expression() instead.
303
303
304
304
distances are only converted when a geomCalculator() has been set
305
305
.. versionadded:: 2.14
306
- \see distanceUnits()
307
- \see setAreaUnits()
306
+ .. seealso:: distanceUnits()
307
+ .. seealso:: setAreaUnits()
308
308
%End
309
309
310
310
QgsUnitTypes::AreaUnit areaUnits() const;
@@ -314,8 +314,8 @@ expression() instead.
314
314
315
315
areas are only converted when a geomCalculator() has been set
316
316
.. versionadded:: 2.14
317
- \see setAreaUnits()
318
- \see distanceUnits()
317
+ .. seealso:: setAreaUnits()
318
+ .. seealso:: distanceUnits()
319
319
:rtype: QgsUnitTypes.AreaUnit
320
320
%End
321
321
@@ -326,8 +326,8 @@ expression() instead.
326
326
327
327
areas are only converted when a geomCalculator() has been set
328
328
.. versionadded:: 2.14
329
- \see areaUnits()
330
- \see setDistanceUnits()
329
+ .. seealso:: areaUnits()
330
+ .. seealso:: setDistanceUnits()
331
331
%End
332
332
333
333
static QString replaceExpressionText( const QString &action, const QgsExpressionContext *context,
@@ -613,7 +613,7 @@ Does this function use a geometry object.
613
613
%Docstring
614
614
Returns a list of the groups the function belongs to.
615
615
.. versionadded:: 3.0
616
- \see group()
616
+ .. seealso:: group()
617
617
:rtype: list of str
618
618
%End
619
619
@@ -662,15 +662,15 @@ The help text for the function.
662
662
\param function function to register
663
663
\param transferOwnership set to true to transfer ownership of function to expression engine
664
664
:return: true on successful registration
665
- \see unregisterFunction
665
+ .. seealso:: unregisterFunction
666
666
:rtype: bool
667
667
%End
668
668
669
669
static bool unregisterFunction( const QString &name );
670
670
%Docstring
671
671
Unregisters a function from the expression engine. The function will no longer be usable in expressions.
672
672
\param name function name
673
- \see registerFunction
673
+ .. seealso:: registerFunction
674
674
:rtype: bool
675
675
%End
676
676
@@ -703,16 +703,16 @@ return index of the function in Functions array
703
703
static QString quotedColumnRef( QString name );
704
704
%Docstring
705
705
Returns a quoted column reference (in double quotes)
706
- \see quotedString()
707
- \see quotedValue()
706
+ .. seealso:: quotedString()
707
+ .. seealso:: quotedValue()
708
708
:rtype: str
709
709
%End
710
710
711
711
static QString quotedString( QString text );
712
712
%Docstring
713
713
Returns a quoted version of a string (in single quotes)
714
- \see quotedValue()
715
- \see quotedColumnRef()
714
+ .. seealso:: quotedValue()
715
+ .. seealso:: quotedColumnRef()
716
716
:rtype: str
717
717
%End
718
718
@@ -722,8 +722,8 @@ return index of the function in Functions array
722
722
quotations where required.
723
723
\param value value to convert to a string representation
724
724
.. versionadded:: 2.14
725
- \see quotedString()
726
- \see quotedColumnRef()
725
+ .. seealso:: quotedString()
726
+ .. seealso:: quotedColumnRef()
727
727
:rtype: str
728
728
%End
729
729
@@ -734,8 +734,8 @@ return index of the function in Functions array
734
734
\param value value to convert to a string representation
735
735
\param type value type
736
736
.. versionadded:: 2.14
737
- \see quotedString()
738
- \see quotedColumnRef()
737
+ .. seealso:: quotedString()
738
+ .. seealso:: quotedColumnRef()
739
739
:rtype: str
740
740
%End
741
741
@@ -753,6 +753,10 @@ return index of the function in Functions array
753
753
754
754
class Node
755
755
{
756
+ %Docstring
757
+
758
+ Abstract base class for all nodes that can appear in an expression.
759
+ %End
756
760
757
761
%TypeHeaderCode
758
762
#include "qgsexpression.h"
@@ -761,49 +765,59 @@ return index of the function in Functions array
761
765
%ConvertToSubClassCode
762
766
switch ( sipCpp->nodeType() )
763
767
{
764
- case QgsExpression::ntUnaryOperator: sipType = sipType_QgsExpression_NodeUnaryOperator; break;
765
- case QgsExpression::ntBinaryOperator: sipType = sipType_QgsExpression_NodeBinaryOperator; break;
766
- case QgsExpression::ntInOperator: sipType = sipType_QgsExpression_NodeInOperator; break;
767
- case QgsExpression::ntFunction: sipType = sipType_QgsExpression_NodeFunction; break;
768
- case QgsExpression::ntLiteral: sipType = sipType_QgsExpression_NodeLiteral; break;
769
- case QgsExpression::ntColumnRef: sipType = sipType_QgsExpression_NodeColumnRef; break;
770
- case QgsExpression::ntCondition: sipType = sipType_QgsExpression_NodeCondition; break;
771
- default: sipType = 0; break;
768
+ case QgsExpression::ntUnaryOperator:
769
+ sipType = sipType_QgsExpression_NodeUnaryOperator;
770
+ break;
771
+ case QgsExpression::ntBinaryOperator:
772
+ sipType = sipType_QgsExpression_NodeBinaryOperator;
773
+ break;
774
+ case QgsExpression::ntInOperator:
775
+ sipType = sipType_QgsExpression_NodeInOperator;
776
+ break;
777
+ case QgsExpression::ntFunction:
778
+ sipType = sipType_QgsExpression_NodeFunction;
779
+ break;
780
+ case QgsExpression::ntLiteral:
781
+ sipType = sipType_QgsExpression_NodeLiteral;
782
+ break;
783
+ case QgsExpression::ntColumnRef:
784
+ sipType = sipType_QgsExpression_NodeColumnRef;
785
+ break;
786
+ case QgsExpression::ntCondition:
787
+ sipType = sipType_QgsExpression_NodeCondition;
788
+ break;
789
+ default:
790
+ sipType = 0;
791
+ break;
772
792
}
773
793
%End
774
794
public:
775
795
virtual ~Node();
776
796
777
797
virtual QgsExpression::NodeType nodeType() const = 0;
778
798
%Docstring
779
- Abstract virtual that returns the type of this node.
799
+ Get the type of this node.
780
800
781
801
:return: The type of this node
782
802
:rtype: QgsExpression.NodeType
783
803
%End
784
804
785
- virtual QVariant eval( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
786
- %Docstring
787
- Abstract virtual eval method
788
- Errors are reported to the parent
789
- .. versionadded:: 2.12
790
- :rtype: QVariant
791
- %End
792
-
793
- virtual bool prepare( QgsExpression *parent, const QgsExpressionContext *context ) = 0;
805
+ virtual QString dump() const = 0;
794
806
%Docstring
795
- Abstract virtual preparation method
796
- Errors are reported to the parent
797
- .. versionadded:: 2.12
798
- :rtype: bool
807
+ Dump this node into a serialized (part) of an expression.
808
+ The returned expression does not necessarily literally match
809
+ the original expression, it's just guaranteed to behave the same way.
810
+ :rtype: str
799
811
%End
800
812
801
- virtual QString dump() const = 0 ;
813
+ QVariant eval( QgsExpression *parent, const QgsExpressionContext *context ) ;
802
814
%Docstring
803
- Abstract virtual dump method
815
+ Evaluate this node with the given context and parent.
816
+ This will return a cached value if it has been determined to be static
817
+ during the prepare() execution.
804
818
805
- :return: An expression which represents this node as string
806
- :rtype: str
819
+ .. versionadded:: 2.12
820
+ :rtype: QVariant
807
821
%End
808
822
809
823
virtual QgsExpression::Node *clone() const = 0;
@@ -832,7 +846,7 @@ return index of the function in Functions array
832
846
833
847
virtual QSet<QString> referencedVariables() const = 0;
834
848
%Docstring
835
- Return a list of all variables which are used in this expression.
849
+ Return a set of all variables which are used in this expression.
836
850
:rtype: set of str
837
851
%End
838
852
@@ -846,6 +860,45 @@ return index of the function in Functions array
846
860
:return: true if a geometry is required to evaluate this expression
847
861
:rtype: bool
848
862
%End
863
+
864
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const = 0;
865
+ %Docstring
866
+ Returns true if this node can be evaluated for a static value. This is used during
867
+ the prepare() step and in case it returns true, the value of this node will already
868
+ be evaluated and the result cached (and therefore not re-evaluated in subsequent calls
869
+ to eval()). In case this returns true, prepareNode() will never be called.
870
+
871
+ .. versionadded:: 3.0
872
+ :rtype: bool
873
+ %End
874
+
875
+ bool prepare( QgsExpression *parent, const QgsExpressionContext *context );
876
+ %Docstring
877
+ Prepare this node for evaluation.
878
+ This will check if the node content is static and in this case cache the value.
879
+ If it's not static it will call prepareNode() to allow the node to do initialization
880
+ work like for example resolving a column name to an attribute index.
881
+
882
+ .. versionadded:: 2.12
883
+ :rtype: bool
884
+ %End
885
+
886
+ private:
887
+ virtual bool prepareNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0 ;
888
+ %Docstring
889
+ Abstract virtual preparation method
890
+ Errors are reported to the parent
891
+ .. versionadded:: 3.0
892
+ :rtype: bool
893
+ %End
894
+ private:
895
+ virtual QVariant evalNode( QgsExpression *parent, const QgsExpressionContext *context ) = 0 ;
896
+ %Docstring
897
+ Abstract virtual eval method
898
+ Errors are reported to the parent
899
+ .. versionadded:: 3.0
900
+ :rtype: QVariant
901
+ %End
849
902
};
850
903
851
904
class NamedNode
@@ -937,18 +990,23 @@ Creates a deep copy of this list. Ownership is transferred to the caller
937
990
:rtype: str
938
991
%End
939
992
940
- protected:
941
-
942
993
};
943
994
944
995
class NodeUnaryOperator : QgsExpression::Node
945
996
{
997
+ %Docstring
998
+ A unary node is either negative as in boolean (not) or as in numbers (minus).
999
+ %End
946
1000
947
1001
%TypeHeaderCode
948
1002
#include "qgsexpression.h"
949
1003
%End
950
1004
public:
1005
+
951
1006
NodeUnaryOperator( QgsExpression::UnaryOperator op, QgsExpression::Node *operand /Transfer/ );
1007
+ %Docstring
1008
+ A node unary operator is modifying the value of ``operand`` by negating it with \op.
1009
+ %End
952
1010
~NodeUnaryOperator();
953
1011
954
1012
QgsExpression::UnaryOperator op() const;
@@ -961,16 +1019,17 @@ Creates a deep copy of this list. Ownership is transferred to the caller
961
1019
%End
962
1020
963
1021
virtual QgsExpression::NodeType nodeType() const;
964
- virtual bool prepare ( QgsExpression *parent, const QgsExpressionContext *context );
965
- virtual QVariant eval ( QgsExpression *parent, const QgsExpressionContext *context );
1022
+ virtual bool prepareNode ( QgsExpression *parent, const QgsExpressionContext *context );
1023
+ virtual QVariant evalNode ( QgsExpression *parent, const QgsExpressionContext *context );
966
1024
virtual QString dump() const;
967
1025
968
1026
virtual QSet<QString> referencedColumns() const;
969
1027
virtual QSet<QString> referencedVariables() const;
970
1028
virtual bool needsGeometry() const;
971
1029
virtual QgsExpression::Node *clone() const;
972
1030
973
- protected:
1031
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;
1032
+
974
1033
};
975
1034
976
1035
class NodeBinaryOperator : QgsExpression::Node
@@ -980,7 +1039,11 @@ Creates a deep copy of this list. Ownership is transferred to the caller
980
1039
#include "qgsexpression.h"
981
1040
%End
982
1041
public:
1042
+
983
1043
NodeBinaryOperator( QgsExpression::BinaryOperator op, QgsExpression::Node *opLeft /Transfer/, QgsExpression::Node *opRight /Transfer/ );
1044
+ %Docstring
1045
+ Binary combination of the left and the right with op.
1046
+ %End
984
1047
~NodeBinaryOperator();
985
1048
986
1049
QgsExpression::BinaryOperator op() const;
@@ -997,14 +1060,15 @@ Creates a deep copy of this list. Ownership is transferred to the caller
997
1060
%End
998
1061
999
1062
virtual QgsExpression::NodeType nodeType() const;
1000
- virtual bool prepare ( QgsExpression *parent, const QgsExpressionContext *context );
1001
- virtual QVariant eval ( QgsExpression *parent, const QgsExpressionContext *context );
1063
+ virtual bool prepareNode ( QgsExpression *parent, const QgsExpressionContext *context );
1064
+ virtual QVariant evalNode ( QgsExpression *parent, const QgsExpressionContext *context );
1002
1065
virtual QString dump() const;
1003
1066
1004
1067
virtual QSet<QString> referencedColumns() const;
1005
1068
virtual QSet<QString> referencedVariables() const;
1006
1069
virtual bool needsGeometry() const;
1007
1070
virtual QgsExpression::Node *clone() const;
1071
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;
1008
1072
1009
1073
int precedence() const;
1010
1074
%Docstring
@@ -1024,7 +1088,11 @@ Creates a deep copy of this list. Ownership is transferred to the caller
1024
1088
#include "qgsexpression.h"
1025
1089
%End
1026
1090
public:
1091
+
1027
1092
NodeInOperator( QgsExpression::Node *node /Transfer/, QgsExpression::NodeList *list /Transfer/, bool notin = false );
1093
+ %Docstring
1094
+ This node tests if the result of \node is in the result of ``list``. Optionally it can be inverted with ``notin`` which by default is false.
1095
+ %End
1028
1096
virtual ~NodeInOperator();
1029
1097
1030
1098
QgsExpression::Node *node() const;
@@ -1041,16 +1109,16 @@ Creates a deep copy of this list. Ownership is transferred to the caller
1041
1109
%End
1042
1110
1043
1111
virtual QgsExpression::NodeType nodeType() const;
1044
- virtual bool prepare ( QgsExpression *parent, const QgsExpressionContext *context );
1045
- virtual QVariant eval ( QgsExpression *parent, const QgsExpressionContext *context );
1112
+ virtual bool prepareNode ( QgsExpression *parent, const QgsExpressionContext *context );
1113
+ virtual QVariant evalNode ( QgsExpression *parent, const QgsExpressionContext *context );
1046
1114
virtual QString dump() const;
1047
1115
1048
1116
virtual QSet<QString> referencedColumns() const;
1049
1117
virtual QSet<QString> referencedVariables() const;
1050
1118
virtual bool needsGeometry() const;
1051
1119
virtual QgsExpression::Node *clone() const;
1120
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;
1052
1121
1053
- protected:
1054
1122
};
1055
1123
1056
1124
class NodeFunction : QgsExpression::Node
@@ -1060,7 +1128,12 @@ Creates a deep copy of this list. Ownership is transferred to the caller
1060
1128
#include "qgsexpression.h"
1061
1129
%End
1062
1130
public:
1131
+
1063
1132
NodeFunction( int fnIndex, QgsExpression::NodeList *args /Transfer/ );
1133
+ %Docstring
1134
+ A function node consists of an index of the function in the global function array and
1135
+ a list of arguments that will be passed to it.
1136
+ %End
1064
1137
1065
1138
virtual ~NodeFunction();
1066
1139
@@ -1074,14 +1147,15 @@ Creates a deep copy of this list. Ownership is transferred to the caller
1074
1147
%End
1075
1148
1076
1149
virtual QgsExpression::NodeType nodeType() const;
1077
- virtual bool prepare ( QgsExpression *parent, const QgsExpressionContext *context );
1078
- virtual QVariant eval ( QgsExpression *parent, const QgsExpressionContext *context );
1150
+ virtual bool prepareNode ( QgsExpression *parent, const QgsExpressionContext *context );
1151
+ virtual QVariant evalNode ( QgsExpression *parent, const QgsExpressionContext *context );
1079
1152
virtual QString dump() const;
1080
1153
1081
1154
virtual QSet<QString> referencedColumns() const;
1082
1155
virtual QSet<QString> referencedVariables() const;
1083
1156
virtual bool needsGeometry() const;
1084
1157
virtual QgsExpression::Node *clone() const;
1158
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;
1085
1159
1086
1160
static bool validateParams( int fnIndex, QgsExpression::NodeList *args, QString &error );
1087
1161
%Docstring
@@ -1107,16 +1181,16 @@ The value of the literal.
1107
1181
%End
1108
1182
1109
1183
virtual QgsExpression::NodeType nodeType() const;
1110
- virtual bool prepare ( QgsExpression *parent, const QgsExpressionContext *context );
1111
- virtual QVariant eval ( QgsExpression *parent, const QgsExpressionContext *context );
1184
+ virtual bool prepareNode ( QgsExpression *parent, const QgsExpressionContext *context );
1185
+ virtual QVariant evalNode ( QgsExpression *parent, const QgsExpressionContext *context );
1112
1186
virtual QString dump() const;
1113
1187
1114
1188
virtual QSet<QString> referencedColumns() const;
1115
1189
virtual QSet<QString> referencedVariables() const;
1116
1190
virtual bool needsGeometry() const;
1117
1191
virtual QgsExpression::Node *clone() const;
1192
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;
1118
1193
1119
- protected:
1120
1194
};
1121
1195
1122
1196
class NodeColumnRef : QgsExpression::Node
@@ -1135,32 +1209,40 @@ The name of the column.
1135
1209
%End
1136
1210
1137
1211
virtual QgsExpression::NodeType nodeType() const;
1138
- virtual bool prepare ( QgsExpression *parent, const QgsExpressionContext *context );
1139
- virtual QVariant eval ( QgsExpression *parent, const QgsExpressionContext *context );
1212
+ virtual bool prepareNode ( QgsExpression *parent, const QgsExpressionContext *context );
1213
+ virtual QVariant evalNode ( QgsExpression *parent, const QgsExpressionContext *context );
1140
1214
virtual QString dump() const;
1141
1215
1142
1216
virtual QSet<QString> referencedColumns() const;
1143
1217
virtual QSet<QString> referencedVariables() const;
1144
1218
virtual bool needsGeometry() const;
1145
1219
1146
1220
virtual QgsExpression::Node *clone() const;
1221
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;
1147
1222
1148
- protected:
1149
1223
};
1150
1224
1225
+
1151
1226
class WhenThen
1152
1227
{
1153
1228
1154
1229
%TypeHeaderCode
1155
1230
#include "qgsexpression.h"
1156
1231
%End
1157
1232
public:
1158
- WhenThen( QgsExpression::Node *whenExp /Transfer/, QgsExpression::Node *thenExp /Transfer/ );
1233
+
1234
+ WhenThen( QgsExpression::Node *whenExp, QgsExpression::Node *thenExp );
1235
+ %Docstring
1236
+ A combination of when and then. Simple as that.
1237
+ %End
1159
1238
~WhenThen();
1160
1239
1161
1240
1162
- QgsExpression::Node *mWhenExp;
1163
- QgsExpression::Node *mThenExp;
1241
+ QgsExpression::WhenThen *clone() const;
1242
+ %Docstring
1243
+ Get a deep copy of this WhenThen combination.
1244
+ :rtype: QgsExpression.WhenThen
1245
+ %End
1164
1246
1165
1247
private:
1166
1248
WhenThen( const QgsExpression::WhenThen &rh );
@@ -1174,29 +1256,33 @@ The name of the column.
1174
1256
#include "qgsexpression.h"
1175
1257
%End
1176
1258
public:
1259
+
1177
1260
NodeCondition( QgsExpression::WhenThenList *conditions, QgsExpression::Node *elseExp = 0 );
1261
+ %Docstring
1262
+ Create a new node with the given list of ``conditions`` and an optional ``elseExp`` expression.
1263
+ %End
1178
1264
1179
1265
1180
1266
~NodeCondition();
1181
1267
1182
1268
virtual QgsExpression::NodeType nodeType() const;
1183
- virtual QVariant eval ( QgsExpression *parent, const QgsExpressionContext *context );
1184
- virtual bool prepare ( QgsExpression *parent, const QgsExpressionContext *context );
1269
+ virtual QVariant evalNode ( QgsExpression *parent, const QgsExpressionContext *context );
1270
+ virtual bool prepareNode ( QgsExpression *parent, const QgsExpressionContext *context );
1185
1271
virtual QString dump() const;
1186
1272
1187
1273
virtual QSet<QString> referencedColumns() const;
1188
1274
virtual QSet<QString> referencedVariables() const;
1189
1275
virtual bool needsGeometry() const;
1190
1276
virtual QgsExpression::Node *clone() const;
1277
+ virtual bool isStatic( QgsExpression *parent, const QgsExpressionContext *context ) const;
1191
1278
1192
- protected:
1193
1279
};
1194
1280
1195
1281
static QString helpText( QString name );
1196
1282
%Docstring
1197
1283
Returns the help text for a specified function.
1198
1284
\param name function name
1199
- \see variableHelpText()
1285
+ .. seealso:: variableHelpText()
1200
1286
:rtype: str
1201
1287
%End
1202
1288
@@ -1206,7 +1292,7 @@ The name of the column.
1206
1292
\param variableName name of variable
1207
1293
\param showValue set to true to include current value of variable in help text
1208
1294
\param value current value of variable to show in help text
1209
- \see helpText()
1295
+ .. seealso:: helpText()
1210
1296
.. versionadded:: 2.12
1211
1297
:rtype: str
1212
1298
%End
0 commit comments