18 #ifndef QGSPROCESSINGCONTEXT_H
19 #define QGSPROCESSINGCONTEXT_H
21 #include "qgis_core.h"
54 Q_DECLARE_FLAGS( Flags, Flag )
74 mFlags = other.mFlags;
75 mProject = other.mProject;
76 mTransformContext = other.mTransformContext;
77 mExpressionContext = other.mExpressionContext;
78 mInvalidGeometryCallback = other.mInvalidGeometryCallback;
79 mUseDefaultInvalidGeometryCallback = other.mUseDefaultInvalidGeometryCallback;
80 mInvalidGeometryCheck = other.mInvalidGeometryCheck;
81 mTransformErrorCallback = other.mTransformErrorCallback;
82 mDefaultEncoding = other.mDefaultEncoding;
83 mFeedback = other.mFeedback;
84 mPreferredVectorFormat = other.mPreferredVectorFormat;
85 mPreferredRasterFormat = other.mPreferredRasterFormat;
86 mEllipsoid = other.mEllipsoid;
87 mDistanceUnit = other.mDistanceUnit;
88 mAreaUnit = other.mAreaUnit;
95 QgsProcessingContext::Flags
flags()
const {
return mFlags; }
101 void setFlags( QgsProcessingContext::Flags flags ) { mFlags = flags; }
123 if ( mEllipsoid.isEmpty() )
124 mEllipsoid = mProject->ellipsoid();
126 mDistanceUnit = mProject->distanceUnits();
128 mAreaUnit = mProject->areaUnits();
169 QString ellipsoid()
const;
179 void setEllipsoid(
const QString &ellipsoid );
227 QgsDateTimeRange currentTimeRange()
const;
235 void setCurrentTimeRange(
const QgsDateTimeRange ¤tTimeRange );
257 , outputName( outputName )
258 , layerTypeHint( layerTypeHint )
278 bool forceName =
false;
314 void setOutputLayerName(
QgsMapLayer *layer )
const;
335 return mLayersToLoadOnCompletion;
349 return mLayersToLoadOnCompletion.contains( layer );
359 void setLayersToLoadOnCompletion(
const QMap< QString, QgsProcessingContext::LayerDetails > &layers );
386 return mLayersToLoadOnCompletion[ layer ];
413 void setInvalidGeometryCallback( SIP_PYCALLABLE / AllowNone / );
415 Py_BEGIN_ALLOW_THREADS
417 sipCpp->setInvalidGeometryCallback( [a0](
const QgsFeature &arg )
420 Py_XDECREF( sipCallMethod( NULL, a0,
"D", &arg, sipType_QgsFeature, NULL ) );
454 void setTransformErrorCallback( SIP_PYCALLABLE / AllowNone / );
456 Py_BEGIN_ALLOW_THREADS
458 sipCpp->setTransformErrorCallback( [a0](
const QgsFeature &arg )
461 Py_XDECREF( sipCallMethod( NULL, a0,
"D", &arg, sipType_QgsFeature, NULL ) );
510 QThread *
thread() {
return tempLayerStore.thread(); }
521 Q_ASSERT_X( QThread::currentThread() ==
QgsProcessingContext::thread(),
"QgsProcessingContext::pushToThread",
"Cannot push context to another thread unless the current thread matches the existing context thread affinity" );
522 tempLayerStore.moveToThread( thread );
544 QgsMapLayer *getMapLayer(
const QString &identifier );
632 QgsProcessingContext::Flags mFlags = QgsProcessingContext::Flags();
633 QPointer< QgsProject > mProject;
640 QgsDateTimeRange mCurrentTimeRange;
647 bool mUseDefaultInvalidGeometryCallback =
true;
648 std::function< void(
const QgsFeature & ) > mInvalidGeometryCallback;
650 std::function< void(
const QgsFeature & ) > mTransformErrorCallback;
651 QString mDefaultEncoding;
652 QMap< QString, LayerDetails > mLayersToLoadOnCompletion;
654 QPointer< QgsProcessingFeedback > mFeedback;
656 QString mPreferredVectorFormat;
657 QString mPreferredRasterFormat;
Contains information about the context in which a coordinate transform is executed.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
InvalidGeometryCheck
Handling of features with invalid geometries.
@ GeometryNoCheck
No invalid geometry checking.
An interface for objects which provide features via a getFeatures method.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Base class for all map layer types.
Details for layers to load into projects.
LayerDetails()=default
Default constructor.
QString name
Friendly name for layer, possibly for use when loading layer into project.
LayerDetails(const QString &name, QgsProject *project, const QString &outputName=QString(), QgsProcessingUtils::LayerHint layerTypeHint=QgsProcessingUtils::LayerHint::UnknownType)
Constructor for LayerDetails.
QString outputName
Associated output name from algorithm which generated the layer.
Contains information about the context in which a processing algorithm is executed.
QString defaultEncoding() const
Returns the default encoding to use for newly created files.
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
QString preferredRasterFormat() const
Returns the preferred raster format to use for vector outputs.
QgsProcessingContext::Flags flags() const
Returns any flags set in the context.
std::function< void(const QgsFeature &) > transformErrorCallback() const
Returns the callback function to use when encountering a transform error when iterating features.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsProcessingContext(const QgsProcessingContext &other)=delete
QgsProcessingContext cannot be copied.
void setDefaultEncoding(const QString &encoding)
Sets the default encoding to use for newly created files.
QThread * thread()
Returns the thread in which the context lives.
void setFeedback(QgsProcessingFeedback *feedback)
Sets an associated feedback object.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void setFlags(QgsProcessingContext::Flags flags)
Sets flags for the context.
void setProject(QgsProject *project)
Sets the project in which the algorithm will be executed.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
QMap< QString, QgsProcessingContext::LayerDetails > layersToLoadOnCompletion() const
Returns a map of layers (by ID or datasource) to LayerDetails, to load into the canvas upon completio...
void pushToThread(QThread *thread)
Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore...
Flag
Flags that affect how processing algorithms are run.
QgsProcessingFeedback * feedback()
Returns the associated feedback object.
bool willLoadLayerOnCompletion(const QString &layer) const
Returns true if the given layer (by ID or datasource) will be loaded into the current project upon co...
const QgsExpressionContext & expressionContext() const
Returns the expression context.
QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const
Returns the behavior used for checking invalid geometries in input layers.
void copyThreadSafeSettings(const QgsProcessingContext &other)
Copies all settings which are safe for use across different threads from other to this context.
QgsProcessingContext & operator=(const QgsProcessingContext &other)=delete
QgsProcessingContext cannot be copied.
void setInvalidGeometryCallback(const std::function< void(const QgsFeature &) > &callback)
Sets a callback function to use when encountering an invalid geometry and invalidGeometryCheck() is s...
void setPreferredVectorFormat(const QString &format)
Sets the preferred vector format to use for vector outputs.
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.
QString preferredVectorFormat() const
Returns the preferred vector format to use for vector outputs.
QgsProcessingContext::LayerDetails & layerToLoadOnCompletionDetails(const QString &layer)
Returns a reference to the details for a given layer which is loaded on completion of the algorithm o...
void setPreferredRasterFormat(const QString &format)
Sets the preferred raster format to use for vector outputs.
Base class for providing feedback from a processing algorithm.
An interface for layer post-processing handlers for execution following a processing algorithm operat...
virtual ~QgsProcessingLayerPostProcessorInterface()=default
virtual void postProcessLayer(QgsMapLayer *layer, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0
Post-processes the specified layer, following successful execution of a processing algorithm.
LayerHint
Layer type hints.
@ UnknownType
Unknown layer type.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsCoordinateTransformContext transformContext
DistanceUnit
Units of distance.
@ DistanceUnknownUnit
Unknown distance unit.
@ AreaUnknownUnit
Unknown areal unit.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.