QGIS API Documentation 3.28.14-Firenze (exported)
Loading...
Searching...
No Matches
qgsexpressioncontext.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsexpressioncontext.cpp
3 ------------------------
4 Date : April 2015
5 Copyright : (C) 2015 by Nyall Dawson
6 Email : nyall dot dawson 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
17#include "qgslogger.h"
18#include "qgsxmlutils.h"
19#include "qgsexpression.h"
20
21const QString QgsExpressionContext::EXPR_FIELDS( QStringLiteral( "_fields_" ) );
22const QString QgsExpressionContext::EXPR_ORIGINAL_VALUE( QStringLiteral( "value" ) );
23const QString QgsExpressionContext::EXPR_SYMBOL_COLOR( QStringLiteral( "symbol_color" ) );
24const QString QgsExpressionContext::EXPR_SYMBOL_ANGLE( QStringLiteral( "symbol_angle" ) );
25const QString QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT( QStringLiteral( "geometry_part_count" ) );
26const QString QgsExpressionContext::EXPR_GEOMETRY_PART_NUM( QStringLiteral( "geometry_part_num" ) );
27const QString QgsExpressionContext::EXPR_GEOMETRY_RING_NUM( QStringLiteral( "geometry_ring_num" ) );
28const QString QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT( QStringLiteral( "geometry_point_count" ) );
29const QString QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM( QStringLiteral( "geometry_point_num" ) );
30const QString QgsExpressionContext::EXPR_CLUSTER_SIZE( QStringLiteral( "cluster_size" ) );
31const QString QgsExpressionContext::EXPR_CLUSTER_COLOR( QStringLiteral( "cluster_color" ) );
32
33//
34// QgsExpressionContextScope
35//
36
38 : mName( name )
39{
40
41}
42
44 : mName( other.mName )
45 , mVariables( other.mVariables )
46 , mHasFeature( other.mHasFeature )
47 , mFeature( other.mFeature )
48 , mHasGeometry( other.mHasGeometry )
49 , mGeometry( other.mGeometry )
50 , mHiddenVariables( other.mHiddenVariables )
51{
52 QHash<QString, QgsScopedExpressionFunction * >::const_iterator it = other.mFunctions.constBegin();
53 for ( ; it != other.mFunctions.constEnd(); ++it )
54 {
55 mFunctions.insert( it.key(), it.value()->clone() );
56 }
57}
58
60{
61 mName = other.mName;
62 mVariables = other.mVariables;
63 mHasFeature = other.mHasFeature;
64 mFeature = other.mFeature;
65 mHasGeometry = other.mHasGeometry;
66 mGeometry = other.mGeometry;
67 mHiddenVariables = other.mHiddenVariables;
68
69 qDeleteAll( mFunctions );
70 mFunctions.clear();
71 QHash<QString, QgsScopedExpressionFunction * >::const_iterator it = other.mFunctions.constBegin();
72 for ( ; it != other.mFunctions.constEnd(); ++it )
73 {
74 mFunctions.insert( it.key(), it.value()->clone() );
75 }
76
77 return *this;
78}
79
81{
82 qDeleteAll( mFunctions );
83}
84
85void QgsExpressionContextScope::setVariable( const QString &name, const QVariant &value, bool isStatic )
86{
87 auto it = mVariables.find( name );
88 if ( it != mVariables.end() )
89 {
90 it->value = value;
91 it->isStatic = isStatic;
92 }
93 else
94 {
96 }
97}
98
100{
101 mVariables.insert( variable.name, variable );
102}
103
105{
106 return mVariables.remove( name ) > 0;
107}
108
109bool QgsExpressionContextScope::hasVariable( const QString &name ) const
110{
111 return mVariables.contains( name );
112}
113
114QVariant QgsExpressionContextScope::variable( const QString &name ) const
115{
116 return hasVariable( name ) ? mVariables.value( name ).value : QVariant();
117}
118
120{
121 QStringList names = mVariables.keys();
122
123 if ( hasFeature() )
124 {
125 names.append( QStringLiteral( "feature" ) );
126 names.append( QStringLiteral( "id" ) );
127 names.append( QStringLiteral( "geometry" ) );
128 }
129
130 return names;
131}
132
134{
135 return mHiddenVariables;
136}
137
138void QgsExpressionContextScope::setHiddenVariables( const QStringList &hiddenVariables )
139{
140 mHiddenVariables = hiddenVariables;
141}
142
143void QgsExpressionContextScope::addHiddenVariable( const QString &hiddenVariable )
144{
145 if ( !mHiddenVariables.contains( hiddenVariable ) )
146 mHiddenVariables << hiddenVariable;
147}
148
149void QgsExpressionContextScope::removeHiddenVariable( const QString &hiddenVariable )
150{
151 if ( mHiddenVariables.contains( hiddenVariable ) )
152 mHiddenVariables.removeAt( mHiddenVariables.indexOf( hiddenVariable ) );
153}
154
155
157class QgsExpressionContextVariableCompare
158{
159 public:
160 explicit QgsExpressionContextVariableCompare( const QgsExpressionContextScope &scope )
161 : mScope( scope )
162 { }
163
164 bool operator()( const QString &a, const QString &b ) const
165 {
166 bool aReadOnly = mScope.isReadOnly( a );
167 bool bReadOnly = mScope.isReadOnly( b );
168 if ( aReadOnly != bReadOnly )
169 return aReadOnly;
170 return QString::localeAwareCompare( a, b ) < 0;
171 }
172
173 private:
174 const QgsExpressionContextScope &mScope;
175};
177
179{
180 QStringList allVariables = mVariables.keys();
181 QStringList filtered;
182 const auto constAllVariables = allVariables;
183 for ( const QString &variable : constAllVariables )
184 {
185 if ( variable.startsWith( '_' ) )
186 continue;
187
188 filtered << variable;
189 }
190 QgsExpressionContextVariableCompare cmp( *this );
191 std::sort( filtered.begin(), filtered.end(), cmp );
192
193 return filtered;
194}
195
196bool QgsExpressionContextScope::isReadOnly( const QString &name ) const
197{
198 return hasVariable( name ) ? mVariables.value( name ).readOnly : false;
199}
200
201bool QgsExpressionContextScope::isStatic( const QString &name ) const
202{
203 return hasVariable( name ) ? mVariables.value( name ).isStatic : false;
204}
205
206QString QgsExpressionContextScope::description( const QString &name ) const
207{
208 return hasVariable( name ) ? mVariables.value( name ).description : QString();
209}
210
211bool QgsExpressionContextScope::hasFunction( const QString &name ) const
212{
213 return mFunctions.contains( name );
214}
215
217{
218 return mFunctions.contains( name ) ? mFunctions.value( name ) : nullptr;
219}
220
222{
223 return mFunctions.keys();
224}
225
227{
228 mFunctions.insert( name, function );
229}
230
231
233{
234 addVariable( StaticVariable( QgsExpressionContext::EXPR_FIELDS, QVariant::fromValue( fields ), true ) );
235}
236
237void QgsExpressionContextScope::readXml( const QDomElement &element, const QgsReadWriteContext & )
238{
239 const QDomNodeList variablesNodeList = element.childNodes();
240 for ( int i = 0; i < variablesNodeList.size(); ++i )
241 {
242 const QDomElement variableElement = variablesNodeList.at( i ).toElement();
243 const QString key = variableElement.attribute( QStringLiteral( "name" ) );
244 if ( variableElement.tagName() == QLatin1String( "Variable" ) )
245 {
246 const QVariant value = QgsXmlUtils::readVariant( variableElement.firstChildElement( QStringLiteral( "Option" ) ) );
247 setVariable( key, value );
248 }
249 else
250 addHiddenVariable( key );
251
252 }
253}
254
255bool QgsExpressionContextScope::writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext & ) const
256{
257 for ( auto it = mVariables.constBegin(); it != mVariables.constEnd(); ++it )
258 {
259 QDomElement varElem = document.createElement( QStringLiteral( "Variable" ) );
260 varElem.setAttribute( QStringLiteral( "name" ), it.key() );
261 QDomElement valueElem = QgsXmlUtils::writeVariant( it.value().value, document );
262 varElem.appendChild( valueElem );
263 element.appendChild( varElem );
264 }
265
266 for ( QString hiddenVariable : mHiddenVariables )
267 {
268 QDomElement varElem = document.createElement( QStringLiteral( "HiddenVariable" ) );
269 varElem.setAttribute( QStringLiteral( "name" ), hiddenVariable );
270 element.appendChild( varElem );
271 }
272 return true;
273}
274
275
276//
277// QgsExpressionContext
278//
279
280QgsExpressionContext::QgsExpressionContext( const QList<QgsExpressionContextScope *> &scopes )
281 : mStack( scopes )
282{
283}
284
286{
287 for ( const QgsExpressionContextScope *scope : std::as_const( other.mStack ) )
288 {
289 mStack << new QgsExpressionContextScope( *scope );
290 }
291 mHighlightedVariables = other.mHighlightedVariables;
292 mHighlightedFunctions = other.mHighlightedFunctions;
293 mCachedValues = other.mCachedValues;
294 mFeedback = other.mFeedback;
295}
296
298{
299 if ( this != &other )
300 {
301 qDeleteAll( mStack );
302 // move the stack over
303 mStack = other.mStack;
304 other.mStack.clear();
305
306 mHighlightedVariables = other.mHighlightedVariables;
307 mHighlightedFunctions = other.mHighlightedFunctions;
308 mCachedValues = other.mCachedValues;
309 mFeedback = other.mFeedback;
310 }
311 return *this;
312}
313
315{
316 if ( &other == this )
317 return *this;
318
319 qDeleteAll( mStack );
320 mStack.clear();
321 for ( const QgsExpressionContextScope *scope : std::as_const( other.mStack ) )
322 {
323 mStack << new QgsExpressionContextScope( *scope );
324 }
325 mHighlightedVariables = other.mHighlightedVariables;
326 mHighlightedFunctions = other.mHighlightedFunctions;
327 mCachedValues = other.mCachedValues;
328 mFeedback = other.mFeedback;
329 return *this;
330}
331
333{
334 qDeleteAll( mStack );
335 mStack.clear();
336}
337
338bool QgsExpressionContext::hasVariable( const QString &name ) const
339{
340 const auto constMStack = mStack;
341 for ( const QgsExpressionContextScope *scope : constMStack )
342 {
343 if ( scope->hasVariable( name ) )
344 return true;
345 }
346 return false;
347}
348
349QVariant QgsExpressionContext::variable( const QString &name ) const
350{
352 return scope ? scope->variable( name ) : QVariant();
353}
354
356{
357 QStringList names = variableNames();
358 QVariantMap m;
359 const auto constNames = names;
360 for ( const QString &name : constNames )
361 {
362 m.insert( name, variable( name ) );
363 }
364 return m;
365}
366
367bool QgsExpressionContext::isHighlightedVariable( const QString &name ) const
368{
369 return mHighlightedVariables.contains( name );
370}
371
373{
374 return mHighlightedVariables;
375}
376
377void QgsExpressionContext::setHighlightedVariables( const QStringList &variableNames )
378{
379 mHighlightedVariables = variableNames;
380}
381
382bool QgsExpressionContext::isHighlightedFunction( const QString &name ) const
383{
384 return mHighlightedFunctions.contains( name );
385}
386
387void QgsExpressionContext::setHighlightedFunctions( const QStringList &names )
388{
389 mHighlightedFunctions = names;
390}
391
393{
394 //iterate through stack backwards, so that higher priority variables take precedence
395 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
396 while ( it != mStack.constBegin() )
397 {
398 --it;
399 if ( ( *it )->hasVariable( name ) )
400 return ( *it );
401 }
402 return nullptr;
403}
404
406{
407 //iterate through stack backwards, so that higher priority variables take precedence
408 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
409 while ( it != mStack.constBegin() )
410 {
411 --it;
412 if ( ( *it )->hasVariable( name ) )
413 return ( *it );
414 }
415 return nullptr;
416}
417
419{
420 if ( index < 0 || index >= mStack.count() )
421 return nullptr;
422
423 return mStack.at( index );
424}
425
427{
428 if ( mStack.count() < 1 )
429 return nullptr;
430
431 return mStack.last();
432}
433
435{
436 if ( !scope )
437 return -1;
438
439 return mStack.indexOf( scope );
440}
441
442int QgsExpressionContext::indexOfScope( const QString &scopeName ) const
443{
444 int index = 0;
445 const auto constMStack = mStack;
446 for ( const QgsExpressionContextScope *scope : constMStack )
447 {
448 if ( scope->name() == scopeName )
449 return index;
450
451 index++;
452 }
453 return -1;
454}
455
457{
458 QSet< QString> names;
459 for ( const QgsExpressionContextScope *scope : mStack )
460 {
461 const QStringList variableNames = scope->variableNames();
462 for ( const QString &name : variableNames )
463 names.insert( name );
464 }
465 return QStringList( names.constBegin(), names.constEnd() );
466}
467
469{
470 QStringList allVariables = variableNames();
471 QStringList filtered;
472 const auto constAllVariables = allVariables;
473
474 QStringList hiddenVariables;
475
476 for ( const QgsExpressionContextScope *scope : mStack )
477 {
478 const QStringList scopeHiddenVariables = scope->hiddenVariables();
479 for ( const QString &name : scopeHiddenVariables )
480 hiddenVariables << name ;
481 }
482
483 for ( const QString &variable : constAllVariables )
484 {
485 if ( variable.startsWith( '_' ) ||
486 hiddenVariables.contains( variable ) )
487 continue;
488
489 filtered << variable;
490 }
491
492 filtered.sort();
493 return filtered;
494}
495
496bool QgsExpressionContext::isReadOnly( const QString &name ) const
497{
498 const auto constMStack = mStack;
499 for ( const QgsExpressionContextScope *scope : constMStack )
500 {
501 if ( scope->isReadOnly( name ) )
502 return true;
503 }
504 return false;
505}
506
507QString QgsExpressionContext::description( const QString &name ) const
508{
510 return ( scope && !scope->description( name ).isEmpty() ) ? scope->description( name ) : QgsExpression::variableHelpText( name );
511}
512
513bool QgsExpressionContext::hasFunction( const QString &name ) const
514{
515 const auto constMStack = mStack;
516 for ( const QgsExpressionContextScope *scope : constMStack )
517 {
518 if ( scope->hasFunction( name ) )
519 return true;
520 }
521 return false;
522}
523
525{
526 QSet< QString > result;
527 for ( const QgsExpressionContextScope *scope : mStack )
528 {
529 const QStringList functionNames = scope->functionNames();
530 for ( const QString &name : functionNames )
531 result.insert( name );
532 }
533 QStringList listResult( result.constBegin(), result.constEnd() );
534 listResult.sort();
535 return listResult;
536}
537
539{
540 //iterate through stack backwards, so that higher priority variables take precedence
541 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
542 while ( it != mStack.constBegin() )
543 {
544 --it;
545 if ( ( *it )->hasFunction( name ) )
546 return ( *it )->function( name );
547 }
548 return nullptr;
549}
550
552{
553 return mStack.count();
554}
555
557{
558 mStack.append( scope );
559}
560
561void QgsExpressionContext::appendScopes( const QList<QgsExpressionContextScope *> &scopes )
562{
563 mStack.append( scopes );
564}
565
567{
568 if ( !mStack.isEmpty() )
569 return mStack.takeLast();
570
571 return nullptr;
572}
573
574QList<QgsExpressionContextScope *> QgsExpressionContext::takeScopes()
575{
576 QList<QgsExpressionContextScope *> stack = mStack;
577 mStack.clear();
578 return stack;
579}
580
582{
583 mStack.append( scope );
584 return *this;
585}
586
588{
589 if ( mStack.isEmpty() )
590 mStack.append( new QgsExpressionContextScope() );
591
592 mStack.last()->setFeature( feature );
593}
594
596{
597 for ( const QgsExpressionContextScope *scope : mStack )
598 {
599 if ( scope->hasFeature() )
600 return true;
601 }
602 return false;
603}
604
606{
607 //iterate through stack backwards, so that higher priority variables take precedence
608 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
609 while ( it != mStack.constBegin() )
610 {
611 --it;
612 if ( ( *it )->hasFeature() )
613 return ( *it )->feature();
614 }
615 return QgsFeature();
616}
617
619{
620 if ( mStack.isEmpty() )
621 mStack.append( new QgsExpressionContextScope() );
622
623 mStack.last()->setGeometry( geometry );
624}
625
627{
628 for ( const QgsExpressionContextScope *scope : mStack )
629 {
630 if ( scope->hasGeometry() )
631 return true;
632 }
633 return false;
634}
635
637{
638 //iterate through stack backwards, so that higher priority variables take precedence
639 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
640 while ( it != mStack.constBegin() )
641 {
642 --it;
643 if ( ( *it )->hasGeometry() )
644 return ( *it )->geometry();
645 }
646 return QgsGeometry();
647}
648
650{
651 if ( mStack.isEmpty() )
652 mStack.append( new QgsExpressionContextScope() );
653
654 mStack.last()->setFields( fields );
655}
656
658{
659 return qvariant_cast<QgsFields>( variable( QgsExpressionContext::EXPR_FIELDS ) );
660}
661
663{
664 if ( mStack.isEmpty() )
665 mStack.append( new QgsExpressionContextScope() );
666
668 value, true ) );
669}
670
671void QgsExpressionContext::setCachedValue( const QString &key, const QVariant &value ) const
672{
673 mCachedValues.insert( key, value );
674}
675
676bool QgsExpressionContext::hasCachedValue( const QString &key ) const
677{
678 return mCachedValues.contains( key );
679}
680
681QVariant QgsExpressionContext::cachedValue( const QString &key ) const
682{
683 return mCachedValues.value( key, QVariant() );
684}
685
687{
688 mCachedValues.clear();
689}
690
692{
693 mFeedback = feedback;
694}
695
697{
698 return mFeedback;
699}
Single scope for storing variables and functions for use within a QgsExpressionContext.
bool hasVariable(const QString &name) const
Tests whether a variable with the specified name exists in the scope.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
QString description(const QString &name) const
Returns the translated description for the variable with the specified name (if set).
void setHiddenVariables(const QStringList &hiddenVariables)
Sets the list of variables intended to be hidden in the expression builder dialog and widget.
void addHiddenVariable(const QString &hiddenVariable)
Adds the passed variable to a list of hidden variables that won't be visible in the expression builde...
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads scope variables from an XML element.
QStringList hiddenVariables() const
Returns the list of variables hidden within the scope.
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes scope variables to an XML element.
QgsExpressionFunction * function(const QString &name) const
Retrieves a function from the scope.
QVariant variable(const QString &name) const
Retrieves a variable's value from the scope.
void removeHiddenVariable(const QString &hiddenVariable)
Removes the passed variable from a list of hidden variables.
bool removeVariable(const QString &name)
Removes a variable from the context scope, if found.
bool isReadOnly(const QString &name) const
Tests whether the specified variable is read only and should not be editable by users.
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
bool hasFeature() const
Returns true if the scope has a feature associated with it.
bool hasFunction(const QString &name) const
Tests whether a function with the specified name exists in the scope.
QString name() const
Returns the friendly display name of the context scope.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
bool isStatic(const QString &name) const
Tests whether the variable with the specified name is static and can be cached.
bool hasGeometry() const
Returns true if the scope has a geometry associated with it.
QStringList filteredVariableNames() const
Returns a filtered and sorted list of variable names contained within the scope.
QStringList functionNames() const
Retrieves a list of names of functions contained in the scope.
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
QgsExpressionContextScope & operator=(const QgsExpressionContextScope &other)
QgsExpressionContextScope(const QString &name=QString())
Constructor for QgsExpressionContextScope.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
bool hasFunction(const QString &name) const
Checks whether a specified function is contained in the context.
QString description(const QString &name) const
Returns a translated description string for the variable with specified name.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
QStringList highlightedVariables() const
Returns the current list of variables highlighted within the context.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
QStringList functionNames() const
Retrieves a list of function names contained in the context.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
int indexOfScope(QgsExpressionContextScope *scope) const
Returns the index of the specified scope if it exists within the context.
void setCachedValue(const QString &key, const QVariant &value) const
Sets a value to cache within the expression context.
void clearCachedValues() const
Clears all cached values from the context.
void setHighlightedFunctions(const QStringList &names)
Sets the list of function names intended to be highlighted to the user.
QgsGeometry geometry() const
Convenience function for retrieving the geometry for the context, if set.
bool isHighlightedFunction(const QString &name) const
Returns true if the specified function name is intended to be highlighted to the user.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
QgsExpressionContext & operator=(const QgsExpressionContext &other)
QgsExpressionContext()=default
Constructor for QgsExpressionContext.
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
void setGeometry(const QgsGeometry &geometry)
Convenience function for setting a geometry for the context.
static const QString EXPR_GEOMETRY_RING_NUM
Inbuilt variable name for geometry ring number variable.
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
QgsExpressionContextScope * activeScopeForVariable(const QString &name)
Returns the currently active scope from the context for a specified variable name.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
QList< QgsExpressionContextScope * > scopes()
Returns a list of scopes contained within the stack.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
QList< QgsExpressionContextScope * > takeScopes()
Returns all scopes from this context and remove them, leaving this context without any context.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly by the expression to check if evaluation sh...
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the expression engine to check if expressio...
int scopeCount() const
Returns the number of scopes contained in the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
bool isReadOnly(const QString &name) const
Returns whether a variable is read only, and should not be modifiable by users.
bool hasGeometry() const
Returns true if the context has a geometry associated with it.
QgsExpressionFunction * function(const QString &name) const
Fetches a matching function from the context.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
QVariantMap variablesToMap() const
Returns a map of variable name to value representing all the expression variables contained by the co...
bool hasCachedValue(const QString &key) const
Returns true if the expression context contains a cached value with a matching key.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
QgsExpressionContext & operator<<(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
QStringList variableNames() const
Returns a list of variables names set by all scopes in the context.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QgsExpressionContextScope * scope(int index)
Returns the scope at the specified index within the context.
QVariant cachedValue(const QString &key) const
Returns the matching cached value, if set.
bool hasFeature() const
Returns true if the context has a feature associated with it.
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
A abstract base class for defining QgsExpression functions.
static QString variableHelpText(const QString &variableName)
Returns the help text for a specified variable.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:56
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:45
Container of fields for a vector layer.
Definition qgsfields.h:45
A geometry is the spatial representation of a feature.
The class is used as a container of context for various read/write operations on other objects.
Expression function for use within a QgsExpressionContextScope.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
Single variable definition for use within a QgsExpressionContextScope.