Skip to content

Commit 4f999c8

Browse files
committed
Doxymentation for QgsExpression
1 parent de1c319 commit 4f999c8

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

src/core/qgsexpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,7 @@ void QgsExpression::setScale( double scale ) { d->mScale = scale; }
29422942

29432943
double QgsExpression::scale() { return d->mScale; }
29442944

2945-
const QString QgsExpression::expression() const
2945+
QString QgsExpression::expression() const
29462946
{
29472947
if ( !d->mExp.isNull() )
29482948
return d->mExp;

src/core/qgsexpression.h

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Possible QVariant value types:
6767
- string
6868
- geometry
6969
70+
Three Value Logic
71+
=================
72+
7073
Similarly to SQL, this class supports three-value logic: true/false/unknown.
7174
Unknown value may be a result of operations with missing data (NULL). Please note
7275
that 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
7578
There is no special (three-value) 'boolean' type: true/false is represented as
7679
1/0 integer, unknown value is represented the same way as NULL values: invalid QVariant.
7780
81+
Performance
82+
===========
83+
7884
For better performance with many evaluations you may first call prepare(fields) function
7985
to 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
8291
type automatically convert the arguments to that type, e.g. sin('2.1') will convert
8392
the argument to a double, length(123) will first convert the number to a string.
8493
Explicit conversion can be achieved with toint, toreal, tostring functions.
@@ -88,15 +97,47 @@ or they can be converted to numeric types.
8897
8998
Arithmetic operators do integer arithmetics if both operands are integer. That is
9099
2+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

93117
Q_NOWARN_DEPRECATED_PUSH
94118
class 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;

src/core/qgsexpressionprivate.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#include "qgsexpression.h"
2424
#include "qgsdistancearea.h"
2525

26+
///@cond
27+
/**
28+
* This class exists only for implicit sharing of QgsExpression
29+
* and is not part of the public API.
30+
* It should be considered an implementation detail.
31+
*/
2632
class QgsExpressionPrivate
2733
{
2834
public:
@@ -62,5 +68,6 @@ class QgsExpressionPrivate
6268

6369
QSharedPointer<QgsDistanceArea> mCalc;
6470
};
71+
///@endcond
6572

6673
#endif // QGSEXPRESSIONPRIVATE_H

0 commit comments

Comments
 (0)