QgsProcessingContext class
Contains information about the context in which a processing algorithm is executed.
Contents
Contextual information includes settings such as the associated project, and expression context.
Public types
- class LayerDetails
- Details for layers to load into projects.
- enum Flag { }
- Flags that affect how processing algorithms are run.
Constructors, destructors, conversion operators
- QgsProcessingContext()
- Constructor for QgsProcessingContext.
- QgsProcessingContext(const QgsProcessingContext& other) deleted
- QgsProcessingContext cannot be copied.
Public functions
-
void addLayerToLoadOnCompletion(const QString& layer,
const QgsProcessingContext::
LayerDetails& details) - Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
- void copyThreadSafeSettings(const QgsProcessingContext& other)
- Copies all settings which are safe for use across different threads from other to this context.
- auto defaultEncoding() const -> QString
- Returns the default encoding to use for newly created files.
- auto expressionContext() -> QgsExpressionContext&
- Returns the expression context.
- auto expressionContext() const -> const QgsExpressionContext&
- Returns the expression context.
- auto feedback() -> QgsProcessingFeedback*
- Returns the associated feedback object.
- auto flags() const -> QgsProcessingContext::Flags
- Returns any flags set in the context.
- auto getMapLayer(const QString& identifier) -> QgsMapLayer*
- Returns a map layer from the context with a matching identifier.
- auto invalidGeometryCallback() const -> std::function<void(const QgsFeature&)>
- Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.
-
auto invalidGeometryCheck() const -> QgsFeatureRequest::
InvalidGeometryCheck - Returns the behavior used for checking invalid geometries in input layers.
-
auto layersToLoadOnCompletion() const -> QMap<QString, QgsProcessingContext::
LayerDetails> - Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
-
auto layerToLoadOnCompletionDetails(const QString& layer) -> QgsProcessingContext::
LayerDetails& - Returns a reference to the details for a given layer which is loaded on completion of the algorithm or model.
- auto operator=(const QgsProcessingContext& other) -> QgsProcessingContext& deleted
- QgsProcessingContext cannot be copied.
- auto project() const -> QgsProject*
- Returns the project in which the algorithm is being executed.
- void pushToThread(QThread* thread)
- Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into another thread.
- void setDefaultEncoding(const QString& encoding)
- Sets the default encoding to use for newly created files.
- void setExpressionContext(const QgsExpressionContext& context)
- Sets the expression context.
- void setFeedback(QgsProcessingFeedback* feedback)
- Sets an associated feedback object.
- void setFlags(QgsProcessingContext::Flags flags)
- Sets flags for the context.
- void setInvalidGeometryCallback(const std::function<void(const QgsFeature&)>& callback)
- Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.
-
void setInvalidGeometryCheck(QgsFeatureRequest::
InvalidGeometryCheck check) - Sets the behavior used for checking invalid geometries in input layers.
-
void setLayersToLoadOnCompletion(const QMap<QString, QgsProcessingContext::
LayerDetails>& layers) - Sets the map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
- void setProject(QgsProject* project)
- Sets the project in which the algorithm will be executed.
- void setTransformContext(const QgsCoordinateTransformContext& context)
- Sets the coordinate transform context.
- void setTransformErrorCallback(const std::function<void(const QgsFeature&)>& callback)
- Sets a callback function to use when encountering a transform error when iterating features.
- auto takeResultLayer(const QString& id) -> QgsMapLayer*
- Takes the result map layer with matching id from the context and transfers ownership of it back to the caller.
- void takeResultsFrom(QgsProcessingContext& context)
- Takes the results from another context and merges them with the results currently stored in this context.
- auto temporaryLayerStore() -> QgsMapLayerStore*
- Returns a reference to the layer store used for storing temporary layers during algorithm execution.
- auto thread() -> QThread*
- Returns the thread in which the context lives.
- auto transformContext() const -> QgsCoordinateTransformContext
- Returns the coordinate transform context.
- auto transformErrorCallback() const -> std::function<void(const QgsFeature&)>
- Returns the callback function to use when encountering a transform error when iterating features.
- auto willLoadLayerOnCompletion(const QString& layer) const -> bool
- Returns true if the given layer (by ID or datasource) will be loaded into the current project upon completion of the algorithm or model.
Function documentation
void QgsProcessingContext:: addLayerToLoadOnCompletion(const QString& layer,
const QgsProcessingContext:: LayerDetails& details)
Adds a layer to load (by ID or datasource) into the canvas upon completion of the algorithm or model.
The details parameter dictates the LayerDetails.
QString QgsProcessingContext:: defaultEncoding() const
Returns the default encoding to use for newly created files.
QgsProcessingFeedback* QgsProcessingContext:: feedback()
Returns the associated feedback object.
QgsProcessingContext::Flags QgsProcessingContext:: flags() const
Returns any flags set in the context.
QgsMapLayer* QgsProcessingContext:: getMapLayer(const QString& identifier)
Returns a map layer from the context with a matching identifier.
This method considers layer IDs, names and sources when matching the identifier (see QgsProcessingUtils::
Ownership is not transferred and remains with the context.
std::function<void(const QgsFeature&)> QgsProcessingContext:: invalidGeometryCallback() const
Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.
QgsFeatureRequest:: InvalidGeometryCheck QgsProcessingContext:: invalidGeometryCheck() const
Returns the behavior used for checking invalid geometries in input layers.
QMap<QString, QgsProcessingContext:: LayerDetails> QgsProcessingContext:: layersToLoadOnCompletion() const
Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
QgsProcessingContext:: LayerDetails& QgsProcessingContext:: layerToLoadOnCompletionDetails(const QString& layer)
Returns a reference to the details for a given layer which is loaded on completion of the algorithm or model.
QgsProject* QgsProcessingContext:: project() const
Returns the project in which the algorithm is being executed.
void QgsProcessingContext:: pushToThread(QThread* thread)
Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into another thread.
This method is only safe to call when the current thread matches the existing thread affinity for the context (see thread()).
void QgsProcessingContext:: setDefaultEncoding(const QString& encoding)
Sets the default encoding to use for newly created files.
void QgsProcessingContext:: setFeedback(QgsProcessingFeedback* feedback)
Sets an associated feedback object.
This allows context related functions to report feedback and errors to users and processing logs. While ideally this feedback object should outlive the context, only a weak pointer to feedback is stored and no errors will occur if feedback is deleted before the context. Ownership of feedback is not transferred.
void QgsProcessingContext:: setFlags(QgsProcessingContext::Flags flags)
Sets flags for the context.
void QgsProcessingContext:: setInvalidGeometryCallback(const std::function<void(const QgsFeature&)>& callback)
Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.
This function will be called using the feature with invalid geometry as a parameter.
void QgsProcessingContext:: setInvalidGeometryCheck(QgsFeatureRequest:: InvalidGeometryCheck check)
Sets the behavior used for checking invalid geometries in input layers.
Settings this to anything but QgsFeatureRequest::
void QgsProcessingContext:: setLayersToLoadOnCompletion(const QMap<QString, QgsProcessingContext:: LayerDetails>& layers)
Sets the map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.
void QgsProcessingContext:: setProject(QgsProject* project)
Sets the project in which the algorithm will be executed.
This also automatically sets the transformContext() to match the project's transform context.
void QgsProcessingContext:: setTransformContext(const QgsCoordinateTransformContext& context)
Sets the coordinate transform context.
Note that setting a project for the context will automatically set the coordinate transform context.
void QgsProcessingContext:: setTransformErrorCallback(const std::function<void(const QgsFeature&)>& callback)
Sets a callback function to use when encountering a transform error when iterating features.
This function will be called using the feature which encountered the transform error as a parameter.
QgsMapLayer* QgsProcessingContext:: takeResultLayer(const QString& id)
Takes the result map layer with matching id from the context and transfers ownership of it back to the caller.
This method can be used to remove temporary layers which are not required for further processing from a context.
void QgsProcessingContext:: takeResultsFrom(QgsProcessingContext& context)
Takes the results from another context and merges them with the results currently stored in this context.
This includes settings like any layers loaded in the temporaryLayerStore() and layersToLoadOnCompletion(). This is only safe to call when both this context and the other context share the same thread() affinity, and that thread is the current thread.
QThread* QgsProcessingContext:: thread()
Returns the thread in which the context lives.
QgsCoordinateTransformContext QgsProcessingContext:: transformContext() const
Returns the coordinate transform context.
std::function<void(const QgsFeature&)> QgsProcessingContext:: transformErrorCallback() const
Returns the callback function to use when encountering a transform error when iterating features.
bool QgsProcessingContext:: willLoadLayerOnCompletion(const QString& layer) const
Returns true if the given layer (by ID or datasource) will be loaded into the current project upon completion of the algorithm or model.