22 #include "qgsprocessingmodelalgorithm.h" 39 for ( QVariantMap::const_iterator it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
71 if ( vars.remove( name ) )
90 QString
id = values.at( 0 ).toString();
103 return new GetLayoutItemVariables( mLayout );
115 GetCurrentFormFieldValue( )
121 QString fieldName( values.at( 0 ).toString() );
123 if ( fieldName.isEmpty() || ! feat.isValid( ) )
127 return feat.attribute( fieldName ) ;
132 return new GetCurrentFormFieldValue( );
141 GetProcessingParameterValue(
const QVariantMap ¶ms )
148 return mParams.value( values.at( 0 ).toString() );
153 return new GetProcessingParameterValue( mParams );
158 const QVariantMap mParams;
168 scope->
addFunction( QStringLiteral(
"current_value" ),
new GetCurrentFormFieldValue( ) );
170 scope->
setVariable( QStringLiteral(
"current_feature" ), formFeature,
true );
171 scope->
setVariable( QStringLiteral(
"form_mode" ), formMode,
true );
193 vars.insert( name, value );
214 if ( vars.remove( name ) )
226 const QStringList variableNames = layer->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
227 const QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
230 for (
const QString &variableName : variableNames )
232 if ( varIndex >= variableValues.length() )
237 QVariant varValue = variableValues.at( varIndex );
239 scope->
setVariable( variableName, varValue,
true );
262 QList<QgsExpressionContextScope *> scopes;
281 QStringList variableNames = layer->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
282 QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
284 variableNames << name;
285 variableValues << value.toString();
296 QStringList variableNames;
297 QStringList variableValues;
299 QVariantMap::const_iterator it = variables.constBegin();
300 for ( ; it != variables.constEnd(); ++it )
302 variableNames << it.key();
303 variableValues << it.value().toString();
353 QVariantList layersIds;
355 const QList<QgsMapLayer *> layersInMap = mapSettings.
layers();
356 layersIds.reserve( layersInMap.count() );
357 layers.reserve( layersInMap.count() );
360 layersIds << layer->id();
373 scope->
addFunction( QStringLiteral(
"is_layer_visible" ),
new GetLayerVisibility( mapSettings.
layers(), mapSettings.
scale() ) );
385 QVariantList matchList;
389 QVariantMap matchMap;
391 matchMap.insert( QStringLiteral(
"valid" ), match.isValid() );
392 matchMap.insert( QStringLiteral(
"layer" ), QVariant::fromValue<QgsWeakMapLayerPointer>(
QgsWeakMapLayerPointer( match.layer() ) ) );
393 matchMap.insert( QStringLiteral(
"feature_id" ), match.featureId() );
394 matchMap.insert( QStringLiteral(
"vertex_index" ), match.vertexIndex() );
395 matchMap.insert( QStringLiteral(
"distance" ), match.distance() );
397 matchList.append( matchMap );
416 angle = markerSymbol->
angle();
427 return scope.release();
430 const QStringList variableNames = layout->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
431 const QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
435 for (
const QString &variableName : variableNames )
437 if ( varIndex >= variableValues.length() )
442 QVariant varValue = variableValues.at( varIndex );
444 scope->setVariable( variableName, varValue );
461 scope->addFunction( QStringLiteral(
"item_variables" ),
new GetLayoutItemVariables( layout ) );
473 scope->setFeature( atlasFeature );
479 return scope.release();
488 QStringList variableNames = layout->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
489 QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
491 variableNames << name;
492 variableValues << value.toString();
503 QStringList variableNames;
504 QStringList variableValues;
506 QVariantMap::const_iterator it = variables.constBegin();
507 for ( ; it != variables.constEnd(); ++it )
509 variableNames << it.key();
510 variableValues << it.value().toString();
563 const QStringList variableNames = item->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
564 const QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
567 for (
const QString &variableName : variableNames )
569 if ( varIndex >= variableValues.length() )
574 QVariant varValue = variableValues.at( varIndex );
609 QStringList variableNames = item->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
610 QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
612 variableNames << name;
613 variableValues << value.toString();
624 QStringList variableNames;
625 QStringList variableValues;
627 QVariantMap::const_iterator it = variables.constBegin();
628 for ( ; it != variables.constEnd(); ++it )
630 variableNames << it.key();
631 variableValues << it.value().toString();
645 const QStringList variableNames = frame->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
646 const QStringList variableValues = frame->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
649 for (
const QString &variableName : variableNames )
651 if ( varIndex >= variableValues.length() )
656 QVariant varValue = variableValues.at( varIndex );
670 QStringList variableNames = frame->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
671 QStringList variableValues = frame->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
673 variableNames << name;
674 variableValues << value.toString();
685 QStringList variableNames;
686 QStringList variableValues;
688 QVariantMap::const_iterator it = variables.constBegin();
689 for ( ; it != variables.constEnd(); ++it )
691 variableNames << it.key();
692 variableValues << it.value().toString();
713 scope->addFunction( QStringLiteral(
"parameter" ),
new GetProcessingParameterValue( parameters ) );
716 return scope.release();
721 return scope.release();
728 if ( !model->sourceFilePath().isEmpty() )
730 modelPath = model->sourceFilePath();
739 const QString modelFolder = !modelPath.isEmpty() ? QFileInfo( modelPath ).path() : QString();
746 const QVariantMap customVariables = model->variables();
747 for (
auto it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
752 return modelScope.release();
759 return scope.release();
774 return mUsesGeometry;
780 return mReferencedColumns;
785 return allParamsStatic( node, parent, context );
792 QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility(
const QList<QgsMapLayer *> &layers,
double scale )
794 , mLayers( _qgis_listRawToQPointer( layers ) )
797 for (
const auto layer : mLayers )
799 if ( layer->hasScaleBasedVisibility() )
801 mScaleBasedVisibilityDetails[ layer ] = qMakePair( layer->minimumScale(), layer->maximumScale() );
806 QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility()
812 if ( mLayers.isEmpty() )
817 bool isVisible =
false;
818 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
819 if ( layer && mLayers.contains( layer ) )
822 if ( mScaleBasedVisibilityDetails.contains( layer ) && !
qgsDoubleNear( mScale, 0.0 ) )
824 if ( ( !
qgsDoubleNear( mScaleBasedVisibilityDetails[ layer ].first, 0.0 ) && mScale > mScaleBasedVisibilityDetails[ layer ].first ) ||
825 ( !
qgsDoubleNear( mScaleBasedVisibilityDetails[ layer ].second, 0.0 ) && mScale < mScaleBasedVisibilityDetails[ layer ].second ) )
837 GetLayerVisibility *func =
new GetLayerVisibility();
838 func->mLayers = mLayers;
839 func->mScale = mScale;
840 func->mScaleBasedVisibilityDetails = mScaleBasedVisibilityDetails;
bool isValid() const
Returns the validity of this feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
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.
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 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.
static void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
static const QString QGIS_VERSION
Version string.
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...
Base class for graphical items within a QgsLayout.
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.
static void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
Abstract base class for all rendered symbols.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
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.
static void removeProjectVariable(QgsProject *project, const QString &name)
Remove project context variable.
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
int count() const override
Returns the number of features to iterate over.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
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.
Container of fields for a vector layer.
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.
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
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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...
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.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
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 ...
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
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.
A marker symbol type, for rendering Point and MultiPoint geometries.
static QString userFullName()
Returns the user's operating system login account full display name.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
QgsUnitTypes::DistanceUnit mapUnits() const
Gets 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.
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
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
Will be called during prepare to determine if the function is static.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
static QgsExpressionContextScope * multiFrameScope(const QgsLayoutMultiFrame *frame)
Creates a new scope which contains variables and functions relating to a QgsLayoutMultiFrame.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
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.
static void setLayoutMultiFrameVariable(QgsLayoutMultiFrame *frame, const QString &name, const QVariant &value)
Sets a layout multi frame context variable, with the given name and value.
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.
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.
QVariantMap variablesToMap() const
Returns a map of variable name to value representing all the expression variables contained by the co...
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
static bool registerFunction(QgsExpressionFunction *function, bool transferOwnership=false)
Registers a function to the expression engine.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
QColor color() const
Returns the symbol's color.
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.
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.
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.
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
QgsProjectStorage * projectStorage() const
Returns pointer to project storage implementation that handles read/write of the project file...
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.
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
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 QgsExpressionContextScope * processingModelAlgorithmScope(const QgsProcessingModelAlgorithm *model, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing model algorithm...
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects. ...
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.
static QgsExpressionContextScope * layoutScope(const QgsLayout *layout)
Creates a new scope which contains variables and functions relating to a QgsLayout layout...
static void setLayoutMultiFrameVariables(QgsLayoutMultiFrame *frame, const QVariantMap &variables)
Sets all layout multiframe context variables for an frame.
static QgsProject * instance()
Returns the QgsProject singleton instance.
virtual QString uuid() const
Returns the item identification string.
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".
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.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QgsFeature feature() const
Returns the current feature for evaluating the layout.
Represents a single parameter passed to a function.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsPointXY center() const
Returns the center point of the rectangle.
QVariantMap customVariables() const
A map of custom project variables.
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.
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
static void setGlobalVariables(const QVariantMap &variables)
Sets all global context variables.
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.
QgsCoordinateReferenceSystem crs
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
double height() const
Returns the height of the rectangle.
Item representing the paper in a layout.