63 : mName( other.mName )
64 , mVariables( other.mVariables )
65 , mHasFeature( other.mHasFeature )
66 , mFeature( other.mFeature )
68 QHash<QString, QgsScopedExpressionFunction * >::const_iterator it = other.mFunctions.constBegin();
69 for ( ; it != other.mFunctions.constEnd(); ++it )
71 mFunctions.insert( it.key(), it.value()->clone() );
78 mVariables = other.mVariables;
79 mHasFeature = other.mHasFeature;
80 mFeature = other.mFeature;
82 qDeleteAll( mFunctions );
84 QHash<QString, QgsScopedExpressionFunction * >::const_iterator it = other.mFunctions.constBegin();
85 for ( ; it != other.mFunctions.constEnd(); ++it )
87 mFunctions.insert( it.key(), it.value()->clone() );
95 qDeleteAll( mFunctions );
100 if ( mVariables.contains( name ) )
103 existing.
value = value;
115 mVariables.insert( variable.
name, variable );
120 return mVariables.remove( name ) > 0;
125 return mVariables.contains( name );
130 return hasVariable( name ) ? mVariables.value( name ).value : QVariant();
135 QStringList names = mVariables.keys();
139 bool QgsExpressionContextScope::variableNameSort(
const QString &a,
const QString &b )
141 return QString::localeAwareCompare( a, b ) < 0;
145 class QgsExpressionContextVariableCompare
152 bool operator()(
const QString &a,
const QString &b )
const 154 bool aReadOnly = mScope.isReadOnly( a );
155 bool bReadOnly = mScope.isReadOnly( b );
156 if ( aReadOnly != bReadOnly )
158 return QString::localeAwareCompare( a, b ) < 0;
168 QStringList allVariables = mVariables.keys();
169 QStringList filtered;
170 Q_FOREACH (
const QString &
variable, allVariables )
172 if ( variable.startsWith(
'_' ) )
177 QgsExpressionContextVariableCompare cmp( *
this );
178 std::sort( filtered.begin(), filtered.end(), cmp );
185 return hasVariable( name ) ? mVariables.value( name ).readOnly :
false;
190 return hasVariable( name ) ? mVariables.value( name ).isStatic :
false;
195 return hasVariable( name ) ? mVariables.value( name ).description : QString();
200 return mFunctions.contains( name );
205 return mFunctions.contains( name ) ? mFunctions.value( name ) :
nullptr;
210 return mFunctions.keys();
215 mFunctions.insert( name,
function );
240 mHighlightedVariables = other.mHighlightedVariables;
241 mHighlightedFunctions = other.mHighlightedFunctions;
242 mCachedValues = other.mCachedValues;
247 if (
this != &other )
249 qDeleteAll( mStack );
251 mStack = other.mStack;
252 other.mStack.clear();
254 mHighlightedVariables = other.mHighlightedVariables;
255 mHighlightedFunctions = other.mHighlightedFunctions;
256 mCachedValues = other.mCachedValues;
263 qDeleteAll( mStack );
269 mHighlightedVariables = other.mHighlightedVariables;
270 mHighlightedFunctions = other.mHighlightedFunctions;
271 mCachedValues = other.mCachedValues;
277 qDeleteAll( mStack );
294 return scope ? scope->
variable( name ) : QVariant();
301 Q_FOREACH (
const QString &name, names )
310 return mHighlightedVariables.contains( name );
320 return mHighlightedFunctions.contains( name );
325 mHighlightedFunctions = names;
331 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
332 while ( it != mStack.constBegin() )
335 if ( ( *it )->hasVariable( name ) )
344 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
345 while ( it != mStack.constBegin() )
348 if ( ( *it )->hasVariable( name ) )
356 if ( index < 0 || index >= mStack.count() )
359 return mStack.at( index );
364 if ( mStack.count() < 1 )
367 return mStack.last();
375 return mStack.indexOf( scope );
383 if ( scope->
name() == scopeName )
398 return names.toSet().toList();
404 QStringList filtered;
405 Q_FOREACH (
const QString &
variable, allVariables )
407 if ( variable.startsWith(
'_' ) )
450 result = result.toSet().toList();
458 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
459 while ( it != mStack.constBegin() )
462 if ( ( *it )->hasFunction( name ) )
463 return ( *it )->function( name );
470 return mStack.count();
475 mStack.append( scope );
480 mStack.append( scopes );
485 if ( !mStack.isEmpty() )
486 return mStack.takeLast();
493 QList<QgsExpressionContextScope *> stack = mStack;
500 mStack.append( scope );
506 if ( mStack.isEmpty() )
509 mStack.last()->setFeature( feature );
525 QList< QgsExpressionContextScope * >::const_iterator it = mStack.constEnd();
526 while ( it != mStack.constBegin() )
529 if ( ( *it )->hasFeature() )
530 return ( *it )->feature();
537 if ( mStack.isEmpty() )
540 mStack.last()->setFields( fields );
550 if ( mStack.isEmpty() )
559 mCachedValues.insert( key, value );
564 return mCachedValues.contains( key );
569 return mCachedValues.value( key, QVariant() );
574 mCachedValues.clear();
588 for ( QVariantMap::const_iterator it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
620 if ( vars.remove( name ) )
630 GetNamedProjectColor(
const QgsProject *project )
632 , mProject( project )
638 QStringList colorStrings = project->
readListEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Colors" ) );
639 QStringList colorLabels = project->
readListEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Labels" ) );
643 for ( QStringList::iterator it = colorStrings.begin();
644 it != colorStrings.end(); ++it )
648 if ( colorLabels.length() > colorIndex )
650 label = colorLabels.at( colorIndex );
653 mColors.insert( label.toLower(), color );
660 QString colorName = values.at( 0 ).toString().toLower();
661 if ( mColors.contains( colorName ) )
663 return QStringLiteral(
"%1,%2,%3" ).arg( mColors.value( colorName ).red() ).arg( mColors.value( colorName ).green() ).arg( mColors.value( colorName ).blue() );
671 return new GetNamedProjectColor( mProject );
677 QHash< QString, QColor > mColors;
694 QString
id = values.at( 0 ).toString();
707 return new GetLayoutItemVariables( mLayout );
719 GetCurrentFormFieldValue( )
725 QString fieldName( values.at( 0 ).toString() );
727 if ( fieldName.isEmpty() || ! feat.isValid( ) )
731 return feat.attribute( fieldName ) ;
736 return new GetCurrentFormFieldValue( );
745 GetProcessingParameterValue(
const QVariantMap ¶ms )
752 return mParams.value( values.at( 0 ).toString() );
757 return new GetProcessingParameterValue( mParams );
762 const QVariantMap mParams;
772 scope->
addFunction( QStringLiteral(
"current_value" ),
new GetCurrentFormFieldValue( ) );
774 scope->
setVariable( QStringLiteral(
"current_feature" ), formFeature,
true );
775 scope->
setVariable( QStringLiteral(
"form_mode" ), formMode,
true );
788 QVariantMap::const_iterator it = vars.constBegin();
790 for ( ; it != vars.constEnd(); ++it )
796 QString projectFolder = QFileInfo( projectPath ).path();
797 QString projectFilename = QFileInfo( projectPath ).fileName();
798 QString projectBasename = project->
baseName();
822 QVariantMap keywords;
824 for (
auto it = metadataKeywords.constBegin(); it != metadataKeywords.constEnd(); ++it )
826 keywords.insert( it.key(), it.value() );
830 scope->
addFunction( QStringLiteral(
"project_color" ),
new GetNamedProjectColor( project ) );
841 vars.insert( name, value );
862 if ( vars.remove( name ) )
875 QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
878 Q_FOREACH (
const QString &variableName, variableNames )
880 if ( varIndex >= variableValues.length() )
885 QVariant varValue = variableValues.at( varIndex );
887 scope->
setVariable( variableName, varValue,
true );
910 QList<QgsExpressionContextScope *>
scopes;
911 scopes << globalScope();
915 scopes << projectScope( project );
918 scopes << layerScope( layer );
930 QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
932 variableNames << name;
933 variableValues << value.toString();
945 QStringList variableValues;
947 QVariantMap::const_iterator it = variables.constBegin();
948 for ( ; it != variables.constEnd(); ++it )
950 variableNames << it.key();
951 variableValues << it.value().toString();
996 QVariantList layersIds;
998 const QList<QgsMapLayer *> layersInMap = mapSettings.
layers();
999 layersIds.reserve( layersInMap.count() );
1000 layers.reserve( layersInMap.count() );
1003 layersIds << layer->id();
1016 scope->
addFunction( QStringLiteral(
"is_layer_visible" ),
new GetLayerVisibility( mapSettings.
layers() ) );
1028 QVariantList matchList;
1032 QVariantMap matchMap;
1034 matchMap.insert( QStringLiteral(
"valid" ), match.isValid() );
1035 matchMap.insert( QStringLiteral(
"layer" ), QVariant::fromValue<QgsWeakMapLayerPointer>(
QgsWeakMapLayerPointer( match.layer() ) ) );
1036 matchMap.insert( QStringLiteral(
"feature_id" ), match.featureId() );
1037 matchMap.insert( QStringLiteral(
"vertex_index" ), match.vertexIndex() );
1038 matchMap.insert( QStringLiteral(
"distance" ), match.distance() );
1040 matchList.append( matchMap );
1059 angle = markerSymbol->
angle();
1070 return scope.release();
1074 QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
1077 Q_FOREACH (
const QString &variableName, variableNames )
1079 if ( varIndex >= variableValues.length() )
1084 QVariant varValue = variableValues.at( varIndex );
1086 scope->setVariable( variableName, varValue );
1103 scope->addFunction( QStringLiteral(
"item_variables" ),
new GetLayoutItemVariables( layout ) );
1115 scope->setFeature( atlasFeature );
1121 return scope.release();
1131 QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
1133 variableNames << name;
1134 variableValues << value.toString();
1137 layout->
setCustomProperty( QStringLiteral(
"variableValues" ), variableValues );
1146 QStringList variableValues;
1148 QVariantMap::const_iterator it = variables.constBegin();
1149 for ( ; it != variables.constEnd(); ++it )
1151 variableNames << it.key();
1152 variableValues << it.value().toString();
1156 layout->
setCustomProperty( QStringLiteral(
"variableValues" ), variableValues );
1206 const QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
1209 for (
const QString &variableName : variableNames )
1211 if ( varIndex >= variableValues.length() )
1216 QVariant varValue = variableValues.at( varIndex );
1252 QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
1254 variableNames << name;
1255 variableValues << value.toString();
1267 QStringList variableValues;
1269 QVariantMap::const_iterator it = variables.constBegin();
1270 for ( ; it != variables.constEnd(); ++it )
1272 variableNames << it.key();
1273 variableValues << it.value().toString();
1291 Q_UNUSED( context );
1294 scope->addFunction( QStringLiteral(
"parameter" ),
new GetProcessingParameterValue( parameters ) );
1297 return scope.release();
1302 return scope.release();
1309 return scope.release();
1324 return mUsesGeometry;
1330 return mReferencedColumns;
1335 return allParamsStatic( node, parent, context );
1342 QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility(
const QList<QgsMapLayer *> &layers )
1344 , mLayers( _qgis_listRawToQPointer( layers ) )
1349 if ( mLayers.isEmpty() )
1354 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
1357 return mLayers.contains( layer );
1367 return new GetLayerVisibility( _qgis_listQPointerToRaw( mLayers ) );
int pageCount() const
Returns the number of pages in the collection.
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
Class for parsing and evaluation of expressions (formerly called "search strings").
static QString locale()
Returns the QGIS locale.
QgsUnitTypes::DistanceUnit mapUnits() const
Gets units of map's geographical coordinates - used for scale calculation.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
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.
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
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.
bool hasFunction(const QString &name) const
Checks whether a specified function is contained in the context.
Base class for all map layer types.
double angle() const
Returns the marker angle for the whole symbol.
static void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
QString title() const
Returns the project's title.
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.
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.
double scale() const
Returns the calculated map scale.
static void setLayoutVariable(QgsLayout *layout, const QString &name, const QVariant &value)
Sets a layout context variable.
static void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
Abstract base class for all rendered symbols.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
QgsExpressionContext & operator=(const QgsExpressionContext &other)
bool isValid() const
Returns the validity of this feature.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
QgsExpressionContextScope(const QString &name=QString())
Constructor for QgsExpressionContextScope.
QgsExpressionFunction * function(const QString &name) const
Retrieves a function from the scope.
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...
QVariant cachedValue(const QString &key) const
Returns the matching cached value, if set.
int scopeCount() const
Returns the number of scopes contained in the context.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
bool isStatic(const QString &name) const
Tests whether the variable with the specified name is static and can be cached.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the object.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Container of fields for a vector layer.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
A geometry is the spatial representation of a feature.
bool hasVariable(const QString &name) const
Tests whether a variable with the specified name exists in the scope.
static QVariantMap customVariables()
Custom expression variables for this application.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
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 QString variableHelpText(const QString &variableName)
Returns the help text for a specified variable.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
bool hasFeature() const
Returns true if the context has a feature associated with it.
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()
Returns all scopes from this context and remove them, leaving this context without any context...
static QgsExpressionContextScope * formScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current attribute form/table feat...
int indexOfScope(QgsExpressionContextScope *scope) const
Returns the index of the specified scope if it exists within the context.
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
Does this function use a geometry object.
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.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
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.
A marker symbol type, for rendering Point and MultiPoint geometries.
static QString userFullName()
Returns the user's operating system login account full display name.
void clearCachedValues() const
Clears all cached values from the context.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QgsLayout * layout() override
Returns the layout associated with the iterator.
void setHighlightedFunctions(const QStringList &names)
Sets the list of function names intended to be highlighted to the user.
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.
QString name() const
Returns the friendly display name of the context scope.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
~QgsExpressionContextScope()
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
Will be called during prepare to determine if the function is static.
QgsUnitTypes::AreaUnit areaUnits() const
Convenience function to query default area measurement units for project.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
bool hasFunction(const QString &name) const
Tests whether a function with the specified name exists in the scope.
QStringList variableNames() const
Returns a list of variables names set by all scopes in the context.
bool removeVariable(const QString &name)
Removes a variable from the context scope, if found.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
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...
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QStringList filteredVariableNames() const
Returns a filtered and sorted list of variable names contained within the scope.
QgsProjectStorage * projectStorage() const
Returns pointer to project storage implementation that handles read/write of the project file...
QgsFeature feature() const
Returns the current feature for evaluating the layout.
QString nameForPage(int page) const
Returns the calculated name for a specified atlas page number.
bool enabled() const
Returns whether the atlas generation is enabled.
bool hasCachedValue(const QString &key) const
Returns true if the expression context contains a cached value with a matching key.
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.
QgsProjectMetadata metadata
QString description(const QString &name) const
Returns the translated description for the variable with the specified name (if set).
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
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
QgsPointXY center() const
Returns the center point of the rectangle.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
bool isReadOnly(const QString &name) const
Returns whether a variable is read only, and should not be modifiable by users.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
static bool registerFunction(QgsExpressionFunction *function, bool transferOwnership=false)
Registers a function to the expression engine.
void setCachedValue(const QString &key, const QVariant &value) const
Sets a value to cache within the expression context.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Reads and writes project states.
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
virtual QString uuid() const
Returns the item identification string.
QString currentFilename() const
Returns the current feature filename.
QStringList functionNames() const
Retrieves a list of function names contained in the context.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
int count() override
Returns the number of features to iterate over.
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
QVariant variable(const QString &name) const
Retrieves a variable's value from the scope.
void setCustomVariables(const QVariantMap &customVariables)
A map of custom project variables.
QString description(const QString &name) const
Returns a translated description string for the variable with specified name.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QSizeF toQSizeF() const
Converts the layout size to a QSizeF.
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.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
QgsCoordinateTransformContext transformContext
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.
A abstract base class for defining QgsExpression functions.
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects. ...
int page() const
Returns the page the item is currently on, with the first page returning 0.
QString baseName() const
Returns the base name of the project file without the path and without extension - derived from fileN...
QgsUnitTypes::DistanceUnit distanceUnits() const
Convenience function to query default distance measurement units for project.
static QgsExpressionContextScope * atlasScope(QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
static const QString QGIS_RELEASE_NAME
Release name.
QVariantMap variablesToMap() const
Returns a map of variable name to value representing all the expression variables contained by the co...
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...
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm's parent class) implements the new pure virtual createInstance(self) call
QVariantMap customVariables() const
A map of custom project variables.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
bool isHighlightedFunction(const QString &name) const
Returns true if the specified function name is intended to be highlighted to the user.
QString authid() const
Returns the authority identifier for the CRS.
QgsExpressionFunction * function(const QString &name) const
Fetches a matching function from the context.
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.
QStringList functionNames() const
Retrieves a list of names of functions contained in the scope.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
QString id() const
Returns the item's ID name.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
Represents a single parameter passed to a function.
const QgsLayout * layout() const
Returns the layout the object is attached to.
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.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Interface for master layout type objects, such as print layouts and reports.
double width() const
Returns the width of the rectangle.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
bool isStatic
A static variable can be cached for the lifetime of a context.
QColor color() const
Returns the symbol's color.
Represents a vector layer which manages a vector based data sets.
bool isReadOnly(const QString &name) const
Tests whether the specified variable is read only and should not be editable by users.
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.
double dpi() const
Returns the dpi for outputting the layout.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QList< QgsExpressionContextScope * > scopes()
Returns a list of scopes contained within the stack.
static void setGlobalVariables(const QVariantMap &variables)
Sets all global context variables.
bool hasFeature() const
Returns true if the scope has a feature associated with it.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
Expression function for use within a QgsExpressionContextScope.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
QString name
Variable name.
QgsCoordinateReferenceSystem crs
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
static QColor decodeColor(const QString &str)
QStringList variableNames() const
Returns a list of variable names contained within the scope.
double height() const
Returns the height of the rectangle.
Item representing the paper in a layout.
QString toProj4() const
Returns a Proj4 string representation of this CRS.
QVariant value
Variable value.