QGIS API Documentation  3.0.2-Girona (307d082)
Classes | Public Types | Public Member Functions | List of all members
QgsProcessingContext Class Reference

Contains information about the context in which a processing algorithm is executed. More...

#include <qgsprocessingcontext.h>

Classes

struct  LayerDetails
 Details for layers to load into projects. More...
 

Public Types

enum  Flag
 Flags that affect how processing algorithms are run. More...
 

Public Member Functions

 QgsProcessingContext ()
 Constructor for QgsProcessingContext. More...
 
 QgsProcessingContext (const QgsProcessingContext &other)=delete
 QgsProcessingContext cannot be copied. More...
 
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. More...
 
void copyThreadSafeSettings (const QgsProcessingContext &other)
 Copies all settings which are safe for use across different threads from other to this context. More...
 
QString defaultEncoding () const
 Returns the default encoding to use for newly created files. More...
 
QgsExpressionContextexpressionContext ()
 Returns the expression context. More...
 
const QgsExpressionContextexpressionContext () const
 Returns the expression context. More...
 
QgsProcessingFeedbackfeedback ()
 Returns the associated feedback object. More...
 
QgsProcessingContext::Flags flags () const
 Returns any flags set in the context. More...
 
QgsMapLayergetMapLayer (const QString &identifier)
 Returns a map layer from the context with a matching identifier. More...
 
std::function< void(const QgsFeature &) > invalidGeometryCallback () const
 Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid. More...
 
QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck () const
 Returns the behavior used for checking invalid geometries in input layers. More...
 
QMap< QString, QgsProcessingContext::LayerDetailslayersToLoadOnCompletion () const
 Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model. More...
 
QgsProcessingContextoperator= (const QgsProcessingContext &other)=delete
 QgsProcessingContext cannot be copied. More...
 
QgsProjectproject () const
 Returns the project in which the algorithm is being executed. More...
 
void pushToThread (QThread *thread)
 Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into another thread. More...
 
void setDefaultEncoding (const QString &encoding)
 Sets the default encoding to use for newly created files. More...
 
void setExpressionContext (const QgsExpressionContext &context)
 Sets the expression context. More...
 
void setFeedback (QgsProcessingFeedback *feedback)
 Sets an associated feedback object. More...
 
void setFlags (QgsProcessingContext::Flags flags)
 Sets flags for the context. More...
 
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. More...
 
void setInvalidGeometryCheck (QgsFeatureRequest::InvalidGeometryCheck check)
 Sets the behavior used for checking invalid geometries in input layers. More...
 
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. More...
 
void setProject (QgsProject *project)
 Sets the project in which the algorithm will be executed. More...
 
void setTransformContext (const QgsCoordinateTransformContext &context)
 Sets the coordinate transform context. More...
 
void setTransformErrorCallback (const std::function< void(const QgsFeature &) > &callback)
 Sets a callback function to use when encountering a transform error when iterating features. More...
 
QgsMapLayertakeResultLayer (const QString &id)
 Takes the result map layer with matching id from the context and transfers ownership of it back to the caller. More...
 
void takeResultsFrom (QgsProcessingContext &context)
 Takes the results from another context and merges them with the results currently stored in this context. More...
 
QgsMapLayerStoretemporaryLayerStore ()
 Returns a reference to the layer store used for storing temporary layers during algorithm execution. More...
 
QThread * thread ()
 Returns the thread in which the context lives. More...
 
QgsCoordinateTransformContext transformContext () const
 Returns the coordinate transform context. More...
 
std::function< void(const QgsFeature &) > transformErrorCallback () const
 Returns the callback function to use when encountering a transform error when iterating features. More...
 

Detailed Description

Contains information about the context in which a processing algorithm is executed.

Contextual information includes settings such as the associated project, and expression context.

Since
QGIS 3.0

Definition at line 40 of file qgsprocessingcontext.h.

Member Enumeration Documentation

◆ Flag

Flags that affect how processing algorithms are run.

Definition at line 45 of file qgsprocessingcontext.h.

Constructor & Destructor Documentation

◆ QgsProcessingContext() [1/2]

QgsProcessingContext::QgsProcessingContext ( )
inline

Constructor for QgsProcessingContext.

Definition at line 54 of file qgsprocessingcontext.h.

◆ QgsProcessingContext() [2/2]

QgsProcessingContext::QgsProcessingContext ( const QgsProcessingContext other)
delete

QgsProcessingContext cannot be copied.

Member Function Documentation

◆ addLayerToLoadOnCompletion()

void QgsProcessingContext::addLayerToLoadOnCompletion ( const QString &  layer,
const QgsProcessingContext::LayerDetails details 
)
inline

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.

See also
setLayersToLoadOnCompletion()
layersToLoadOnCompletion()

Definition at line 206 of file qgsprocessingcontext.h.

◆ copyThreadSafeSettings()

void QgsProcessingContext::copyThreadSafeSettings ( const QgsProcessingContext other)
inline

Copies all settings which are safe for use across different threads from other to this context.

Definition at line 73 of file qgsprocessingcontext.h.

◆ defaultEncoding()

QString QgsProcessingContext::defaultEncoding ( ) const
inline

Returns the default encoding to use for newly created files.

See also
setDefaultEncoding()

Definition at line 298 of file qgsprocessingcontext.h.

◆ expressionContext() [1/2]

QgsExpressionContext& QgsProcessingContext::expressionContext ( )
inline

Returns the expression context.

Definition at line 122 of file qgsprocessingcontext.h.

◆ expressionContext() [2/2]

const QgsExpressionContext& QgsProcessingContext::expressionContext ( ) const
inline

Returns the expression context.

Definition at line 127 of file qgsprocessingcontext.h.

◆ feedback()

QgsProcessingFeedback* QgsProcessingContext::feedback ( )
inline

Returns the associated feedback object.

See also
setFeedback()

Definition at line 310 of file qgsprocessingcontext.h.

◆ flags()

QgsProcessingContext::Flags QgsProcessingContext::flags ( ) const
inline

Returns any flags set in the context.

See also
setFlags()

Definition at line 90 of file qgsprocessingcontext.h.

◆ getMapLayer()

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::mapLayerFromString() for details).

Ownership is not transferred and remains with the context.

See also
takeResultLayer()

Definition at line 65 of file qgsprocessingcontext.cpp.

◆ invalidGeometryCallback()

std::function< void( const QgsFeature & ) > QgsProcessingContext::invalidGeometryCallback ( ) const
inline

Returns the callback function to use when encountering an invalid geometry and invalidGeometryCheck() is set to GeometryAbortOnInvalid.

Since
QGIS 3.0
Note
not available in Python bindings
See also
setInvalidGeometryCallback()

Definition at line 257 of file qgsprocessingcontext.h.

◆ invalidGeometryCheck()

QgsFeatureRequest::InvalidGeometryCheck QgsProcessingContext::invalidGeometryCheck ( ) const
inline

Returns the behavior used for checking invalid geometries in input layers.

See also
setInvalidGeometryCheck()

Definition at line 215 of file qgsprocessingcontext.h.

◆ layersToLoadOnCompletion()

QMap< QString, QgsProcessingContext::LayerDetails > QgsProcessingContext::layersToLoadOnCompletion ( ) const
inline

Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.

See also
setLayersToLoadOnCompletion()
addLayerToLoadOnCompletion()

Definition at line 185 of file qgsprocessingcontext.h.

◆ operator=()

QgsProcessingContext& QgsProcessingContext::operator= ( const QgsProcessingContext other)
delete

QgsProcessingContext cannot be copied.

◆ project()

QgsProject* QgsProcessingContext::project ( ) const
inline

Returns the project in which the algorithm is being executed.

See also
setProject()

Definition at line 102 of file qgsprocessingcontext.h.

◆ pushToThread()

void QgsProcessingContext::pushToThread ( QThread *  thread)
inline

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()).

See also
thread()

Definition at line 334 of file qgsprocessingcontext.h.

◆ setDefaultEncoding()

void QgsProcessingContext::setDefaultEncoding ( const QString &  encoding)
inline

Sets the default encoding to use for newly created files.

See also
defaultEncoding()

Definition at line 304 of file qgsprocessingcontext.h.

◆ setExpressionContext()

void QgsProcessingContext::setExpressionContext ( const QgsExpressionContext context)
inline

Sets the expression context.

Definition at line 132 of file qgsprocessingcontext.h.

◆ setFeedback()

void QgsProcessingContext::setFeedback ( QgsProcessingFeedback feedback)
inline

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.

See also
setFeedback()

Definition at line 320 of file qgsprocessingcontext.h.

◆ setFlags()

void QgsProcessingContext::setFlags ( QgsProcessingContext::Flags  flags)
inline

Sets flags for the context.

See also
flags()

Definition at line 96 of file qgsprocessingcontext.h.

◆ setInvalidGeometryCallback()

void QgsProcessingContext::setInvalidGeometryCallback ( const std::function< void(const QgsFeature &) > &  callback)
inline

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.

Since
QGIS 3.0
See also
invalidGeometryCallback()

Definition at line 233 of file qgsprocessingcontext.h.

◆ setInvalidGeometryCheck()

void QgsProcessingContext::setInvalidGeometryCheck ( QgsFeatureRequest::InvalidGeometryCheck  check)

Sets the behavior used for checking invalid geometries in input layers.

Settings this to anything but QgsFeatureRequest::GeometryNoCheck will also reset the invalidGeometryCallback() to a default implementation.

See also
invalidGeometryCheck()

Definition at line 21 of file qgsprocessingcontext.cpp.

◆ setLayersToLoadOnCompletion()

void QgsProcessingContext::setLayersToLoadOnCompletion ( const QMap< QString, QgsProcessingContext::LayerDetails > &  layers)
inline

Sets the map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completion of the algorithm or model.

See also
addLayerToLoadOnCompletion()
layersToLoadOnCompletion()

Definition at line 195 of file qgsprocessingcontext.h.

◆ setProject()

void QgsProcessingContext::setProject ( QgsProject project)
inline

Sets the project in which the algorithm will be executed.

This also automatically sets the transformContext() to match the project's transform context.

See also
project()

Definition at line 112 of file qgsprocessingcontext.h.

◆ setTransformContext()

void QgsProcessingContext::setTransformContext ( const QgsCoordinateTransformContext context)
inline

Sets the coordinate transform context.

Note that setting a project for the context will automatically set the coordinate transform context.

See also
transformContext()

Definition at line 148 of file qgsprocessingcontext.h.

◆ setTransformErrorCallback()

void QgsProcessingContext::setTransformErrorCallback ( const std::function< void(const QgsFeature &) > &  callback)
inline

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.

Since
QGIS 3.0
See also
transformErrorCallback()

Definition at line 267 of file qgsprocessingcontext.h.

◆ takeResultLayer()

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.

See also
getMapLayer()

Definition at line 70 of file qgsprocessingcontext.cpp.

◆ takeResultsFrom()

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.

Definition at line 53 of file qgsprocessingcontext.cpp.

◆ temporaryLayerStore()

QgsMapLayerStore* QgsProcessingContext::temporaryLayerStore ( )
inline

Returns a reference to the layer store used for storing temporary layers during algorithm execution.

Definition at line 154 of file qgsprocessingcontext.h.

◆ thread()

QThread* QgsProcessingContext::thread ( )
inline

Returns the thread in which the context lives.

See also
pushToThread()

Definition at line 326 of file qgsprocessingcontext.h.

◆ transformContext()

QgsCoordinateTransformContext QgsProcessingContext::transformContext ( ) const
inline

Returns the coordinate transform context.

See also
setTransformContext()

Definition at line 138 of file qgsprocessingcontext.h.

◆ transformErrorCallback()

std::function< void( const QgsFeature & ) > QgsProcessingContext::transformErrorCallback ( ) const
inline

Returns the callback function to use when encountering a transform error when iterating features.

Since
QGIS 3.0
Note
not available in Python bindings
See also
setTransformErrorCallback()
destinationCrs()

Definition at line 292 of file qgsprocessingcontext.h.


The documentation for this class was generated from the following files: