@@ -67,6 +67,9 @@ Possible QVariant value types:
6767- string
6868- geometry
6969
70+ Three Value Logic
71+ =================
72+
7073Similarly to SQL, this class supports three-value logic: true/false/unknown.
7174Unknown value may be a result of operations with missing data (NULL). Please note
7275that NULL is different value than zero or an empty string. For example
@@ -75,10 +78,16 @@ that NULL is different value than zero or an empty string. For example
7578There is no special (three-value) 'boolean' type: true/false is represented as
76791/0 integer, unknown value is represented the same way as NULL values: invalid QVariant.
7780
81+ Performance
82+ ===========
83+
7884For better performance with many evaluations you may first call prepare(fields) function
7985to find out indices of columns and then repeatedly call evaluate(feature).
8086
81- Type conversion: operators and functions that expect arguments to be of particular
87+ Type conversion
88+ ===============
89+
90+ Operators and functions that expect arguments to be of a particular
8291type automatically convert the arguments to that type, e.g. sin('2.1') will convert
8392the argument to a double, length(123) will first convert the number to a string.
8493Explicit conversion can be achieved with toint, toreal, tostring functions.
@@ -88,15 +97,47 @@ or they can be converted to numeric types.
8897
8998Arithmetic operators do integer arithmetics if both operands are integer. That is
90992+2 yields integer 4, but 2.0+2 returns real number 4.0. There are also two versions of
91- division and modulo operators: 1.0/2 returns 0.5 while 1/2 returns 0. */
100+ division and modulo operators: 1.0/2 returns 0.5 while 1/2 returns 0.
101+
102+ Implicit sharing
103+ ================
104+
105+ This class is implicitly shared, copying has a very low overhead.
106+ It is normally preferable to call `QgsExpression( otherExpression )` instead of
107+ `QgsExpression( otherExpression.expression() )`. A deep copy will only be made
108+ when {@link prepare()} is called. For usage this means mainly, that you should
109+ normally keep an unprepared master copy of a QgsExpression and whenever using it
110+ with a particular QgsFeatureIterator copy it just before and prepare it using the
111+ same context as the iterator.
112+
113+ Implicit sharing was added in 2.14
114+
115+ */
92116
93117Q_NOWARN_DEPRECATED_PUSH
94118class CORE_EXPORT QgsExpression
95119{
96120 Q_DECLARE_TR_FUNCTIONS ( QgsExpression )
97121 public:
122+ /* *
123+ * Creates a new expression based on the provided string.
124+ * The string will immediately be parsed. For optimization
125+ * {@link prepare()} should alwys be called before every
126+ * loop in which this expression is used.
127+ */
98128 QgsExpression ( const QString& expr );
129+
130+ /* *
131+ * Create a copy of this expression. This is preferred
132+ * over recreating an expression from a string since
133+ * it does not need to be re-parsed.
134+ */
99135 QgsExpression ( const QgsExpression& other );
136+ /* *
137+ * Create a copy of this expression. This is preferred
138+ * over recreating an expression from a string since
139+ * it does not need to be re-parsed.
140+ */
100141 QgsExpression& operator =( const QgsExpression& other );
101142 ~QgsExpression ();
102143
@@ -223,10 +264,15 @@ class CORE_EXPORT QgsExpression
223264
224265 double scale ();
225266
226- // ! Alias for dump()
227- const QString expression () const ;
267+ // ! Return the original, unmodified expression string.
268+ // ! If there was none supplied because it was constructed by sole
269+ // ! API calls, dump() will be used to create one instead.
270+ QString expression () const ;
228271
229- // ! Return the expression string that represents this QgsExpression.
272+ // ! Return an expression string, constructed from the internal
273+ // ! abstract syntax tree. This does not contain any nice whitespace
274+ // ! formatting or comments. In general it is preferrable to use
275+ // ! expression() instead.
230276 QString dump () const ;
231277
232278 // ! Return calculator used for distance and area calculations
@@ -331,6 +377,7 @@ class CORE_EXPORT QgsExpression
331377 // strings
332378 boConcat,
333379 };
380+
334381 enum SpatialOperator
335382 {
336383 soBbox,
@@ -1055,6 +1102,12 @@ class CORE_EXPORT QgsExpression
10551102 QList<HelpVariant> mVariants ;
10561103 };
10571104
1105+ /* *
1106+ * Helper for implicit sharing. When called will create
1107+ * a new deep copy of this expression.
1108+ *
1109+ * @note not available in Python bindings
1110+ */
10581111 void detach ();
10591112
10601113 QgsExpressionPrivate* d;
0 commit comments