19 #include "qgsexpression.h" 20 #include "qgsexpressionfunction.h" 62 : mName( other.mName )
63 , mVariables( other.mVariables )
64 , mHasFeature( other.mHasFeature )
65 , mFeature( other.mFeature )
67 QHash<QString, QgsScopedExpressionFunction * >::const_iterator it = other.mFunctions.constBegin();
68 for ( ; it != other.mFunctions.constEnd(); ++it )
70 mFunctions.insert( it.key(), it.value()->clone() );
77 mVariables = other.mVariables;
78 mHasFeature = other.mHasFeature;
79 mFeature = other.mFeature;
81 qDeleteAll( mFunctions );
83 QHash<QString, QgsScopedExpressionFunction * >::const_iterator it = other.mFunctions.constBegin();
84 for ( ; it != other.mFunctions.constEnd(); ++it )
86 mFunctions.insert( it.key(), it.value()->clone() );
94 qDeleteAll( mFunctions );
99 if ( mVariables.contains( name ) )
102 existing.
value = value;
114 mVariables.insert( variable.
name, variable );
119 return mVariables.remove( name ) > 0;
124 return mVariables.contains( name );
129 return hasVariable( name ) ? mVariables.value( name ).value : QVariant();
134 QStringList names = mVariables.keys();
138 bool QgsExpressionContextScope::variableNameSort(
const QString &a,
const QString &b )
140 return QString::localeAwareCompare( a, b ) < 0;
144 class QgsExpressionContextVariableCompare
151 bool operator()(
const QString &a,
const QString &b )
const 153 bool aReadOnly = mScope.isReadOnly( a );
154 bool bReadOnly = mScope.isReadOnly( b );
155 if ( aReadOnly != bReadOnly )
157 return QString::localeAwareCompare( a, b ) < 0;
167 QStringList allVariables = mVariables.keys();
168 QStringList filtered;
169 Q_FOREACH (
const QString &
variable, allVariables )
171 if ( variable.startsWith(
'_' ) )
176 QgsExpressionContextVariableCompare cmp( *
this );
177 std::sort( filtered.begin(), filtered.end(), cmp );
184 return hasVariable( name ) ? mVariables.value( name ).readOnly :
false;
189 return hasVariable( name ) ? mVariables.value( name ).isStatic :
false;
194 return hasVariable( name ) ? mVariables.value( name ).description : QString();
199 return mFunctions.contains( name );
204 return mFunctions.contains( name ) ? mFunctions.value( name ) :
nullptr;
209 return mFunctions.keys();
214 mFunctions.insert( name,
function );
239 mHighlightedVariables = other.mHighlightedVariables;
240 mCachedValues = other.mCachedValues;
245 if (
this != &other )
247 qDeleteAll( mStack );
249 mStack = other.mStack;
250 other.mStack.clear();
252 mHighlightedVariables = other.mHighlightedVariables;
253 mCachedValues = other.mCachedValues;
260 qDeleteAll( mStack );
266 mHighlightedVariables = other.mHighlightedVariables;
267 mCachedValues = other.mCachedValues;
273 qDeleteAll( mStack );
290 return scope ? scope->
variable( name ) : QVariant();
297 Q_FOREACH (
const QString &name, names )
306 return mHighlightedVariables.contains( name );
317 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
318 while ( it != mStack.constBegin() )
321 if ( ( *it )->hasVariable( name ) )
330 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
331 while ( it != mStack.constBegin() )
334 if ( ( *it )->hasVariable( name ) )
342 if ( index < 0 || index >= mStack.count() )
345 return mStack.at( index );
350 if ( mStack.count() < 1 )
353 return mStack.last();
361 return mStack.indexOf( scope );
369 if ( scope->
name() == scopeName )
384 return names.toSet().toList();
390 QStringList filtered;
391 Q_FOREACH (
const QString &
variable, allVariables )
393 if ( variable.startsWith(
'_' ) )
416 return ( scope && !scope->
description( name ).isEmpty() ) ? scope->
description( name ) : QgsExpression::variableHelpText( name );
436 result = result.toSet().toList();
444 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
445 while ( it != mStack.constBegin() )
448 if ( ( *it )->hasFunction( name ) )
449 return ( *it )->function( name );
456 return mStack.count();
461 mStack.append( scope );
466 mStack.append( scopes );
471 if ( !mStack.isEmpty() )
472 return mStack.takeLast();
479 QList<QgsExpressionContextScope *> stack = mStack;
486 mStack.append( scope );
492 if ( mStack.isEmpty() )
495 mStack.last()->setFeature( feature );
511 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
512 while ( it != mStack.constBegin() )
515 if ( ( *it )->hasFeature() )
516 return ( *it )->feature();
523 if ( mStack.isEmpty() )
526 mStack.last()->setFields( fields );
536 if ( mStack.isEmpty() )
545 mCachedValues.insert( key, value );
550 return mCachedValues.contains( key );
555 return mCachedValues.value( key, QVariant() );
560 mCachedValues.clear();
574 for ( QVariantMap::const_iterator it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
606 if ( vars.remove( name ) )
616 GetNamedProjectColor(
const QgsProject *project )
618 , mProject( project )
624 QStringList colorStrings = project->
readListEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Colors" ) );
625 QStringList colorLabels = project->
readListEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Labels" ) );
629 for ( QStringList::iterator it = colorStrings.begin();
630 it != colorStrings.end(); ++it )
634 if ( colorLabels.length() > colorIndex )
636 label = colorLabels.at( colorIndex );
639 mColors.insert( label.toLower(), color );
644 QVariant func(
const QVariantList &values,
const QgsExpressionContext *, QgsExpression *,
const QgsExpressionNodeFunction * )
override 646 QString colorName = values.at( 0 ).toString().toLower();
647 if ( mColors.contains( colorName ) )
649 return QStringLiteral(
"%1,%2,%3" ).arg( mColors.value( colorName ).red() ).arg( mColors.value( colorName ).green() ).arg( mColors.value( colorName ).blue() );
657 return new GetNamedProjectColor( mProject );
663 QHash< QString, QColor > mColors;
670 GetLayoutItemVariables(
const QgsLayout *c )
671 :
QgsScopedExpressionFunction( QStringLiteral(
"item_variables" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral(
"id" ) ), QStringLiteral(
"Layout" ) )
675 QVariant func(
const QVariantList &values,
const QgsExpressionContext *, QgsExpression *,
const QgsExpressionNodeFunction * )
override 680 QString
id = values.at( 0 ).toString().toLower();
693 return new GetLayoutItemVariables( mLayout );
705 GetLayerVisibility(
const QList<QgsMapLayer *> &layers )
706 :
QgsScopedExpressionFunction( QStringLiteral(
"is_layer_visible" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral(
"id" ) ), QStringLiteral(
"General" ) )
710 QVariant func(
const QVariantList &values,
const QgsExpressionContext *, QgsExpression *,
const QgsExpressionNodeFunction * )
override 712 if ( mLayers.isEmpty() )
714 return QVariant(
false );
717 QgsMapLayer *layer = _qgis_findLayer( mLayers, values.at( 0 ).toString() );
720 return QVariant(
true );
724 return QVariant(
false );
730 return new GetLayerVisibility( mLayers );
735 const QList<QgsMapLayer *> mLayers;
742 GetProcessingParameterValue(
const QVariantMap ¶ms )
743 :
QgsScopedExpressionFunction( QStringLiteral(
"parameter" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral(
"name" ) ), QStringLiteral(
"Processing" ) )
747 QVariant func(
const QVariantList &values,
const QgsExpressionContext *, QgsExpression *,
const QgsExpressionNodeFunction * )
override 749 return mParams.value( values.at( 0 ).toString() );
754 return new GetProcessingParameterValue( mParams );
759 const QVariantMap mParams;
774 QVariantMap::const_iterator it = vars.constBegin();
776 for ( ; it != vars.constEnd(); ++it )
790 scope->
addFunction( QStringLiteral(
"project_color" ),
new GetNamedProjectColor( project ) );
801 vars.insert( name, value );
822 if ( vars.remove( name ) )
835 QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
838 Q_FOREACH (
const QString &variableName, variableNames )
840 if ( varIndex >= variableValues.length() )
845 QVariant varValue = variableValues.at( varIndex );
847 scope->
setVariable( variableName, varValue,
true );
869 QList<QgsExpressionContextScope *>
scopes;
870 scopes << globalScope();
874 scopes << projectScope( project );
877 scopes << layerScope( layer );
888 QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
890 variableNames << name;
891 variableValues << value.toString();
903 QStringList variableValues;
905 QVariantMap::const_iterator it = variables.constBegin();
906 for ( ; it != variables.constEnd(); ++it )
908 variableNames << it.key();
909 variableValues << it.value().toString();
938 scope->
addFunction( QStringLiteral(
"is_layer_visible" ),
new GetLayerVisibility( mapSettings.
layers() ) );
947 QVariantList matchList;
951 QVariantMap matchMap;
953 matchMap.insert( QStringLiteral(
"valid" ), match.isValid() );
954 matchMap.insert( QStringLiteral(
"layer" ), QVariant::fromValue<QgsWeakMapLayerPointer>(
QgsWeakMapLayerPointer( match.layer() ) ) );
955 matchMap.insert( QStringLiteral(
"feature_id" ), match.featureId() );
956 matchMap.insert( QStringLiteral(
"vertex_index" ), match.vertexIndex() );
957 matchMap.insert( QStringLiteral(
"distance" ), match.distance() );
959 matchList.append( matchMap );
978 angle = markerSymbol->
angle();
989 return scope.release();
993 QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
996 Q_FOREACH (
const QString &variableName, variableNames )
998 if ( varIndex >= variableValues.length() )
1003 QVariant varValue = variableValues.at( varIndex );
1005 scope->setVariable( variableName, varValue );
1022 scope->addFunction( QStringLiteral(
"item_variables" ),
new GetLayoutItemVariables( layout ) );
1034 scope->setFeature( atlasFeature );
1040 return scope.release();
1050 QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
1052 variableNames << name;
1053 variableValues << value.toString();
1056 layout->
setCustomProperty( QStringLiteral(
"variableValues" ), variableValues );
1065 QStringList variableValues;
1067 QVariantMap::const_iterator it = variables.constBegin();
1068 for ( ; it != variables.constEnd(); ++it )
1070 variableNames << it.key();
1071 variableValues << it.value().toString();
1075 layout->
setCustomProperty( QStringLiteral(
"variableValues" ), variableValues );
1125 const QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
1128 for (
const QString &variableName : variableNames )
1130 if ( varIndex >= variableValues.length() )
1135 QVariant varValue = variableValues.at( varIndex );
1171 QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
1173 variableNames << name;
1174 variableValues << value.toString();
1186 QStringList variableValues;
1188 QVariantMap::const_iterator it = variables.constBegin();
1189 for ( ; it != variables.constEnd(); ++it )
1191 variableNames << it.key();
1192 variableValues << it.value().toString();
1210 Q_UNUSED( context );
1214 return scope.release();
1219 scope->addFunction( QStringLiteral(
"parameter" ),
new GetProcessingParameterValue( parameters ) );
1221 return scope.release();
1228 return scope.release();
1233 QgsExpression::registerFunction(
new GetNamedProjectColor(
nullptr ) );
1234 QgsExpression::registerFunction(
new GetLayoutItemVariables(
nullptr ) );
1235 QgsExpression::registerFunction(
new GetLayerVisibility( QList<QgsMapLayer *>() ) );
1236 QgsExpression::registerFunction(
new GetProcessingParameterValue( QVariantMap() ) );
1242 return mUsesGeometry;
1248 return mReferencedColumns;
1253 return allParamsStatic( node, parent, context );
bool isValid() const
Returns the validity of this feature.
bool hasVariable(const QString &name) const
Tests whether a variable with the specified name exists in the scope.
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static QString locale()
Returns the QGIS locale.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
QVariant cachedValue(const QString &key) const
Returns the matching cached value, if set.
QString description(const QString &name) const
Returns the translated description for the variable with the specified name (if set).
static QgsExpressionContextScope * processingAlgorithmScope(const QgsProcessingAlgorithm *algorithm, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing algorithm...
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
static void setLayoutItemVariable(QgsLayoutItem *item, const QString &name, const QVariant &value)
Sets a layout item context variable, with the given name and value.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Single variable definition for use within a QgsExpressionContextScope.
static void setGlobalVariable(const QString &name, const QVariant &value)
Sets a global context variable.
Base class for all map layer types.
void setCachedValue(const QString &key, const QVariant &value) const
Sets a value to cache within the expression context.
static void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
static const QString QGIS_VERSION
Version string.
QgsExpressionContextScope * scope(int index)
Returns the scope at the specified index within the context.
static void setLayerVariables(QgsMapLayer *layer, const QVariantMap &variables)
Sets all layer context variables.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
bool isReadOnly(const QString &name) const
Returns whether a variable is read only, and should not be modifiable by users.
Base class for graphical items within a QgsLayout.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
static void setLayoutVariable(QgsLayout *layout, const QString &name, const QVariant &value)
Sets a layout context variable.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
static void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
QgsExpressionContext & operator=(const QgsExpressionContext &other)
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
bool hasFunction(const QString &name) const
Checks whether a specified function is contained in the context.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
QgsExpressionContextScope(const QString &name=QString())
Constructor for QgsExpressionContextScope.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
static void removeProjectVariable(QgsProject *project, const QString &name)
Remove project context variable.
QgsExpressionContextScope * activeScopeForVariable(const QString &name)
Returns the currently active scope from the context for a specified variable name.
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
QStringList variableNames() const
Returns a list of variable names contained within the scope.
bool hasCachedValue(const QString &key) const
Returns true if the expression context contains a cached value with a matching key.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the object.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
QString toProj4() const
Returns a Proj4 string representation of this CRS.
bool isReadOnly(const QString &name) const
Tests whether the specified variable is read only and should not be editable by users.
Container of fields for a vector layer.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
A geometry is the spatial representation of a feature.
static QVariantMap customVariables()
Custom expression variables for this application.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
static QgsExpressionContextScope * mapToolCaptureScope(const QList< QgsPointLocator::Match > &matches)
Sets the expression context variables which are available for expressions triggered by a map tool cap...
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
QList< QgsMapLayer * > layers() const
Get list of layers for map rendering The layers are stored in the reverse order of how they are rende...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsExpressionContextScope & operator=(const QgsExpressionContextScope &other)
QList< QgsExpressionContextScope * > takeScopes()
Return all scopes from this context and remove them, leaving this context without any context...
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
static void setLayoutVariables(QgsLayout *layout, const QVariantMap &variables)
Sets all layout context variables.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
static const int QGIS_VERSION_INT
Version number used for comparing versions using the "Check QGIS Version" function.
Abstract base class for processing algorithms.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
QgsExpressionContext & operator<<(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QString userFullName()
Returns the user's operating system login account full display name.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
QString description(const QString &name) const
Returns a translated description string for the variable with specified name.
bool hasFeature() const
Returns true if the context has a feature associated with it.
QgsUnitTypes::DistanceUnit mapUnits() const
Get units of map's geographical coordinates - used for scale calculation.
QgsLayout * layout() override
Returns the layout associated with the iterator.
The QgsMapSettings class contains configuration for rendering of the map.
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()
QSizeF toQSizeF() const
Converts the layout size to a QSizeF.
static QgsExpressionContextScope * layoutItemScope(const QgsLayoutItem *item)
Creates a new scope which contains variables and functions relating to a QgsLayoutItem.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
bool removeVariable(const QString &name)
Removes a variable from the context scope, if found.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
bool hasFunction(const QString &name) const
Tests whether a function with the specified name exists in the scope.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
QgsFields fields() const override
Returns the list of fields of this layer.
int scopeCount() const
Returns the number of scopes contained in the context.
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout...
static void setProjectVariables(QgsProject *project, const QVariantMap &variables)
Sets all project context variables.
double scale() const
Returns the calculated map scale.
double dpi() const
Returns the dpi for outputting the layout.
double width() const
Returns the width of the rectangle.
static QgsExpressionContextScope * notificationScope(const QString &message=QString())
Creates a new scope which contains variables and functions relating to provider notifications.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static void removeGlobalVariable(const QString &name)
Remove a global context variable.
QgsCoordinateReferenceSystem crs
QVariantMap variablesToMap() const
Returns a map of variable name to value representing all the expression variables contained by the co...
Class used to render an Atlas, iterating over geometry features.
QVariant variable(const QString &name) const
Retrieves a variable's value from the scope.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
Reads and writes project states.
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
QString currentFilename() const
Returns the current feature filename.
int page() const
Returns the page the item is currently on, with the first page returning 0.
QString id() const
Returns the item's ID name.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
QgsExpressionFunction * function(const QString &name) const
Retrieves a function from the scope.
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
QStringList variableNames() const
Returns a list of variables names set by all scopes in the context.
int count() override
Returns the number of features to iterate over.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
QStringList functionNames() const
Retrieves a list of names of functions contained in the scope.
void setCustomVariables(const QVariantMap &customVariables)
A map of custom project variables.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
static QString userLoginName()
Returns the user's operating system login account name.
static QString osName()
Returns a string name of the operating system QGIS is running on.
int pageCount() const
Returns the number of pages in the collection.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
static void setProjectVariable(QgsProject *project, const QString &name, const QVariant &value)
Sets a project context variable.
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects. ...
static QgsExpressionContextScope * atlasScope(QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QStringList functionNames() const
Retrieves a list of function names contained in the context.
static const QString QGIS_RELEASE_NAME
Release name.
QgsExpressionContext()=default
Constructor for QgsExpressionContext.
static QgsExpressionContextScope * layoutScope(const QgsLayout *layout)
Creates a new scope which contains variables and functions relating to a QgsLayout layout...
void clearCachedValues() const
Clears all cached values from the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
virtual QString uuid() const
Returns the item identification string.
This class represents a coordinate reference system (CRS).
bool isStatic(const QString &name) const
Tests whether the variable with the specified name is static and can be cached.
QString nameForPage(int page) const
Returns the calculated name for a specified atlas page number.
static QString platform()
Returns the QGIS platform name, e.g., "desktop" or "server".
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the layout.
bool enabled() const
Returns whether the atlas generation is enabled.
bool hasFeature() const
Returns true if the scope has a feature associated with it.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QgsFeature feature() const
Returns the current feature for evaluating the layout.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QString title() const
Returns the project's title.
QgsPointXY center() const
Returns the center point of the rectangle.
QVariantMap customVariables() const
A map of custom project variables.
QString name() const
Returns the friendly display name of the context scope.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Interface for master layout type objects, such as print layouts and reports.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
bool isStatic
A static variable can be cached for the lifetime of a context.
Represents a vector layer which manages a vector based data sets.
int indexOfScope(QgsExpressionContextScope *scope) const
Returns the index of the specified scope if it exists within the context.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
Contains information about the context in which a processing algorithm is executed.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
QStringList filteredVariableNames() const
Returns a filtered and sorted list of variable names contained within the scope.
QList< QgsExpressionContextScope *> scopes()
Returns a list of scopes contained within the stack.
static void setGlobalVariables(const QVariantMap &variables)
Sets all global context variables.
QgsExpressionFunction * function(const QString &name) const
Fetches a matching function from the context.
Expression function for use within a QgsExpressionContextScope.
double angle() const
Returns the marker angle for the whole symbol.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
QString authid() const
Returns the authority identifier for the CRS.
QString name
Variable name.
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
static QColor decodeColor(const QString &str)
double height() const
Returns the height of the rectangle.
Item representing the paper in a layout.
QVariant value
Variable value.