18#ifndef QGSPROCESSINGCONTEXT_H
19#define QGSPROCESSINGCONTEXT_H
55 Q_DECLARE_FLAGS( Flags, Flag )
86 mFlags = other.mFlags;
87 mProject = other.mProject;
88 mTransformContext = other.mTransformContext;
89 mExpressionContext = other.mExpressionContext;
91 mInvalidGeometryCallback = other.mInvalidGeometryCallback;
92 mUseDefaultInvalidGeometryCallback = other.mUseDefaultInvalidGeometryCallback;
93 mInvalidGeometryCheck = other.mInvalidGeometryCheck;
94 mTransformErrorCallback = other.mTransformErrorCallback;
95 mDefaultEncoding = other.mDefaultEncoding;
96 mFeedback = other.mFeedback;
97 mPreferredVectorFormat = other.mPreferredVectorFormat;
98 mPreferredRasterFormat = other.mPreferredRasterFormat;
99 mEllipsoid = other.mEllipsoid;
100 mDistanceUnit = other.mDistanceUnit;
101 mAreaUnit = other.mAreaUnit;
102 mLogLevel = other.mLogLevel;
103 mTemporaryFolderOverride = other.mTemporaryFolderOverride;
104 mMaximumThreads = other.mMaximumThreads;
111 QgsProcessingContext::Flags
flags()
const {
return mFlags; }
117 void setFlags( QgsProcessingContext::Flags flags ) { mFlags = flags; }
139 if ( mEllipsoid.isEmpty() )
140 mEllipsoid = mProject->ellipsoid();
141 if ( mDistanceUnit == Qgis::DistanceUnit::Unknown )
142 mDistanceUnit = mProject->distanceUnits();
143 if ( mAreaUnit == Qgis::AreaUnit::Unknown )
144 mAreaUnit = mProject->areaUnits();
185 QString ellipsoid()
const;
195 void setEllipsoid(
const QString &ellipsoid );
243 QgsDateTimeRange currentTimeRange()
const;
251 void setCurrentTimeRange(
const QgsDateTimeRange ¤tTimeRange );
273 , outputName( outputName )
274 , layerTypeHint( layerTypeHint )
294 bool forceName =
false;
315 int layerSortKey = 0;
346 void setOutputLayerName(
QgsMapLayer *layer )
const;
367 return mLayersToLoadOnCompletion;
381 return mLayersToLoadOnCompletion.contains( layer );
391 void setLayersToLoadOnCompletion(
const QMap< QString, QgsProcessingContext::LayerDetails > &layers );
418 return mLayersToLoadOnCompletion[ layer ];
445 void setInvalidGeometryCallback( SIP_PYCALLABLE / AllowNone / );
447 Py_BEGIN_ALLOW_THREADS
449 sipCpp->setInvalidGeometryCallback( [a0](
const QgsFeature &arg )
452 Py_XDECREF( sipCallMethod( NULL, a0,
"D", &arg, sipType_QgsFeature, NULL ) );
486 void setTransformErrorCallback( SIP_PYCALLABLE / AllowNone / );
488 Py_BEGIN_ALLOW_THREADS
490 sipCpp->setTransformErrorCallback( [a0](
const QgsFeature &arg )
493 Py_XDECREF( sipCallMethod( NULL, a0,
"D", &arg, sipType_QgsFeature, NULL ) );
542 QThread *
thread() {
return tempLayerStore.thread(); }
553 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" );
554 tempLayerStore.moveToThread( thread );
576 QgsMapLayer *getMapLayer(
const QString &identifier );
668 LogLevel logLevel()
const;
676 void setLogLevel( LogLevel level );
687 QString temporaryFolder()
const;
698 void setTemporaryFolder(
const QString &folder );
711 int maximumThreads()
const;
728 void setMaximumThreads(
int threads );
735 QVariantMap exportToMap()
const;
744 IncludeProjectPath = 1 << 0,
746 Q_DECLARE_FLAGS( ProcessArgumentFlags, ProcessArgumentFlag )
753 QStringList asQgisProcessArguments( QgsProcessingContext::ProcessArgumentFlags flags = QgsProcessingContext::ProcessArgumentFlags() )
const;
757 QgsProcessingContext::Flags mFlags = QgsProcessingContext::Flags();
758 QPointer< QgsProject > mProject;
765 QgsDateTimeRange mCurrentTimeRange;
772 bool mUseDefaultInvalidGeometryCallback =
true;
773 std::function< void(
const QgsFeature & ) > mInvalidGeometryCallback;
775 std::function< void(
const QgsFeature & ) > mTransformErrorCallback;
776 QString mDefaultEncoding;
777 QMap< QString, LayerDetails > mLayersToLoadOnCompletion;
779 QPointer< QgsProcessingFeedback > mFeedback;
781 QString mPreferredVectorFormat;
782 QString mPreferredRasterFormat;
784 LogLevel mLogLevel = DefaultLevel;
786 QString mTemporaryFolderOverride;
787 int mMaximumThreads = QThread::idealThreadCount();
DistanceUnit
Units of distance.
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...
void setLoadedLayerStore(QgsMapLayerStore *store)
Sets the destination layer store for any layers loaded during expression evaluation.
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 unique ID, geometry and a list of field...
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.
QString groupName
Optional name for a layer tree group under which to place the layer when loading it into a project.
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.
QThread * thread()
Returns the thread in which the context lives.
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...
QgsProcessingFeedback * feedback()
Returns the associated feedback object.
QString preferredRasterFormat() const
Returns the preferred raster format to use for vector outputs.
QgsProcessingContext::Flags flags() const
Returns any flags set in the context.
ProcessArgumentFlag
Flags controlling the results given by asQgisProcessArguments().
LogLevel
Logging level for algorithms to use when pushing feedback messages.
@ Verbose
Verbose logging.
QgsExpressionContext & expressionContext()
Returns the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context.
const QgsExpressionContext & expressionContext() const
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.
void setFeedback(QgsProcessingFeedback *feedback)
Sets an associated feedback object.
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.
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...
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
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.
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.
QgsProcessingContext & operator=(const QgsProcessingContext &other)=delete
QgsProcessingContext cannot be copied.
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.
std::function< void(const QgsFeature &) > transformErrorCallback() const
Returns the callback function to use when encountering a transform error when iterating features.
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
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.