Branch data Line data Source code
1 : : /***************************************************************************
2 : : qgsexpression.h
3 : : -------------------
4 : : begin : August 2011
5 : : copyright : (C) 2011 Martin Dobias
6 : : email : wonder.sk at gmail dot com
7 : : ***************************************************************************
8 : : * *
9 : : * This program is free software; you can redistribute it and/or modify *
10 : : * it under the terms of the GNU General Public License as published by *
11 : : * the Free Software Foundation; either version 2 of the License, or *
12 : : * (at your option) any later version. *
13 : : * *
14 : : ***************************************************************************/
15 : :
16 : : #ifndef QGSEXPRESSION_H
17 : : #define QGSEXPRESSION_H
18 : :
19 : : #include "qgis_core.h"
20 : : #include <QMetaType>
21 : : #include <QStringList>
22 : : #include <QVariant>
23 : : #include <QList>
24 : : #include <QDomDocument>
25 : : #include <QCoreApplication>
26 : : #include <QSet>
27 : : #include <functional>
28 : :
29 : : #include "qgis.h"
30 : : #include "qgsunittypes.h"
31 : : #include "qgsinterval.h"
32 : : #include "qgsexpressionnode.h"
33 : :
34 : : class QgsFeature;
35 : : class QgsGeometry;
36 : : class QgsOgcUtils;
37 : : class QgsVectorLayer;
38 : : class QgsVectorDataProvider;
39 : : class QgsField;
40 : : class QgsFields;
41 : : class QgsDistanceArea;
42 : : class QDomElement;
43 : : class QgsExpressionContext;
44 : : class QgsExpressionPrivate;
45 : : class QgsExpressionFunction;
46 : :
47 : : /**
48 : : * \ingroup core
49 : : * \brief Class for parsing and evaluation of expressions (formerly called "search strings").
50 : : * The expressions try to follow both syntax and semantics of SQL expressions.
51 : :
52 : : Usage:
53 : : \code{.py}
54 : : exp = QgsExpression("gid*2 > 10 and type not in ('D','F')")
55 : : if exp.hasParserError():
56 : : # show error message with parserErrorString() and exit
57 : :
58 : : result = exp.evaluate(feature, fields)
59 : : if exp.hasEvalError():
60 : : # show error message with evalErrorString()
61 : : else:
62 : : # examine the result
63 : : \endcode
64 : :
65 : : \section value_logic Three Value Logic
66 : :
67 : : Similarly to SQL, this class supports three-value logic: true/false/unknown.
68 : : Unknown value may be a result of operations with missing data (NULL). Please note
69 : : that NULL is different value than zero or an empty string. For example
70 : : 3 > NULL returns unknown.
71 : :
72 : : There is no special (three-value) 'boolean' type: true/false is represented as
73 : : 1/0 integer, unknown value is represented the same way as NULL values: NULL QVariant.
74 : :
75 : : \section performance Performance
76 : :
77 : : For better performance with many evaluations you may first call prepare(fields) function
78 : : to find out indices of columns and then repeatedly call evaluate(feature).
79 : :
80 : : \section type_conversion Type conversion
81 : :
82 : : Operators and functions that expect arguments to be of a particular
83 : : type automatically convert the arguments to that type, e.g. sin('2.1') will convert
84 : : the argument to a double, length(123) will first convert the number to a string.
85 : : Explicit conversion can be achieved with to_int, to_real, to_string functions.
86 : : If implicit or explicit conversion is invalid, the evaluation returns an error.
87 : : Comparison operators do numeric comparison in case both operators are numeric (int/double)
88 : : or they can be converted to numeric types.
89 : :
90 : : \section implicit_sharing Implicit sharing
91 : :
92 : : This class is implicitly shared, copying has a very low overhead.
93 : : It is normally preferable to call `QgsExpression( otherExpression )` instead of
94 : : `QgsExpression( otherExpression.expression() )`. A deep copy will only be made
95 : : when prepare() is called. For usage this means mainly, that you should
96 : : normally keep an unprepared master copy of a QgsExpression and whenever using it
97 : : with a particular QgsFeatureIterator copy it just before and prepare it using the
98 : : same context as the iterator.
99 : :
100 : : Implicit sharing was added in 2.14
101 : :
102 : : */
103 : :
104 : : class CORE_EXPORT QgsExpression
105 : : {
106 : 0 : Q_DECLARE_TR_FUNCTIONS( QgsExpression )
107 : : public:
108 : :
109 : : /**
110 : : * Details about any parser errors that were found when parsing the expression.
111 : : * \since QGIS 3.0
112 : : */
113 : 0 : struct CORE_EXPORT ParserError
114 : : {
115 : : enum ParserErrorType
116 : : {
117 : : Unknown = 0, //!< Unknown error type.
118 : : FunctionUnknown = 1, //!< Function was unknown.
119 : : FunctionWrongArgs = 2, //!< Function was called with the wrong number of args.
120 : : FunctionInvalidParams = 3, //!< Function was called with invalid args.
121 : : FunctionNamedArgsError = 4 //!< Non named function arg used after named arg.
122 : : };
123 : :
124 : : /**
125 : : * The type of parser error that was found.
126 : : */
127 : 0 : ParserErrorType errorType = ParserErrorType::Unknown;
128 : :
129 : : /**
130 : : * The message for the error at this location.
131 : : */
132 : : QString errorMsg;
133 : :
134 : : /**
135 : : * The first line that contained the error in the parser.
136 : : * Depending on the error sometimes this doesn't mean anything.
137 : : */
138 : 0 : int firstLine = 0;
139 : :
140 : : /**
141 : : * The first column that contained the error in the parser.
142 : : * Depending on the error sometimes this doesn't mean anything.
143 : : */
144 : 0 : int firstColumn = 0;
145 : :
146 : : /**
147 : : * The last line that contained the error in the parser.
148 : : */
149 : 0 : int lastLine = 0;
150 : :
151 : : /**
152 : : * The last column that contained the error in the parser.
153 : : */
154 : 0 : int lastColumn = 0;
155 : : };
156 : :
157 : : /**
158 : : * Creates a new expression based on the provided string.
159 : : * The string will immediately be parsed. For optimization
160 : : * prepare() should always be called before every
161 : : * loop in which this expression is used.
162 : : */
163 : : QgsExpression( const QString &expr );
164 : :
165 : : /**
166 : : * Create a copy of this expression. This is preferred
167 : : * over recreating an expression from a string since
168 : : * it does not need to be re-parsed.
169 : : */
170 : : QgsExpression( const QgsExpression &other );
171 : :
172 : : /**
173 : : * Create a copy of this expression. This is preferred
174 : : * over recreating an expression from a string since
175 : : * it does not need to be re-parsed.
176 : : */
177 : : QgsExpression &operator=( const QgsExpression &other );
178 : :
179 : : /**
180 : : * Automatically convert this expression to a string where requested.
181 : : *
182 : : * \since QGIS 3.0
183 : : */
184 : : operator QString() const SIP_SKIP;
185 : :
186 : : /**
187 : : * Create an empty expression.
188 : : *
189 : : * \since QGIS 3.0
190 : : */
191 : : QgsExpression();
192 : :
193 : : ~QgsExpression();
194 : :
195 : : /**
196 : : * Compares two expressions. The operator returns TRUE
197 : : * if the expression string is equal.
198 : : *
199 : : * \since QGIS 3.0
200 : : */
201 : : bool operator==( const QgsExpression &other ) const;
202 : :
203 : : /**
204 : : * Checks if this expression is valid.
205 : : * A valid expression could be parsed but does not necessarily evaluate properly.
206 : : *
207 : : * \since QGIS 3.0
208 : : */
209 : : bool isValid() const;
210 : :
211 : : //! Returns TRUE if an error occurred when parsing the input expression
212 : : bool hasParserError() const;
213 : : //! Returns parser error
214 : : QString parserErrorString() const;
215 : :
216 : : /**
217 : : * Returns parser error details including location of error.
218 : : * \since QGIS 3.0
219 : : */
220 : : QList<QgsExpression::ParserError> parserErrors() const;
221 : :
222 : : /**
223 : : * Returns the root node of the expression.
224 : : *
225 : : * The root node is NULLPTR if parsing has failed.
226 : : */
227 : : const QgsExpressionNode *rootNode() const;
228 : :
229 : : /**
230 : : * Gets the expression ready for evaluation - find out column indexes.
231 : : * \param context context for preparing expression
232 : : * \since QGIS 2.12
233 : : */
234 : : bool prepare( const QgsExpressionContext *context );
235 : :
236 : : /**
237 : : * Gets list of columns referenced by the expression.
238 : : *
239 : : * \note If the returned list contains the QgsFeatureRequest::AllAttributes constant then
240 : : * all attributes from the layer are required for evaluation of the expression.
241 : : * QgsFeatureRequest::setSubsetOfAttributes automatically handles this case.
242 : : *
243 : : * \warning If the expression has been prepared via a call to QgsExpression::prepare(),
244 : : * or a call to QgsExpressionNode::prepare() for a node has been made, then parts of
245 : : * the expression may have been determined to evaluate to a static pre-calculatable value.
246 : : * In this case the results will omit attribute indices which are used by these
247 : : * pre-calculated nodes, regardless of their actual referenced columns.
248 : : * If you are seeking to use these functions to introspect an expression you must
249 : : * take care to do this with an unprepared expression.
250 : : *
251 : : * \see referencedAttributeIndexes()
252 : : */
253 : : QSet<QString> referencedColumns() const;
254 : :
255 : : /**
256 : : * Returns a list of all variables which are used in this expression.
257 : : * If the list contains a NULL QString, there is a variable name used
258 : : * which is determined at runtime.
259 : : *
260 : : * \note In contrast to the referencedColumns() function this method
261 : : * is not affected by any previous calls to QgsExpression::prepare(),
262 : : * or QgsExpressionNode::prepare().
263 : : *
264 : : * \since QGIS 3.0
265 : : */
266 : : QSet<QString> referencedVariables() const;
267 : :
268 : : /**
269 : : * Returns a list of the names of all functions which are used in this expression.
270 : : *
271 : : * \note In contrast to the referencedColumns() function this method
272 : : * is not affected by any previous calls to QgsExpression::prepare(),
273 : : * or QgsExpressionNode::prepare().
274 : : *
275 : : * \since QGIS 3.2
276 : : */
277 : : QSet<QString> referencedFunctions() const;
278 : :
279 : : #ifndef SIP_RUN
280 : :
281 : : /**
282 : : * Returns a list of all nodes which are used in this expression
283 : : *
284 : : * \note not available in Python bindings
285 : : * \since QGIS 3.2
286 : : */
287 : : QList<const QgsExpressionNode *> nodes( ) const;
288 : :
289 : : /**
290 : : * Returns a list of all nodes of the given class which are used in this expression
291 : : *
292 : : * \note not available in Python bindings
293 : : * \since QGIS 3.2
294 : : */
295 : : template <class T>
296 : 0 : QList<const T *> findNodes( ) const
297 : : {
298 : 0 : QList<const T *> lst;
299 : 0 : const QList<const QgsExpressionNode *> allNodes( nodes() );
300 : 0 : for ( const auto &node : allNodes )
301 : : {
302 : 0 : const T *n = dynamic_cast<const T *>( node );
303 : 0 : if ( n )
304 : 0 : lst << n;
305 : : }
306 : 0 : return lst;
307 : 0 : }
308 : : #endif
309 : :
310 : : /**
311 : : * Returns a list of field name indexes obtained from the provided fields.
312 : : *
313 : : * \warning If the expression has been prepared via a call to QgsExpression::prepare(),
314 : : * or a call to QgsExpressionNode::prepare() for a node has been made, then parts of
315 : : * the expression may have been determined to evaluate to a static pre-calculatable value.
316 : : * In this case the results will omit attribute indices which are used by these
317 : : * pre-calculated nodes, regardless of their actual referenced columns.
318 : : * If you are seeking to use these functions to introspect an expression you must
319 : : * take care to do this with an unprepared expression.
320 : : *
321 : : * \since QGIS 3.0
322 : : */
323 : : QSet<int> referencedAttributeIndexes( const QgsFields &fields ) const;
324 : :
325 : : //! Returns TRUE if the expression uses feature geometry for some computation
326 : : bool needsGeometry() const;
327 : :
328 : : // evaluation
329 : :
330 : : /**
331 : : * Evaluate the feature and return the result.
332 : : * \note this method does not expect that prepare() has been called on this instance
333 : : * \since QGIS 2.12
334 : : */
335 : : QVariant evaluate();
336 : :
337 : : /**
338 : : * Evaluate the expression against the specified context and return the result.
339 : : * \param context context for evaluating expression
340 : : * \note prepare() should be called before calling this method.
341 : : * \since QGIS 2.12
342 : : */
343 : : QVariant evaluate( const QgsExpressionContext *context );
344 : :
345 : : //! Returns TRUE if an error occurred when evaluating last input
346 : : bool hasEvalError() const;
347 : : //! Returns evaluation error
348 : : QString evalErrorString() const;
349 : : //! Sets evaluation error (used internally by evaluation functions)
350 : : void setEvalErrorString( const QString &str );
351 : :
352 : : /**
353 : : * Checks whether an expression consists only of a single field reference
354 : : * \since QGIS 2.9
355 : : */
356 : : bool isField() const;
357 : :
358 : : /**
359 : : * Tests whether a string is a valid expression.
360 : : * \param text string to test
361 : : * \param context optional expression context
362 : : * \param errorMessage will be filled with any error message from the validation
363 : : * \returns TRUE if string is a valid expression
364 : : * \since QGIS 2.12
365 : : */
366 : : static bool checkExpression( const QString &text, const QgsExpressionContext *context, QString &errorMessage SIP_OUT );
367 : :
368 : : /**
369 : : * Set the expression string, will reset the whole internal structure.
370 : : *
371 : : * \since QGIS 3.0
372 : : */
373 : : void setExpression( const QString &expression );
374 : :
375 : : /**
376 : : * Returns the original, unmodified expression string.
377 : : * If there was none supplied because it was constructed by sole
378 : : * API calls, dump() will be used to create one instead.
379 : : */
380 : : QString expression() const;
381 : :
382 : : /**
383 : : * Returns an expression string, constructed from the internal
384 : : * abstract syntax tree. This does not contain any nice whitespace
385 : : * formatting or comments. In general it is preferable to use
386 : : * expression() instead.
387 : : */
388 : : QString dump() const;
389 : :
390 : : /**
391 : : * Returns calculator used for distance and area calculations
392 : : * (used by $length, $area and $perimeter functions only)
393 : : * \see setGeomCalculator()
394 : : * \see distanceUnits()
395 : : * \see areaUnits()
396 : : */
397 : : QgsDistanceArea *geomCalculator();
398 : :
399 : : /**
400 : : * Sets the geometry calculator used for distance and area calculations in expressions.
401 : : * (used by $length, $area and $perimeter functions only).
402 : : * If the geometry calculator is set to NULLPTR (default), prepare() will read variables
403 : : * from the expression context ("project_ellipsoid", "_project_transform_context" and
404 : : * "_layer_crs") to build a geometry calculator.
405 : : * If these variables does not exist and if setGeomCalculator() is not called,
406 : : * all distance and area calculations are performed using simple
407 : : * Cartesian methods (ie no ellipsoidal calculations).
408 : : * \param calc geometry calculator. Ownership is not transferred. Set to NULLPTR to force
409 : : * Cartesian calculations.
410 : : * \see geomCalculator()
411 : : */
412 : : void setGeomCalculator( const QgsDistanceArea *calc );
413 : :
414 : : /**
415 : : * Returns the desired distance units for calculations involving geomCalculator(), e.g., "$length" and "$perimeter".
416 : : * \note distances are only converted when a geomCalculator() has been set
417 : : * \see setDistanceUnits()
418 : : * \see areaUnits()
419 : : * \since QGIS 2.14
420 : : */
421 : : QgsUnitTypes::DistanceUnit distanceUnits() const;
422 : :
423 : : /**
424 : : * Sets the desired distance units for calculations involving geomCalculator(), e.g., "$length" and "$perimeter".
425 : : * If distance units are set to QgsUnitTypes::DistanceUnknownUnit (default), prepare() will read
426 : : * variables from the expression context ("project_distance_units") to determine distance units.
427 : : * \note distances are only converted when a geomCalculator() has been set
428 : : * \see distanceUnits()
429 : : * \see setAreaUnits()
430 : : * \since QGIS 2.14
431 : : */
432 : : void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
433 : :
434 : : /**
435 : : * Returns the desired areal units for calculations involving geomCalculator(), e.g., "$area".
436 : : * \note areas are only converted when a geomCalculator() has been set
437 : : * \see setAreaUnits()
438 : : * \see distanceUnits()
439 : : * \since QGIS 2.14
440 : : */
441 : : QgsUnitTypes::AreaUnit areaUnits() const;
442 : :
443 : : /**
444 : : * Sets the desired areal units for calculations involving geomCalculator(), e.g., "$area".
445 : : * If distance units are set to QgsUnitTypes::AreaUnknownUnit (default), prepare() will read
446 : : * variables from the expression context ("project_distance_units") to determine distance units.
447 : : * \note areas are only converted when a geomCalculator() has been set
448 : : * \see areaUnits()
449 : : * \see setDistanceUnits()
450 : : * \since QGIS 2.14
451 : : */
452 : : void setAreaUnits( QgsUnitTypes::AreaUnit unit );
453 : :
454 : : /**
455 : : * This function replaces each expression between [% and %]
456 : : * in the string with the result of its evaluation with the specified context
457 : : *
458 : : * Additional substitutions can be passed through the substitutionMap parameter
459 : : * \param action The source string in which placeholders should be replaced.
460 : : * \param context Expression context
461 : : * \param distanceArea Optional QgsDistanceArea. If specified, the QgsDistanceArea is used for distance
462 : : * and area conversion
463 : : * \since QGIS 2.12
464 : : */
465 : : static QString replaceExpressionText( const QString &action, const QgsExpressionContext *context,
466 : : const QgsDistanceArea *distanceArea = nullptr );
467 : :
468 : : /**
469 : : * This function returns variables in each expression between [% and %].
470 : : *
471 : : * \param text The source string in which variables should be searched.
472 : : *
473 : : * \since QGIS 3.2
474 : : */
475 : : static QSet<QString> referencedVariables( const QString &text );
476 : :
477 : : /**
478 : : * Attempts to evaluate a text string as an expression to a resultant double
479 : : * value.
480 : : * \param text text to evaluate as expression
481 : : * \param fallbackValue value to return if text can not be evaluated as a double
482 : : * \returns evaluated double value, or fallback value
483 : : * \note this method is inefficient for bulk evaluation of expressions, it is intended
484 : : * for one-off evaluations only.
485 : : * \since QGIS 2.7
486 : : */
487 : : static double evaluateToDouble( const QString &text, double fallbackValue );
488 : :
489 : : enum SpatialOperator
490 : : {
491 : : soBbox,
492 : : soIntersects,
493 : : soContains,
494 : : soCrosses,
495 : : soEquals,
496 : : soDisjoint,
497 : : soOverlaps,
498 : : soTouches,
499 : : soWithin,
500 : : };
501 : :
502 : : static const QList<QgsExpressionFunction *> &Functions();
503 : :
504 : : static const QStringList &BuiltinFunctions();
505 : :
506 : : /**
507 : : * Registers a function to the expression engine. This is required to allow expressions to utilize the function.
508 : : * \param function function to register
509 : : * \param transferOwnership set to TRUE to transfer ownership of function to expression engine
510 : : * \returns TRUE on successful registration
511 : : * \see unregisterFunction
512 : : */
513 : : static bool registerFunction( QgsExpressionFunction *function, bool transferOwnership = false );
514 : :
515 : : /**
516 : : * Unregisters a function from the expression engine. The function will no longer be usable in expressions.
517 : : * \param name function name
518 : : * \see registerFunction
519 : : */
520 : : static bool unregisterFunction( const QString &name );
521 : :
522 : : /**
523 : : * Deletes all registered functions whose ownership have been transferred to the expression engine.
524 : : * \since QGIS 2.12
525 : : */
526 : : static void cleanRegisteredFunctions();
527 : :
528 : : //! tells whether the identifier is a name of existing function
529 : : static bool isFunctionName( const QString &name );
530 : :
531 : : //! Returns index of the function in Functions array
532 : : static int functionIndex( const QString &name );
533 : :
534 : : /**
535 : : * Returns the number of functions defined in the parser
536 : : * \returns The number of function defined in the parser.
537 : : */
538 : : static int functionCount();
539 : :
540 : : /**
541 : : * Returns a quoted column reference (in double quotes)
542 : : * \see quotedString()
543 : : * \see quotedValue()
544 : : */
545 : : static QString quotedColumnRef( QString name );
546 : :
547 : : /**
548 : : * Returns a quoted version of a string (in single quotes)
549 : : * \see quotedValue()
550 : : * \see quotedColumnRef()
551 : : */
552 : : static QString quotedString( QString text );
553 : :
554 : : /**
555 : : * Returns a string representation of a literal value, including appropriate
556 : : * quotations where required.
557 : : * \param value value to convert to a string representation
558 : : * \see quotedString()
559 : : * \see quotedColumnRef()
560 : : * \since QGIS 2.14
561 : : */
562 : : static QString quotedValue( const QVariant &value );
563 : :
564 : : /**
565 : : * Returns a string representation of a literal value, including appropriate
566 : : * quotations where required.
567 : : * \param value value to convert to a string representation
568 : : * \param type value type
569 : : * \see quotedString()
570 : : * \see quotedColumnRef()
571 : : * \since QGIS 2.14
572 : : */
573 : : static QString quotedValue( const QVariant &value, QVariant::Type type );
574 : :
575 : : //////
576 : :
577 : : /**
578 : : * Returns the help text for a specified function.
579 : : * \param name function name
580 : : * \see variableHelpText()
581 : : * \see formatVariableHelp()
582 : : */
583 : : static QString helpText( QString name );
584 : :
585 : : /**
586 : : * Returns a string list of search tags for a specified function.
587 : : * \param name function name
588 : : * \since QGIS 3.12
589 : : */
590 : : static QStringList tags( const QString &name );
591 : :
592 : : /**
593 : : * Returns the help text for a specified variable.
594 : : * \param variableName name of variable
595 : : * \see helpText()
596 : : * \since QGIS 2.12
597 : : */
598 : : static QString variableHelpText( const QString &variableName );
599 : :
600 : : /**
601 : : * Returns formatted help text for a variable.
602 : : * \param description translated description of variable
603 : : * \param showValue set to TRUE to include current value of variable in help text
604 : : * \param value current value of variable to show in help text
605 : : * \see helpText()
606 : : * \see variableHelpText()
607 : : * \since QGIS 3.0
608 : : */
609 : : static QString formatVariableHelp( const QString &description, bool showValue = true, const QVariant &value = QVariant() );
610 : :
611 : : /**
612 : : * Returns the translated name for a function group.
613 : : * \param group untranslated group name
614 : : */
615 : : static QString group( const QString &group );
616 : :
617 : : /**
618 : : * Formats an expression result for friendly display to the user. Truncates the result to a sensible
619 : : * length, and presents text representations of non numeric/text types (e.g., geometries and features).
620 : : * \param value expression result to format
621 : : * \param htmlOutput set to TRUE to allow HTML formatting, or FALSE for plain text output
622 : : * \param maximumPreviewLength define the maximum character length of the preview
623 : : * \returns formatted string, may contain HTML formatting characters if \a htmlOutput is TRUE
624 : : * \since QGIS 2.14
625 : : */
626 : : static QString formatPreviewString( const QVariant &value, bool htmlOutput = true, int maximumPreviewLength = 60 );
627 : :
628 : : /**
629 : : * Create an expression allowing to evaluate if a field is equal to a
630 : : * value. The value may be null.
631 : : * \param fieldName the name of the field
632 : : * \param value the value of the field
633 : : * \returns the expression to evaluate field equality
634 : : * \since QGIS 3.0
635 : : */
636 : : static QString createFieldEqualityExpression( const QString &fieldName, const QVariant &value );
637 : :
638 : : /**
639 : : * Returns TRUE if the given \a expression is a simple "field=value" type expression.
640 : : *
641 : : * \param expression expression to test
642 : : * \param field will be set to the field name if the expression is a field equality expression
643 : : * \param value will be set to the value if the expression is a field equality expression
644 : : * \returns TRUE if the expression is a field equality expression
645 : : *
646 : : * \since QGIS 3.18
647 : : */
648 : : static bool isFieldEqualityExpression( const QString &expression, QString &field SIP_OUT, QVariant &value SIP_OUT );
649 : :
650 : : /**
651 : : * Attempts to reduce a list of expressions to a single "field IN (val1, val2, ... )" type expression.
652 : : *
653 : : * This will only be possible if all the input expressions form simple "field=value" OR "field IN (value1, value2)" expressions, and all
654 : : * reference the same field name.
655 : : *
656 : : * Returns TRUE if the given \a expressions could be converted to an IN type expression.
657 : : *
658 : : * \param expressions expressions to test
659 : : * \param result will be set to the calculated "field IN (...)" expression, wherever possible
660 : : * \returns TRUE if the expression was converted to a field IN type expression
661 : : *
662 : : * \since QGIS 3.18
663 : : */
664 : : static bool attemptReduceToInClause( const QStringList &expressions, QString &result SIP_OUT );
665 : :
666 : : #ifdef SIP_RUN
667 : : SIP_PYOBJECT __repr__();
668 : : % MethodCode
669 : : QString str = QStringLiteral( "<QgsExpression: '%1'>" ).arg( sipCpp->expression() );
670 : : sipRes = PyUnicode_FromString( str.toUtf8().constData() );
671 : : % End
672 : : #endif
673 : :
674 : : private:
675 : : void initGeomCalculator( const QgsExpressionContext *context );
676 : :
677 : : /**
678 : : * Helper for implicit sharing. When called will create
679 : : * a new deep copy of this expression.
680 : : *
681 : : * \note not available in Python bindings
682 : : */
683 : : void detach() SIP_SKIP;
684 : :
685 : : QgsExpressionPrivate *d = nullptr;
686 : :
687 : : //! \note not available in Python bindings
688 : : static void initFunctionHelp() SIP_SKIP;
689 : : //! \note not available in Python bindings
690 : : static void initVariableHelp() SIP_SKIP;
691 : :
692 : : friend class QgsOgcUtils;
693 : : };
694 : :
695 : 0 : Q_DECLARE_METATYPE( QgsExpression )
696 : :
697 : : #endif // QGSEXPRESSION_H
|