diff --git a/python/core/processing/qgsprocessingcontext.sip b/python/core/processing/qgsprocessingcontext.sip index a701fa9d7c84..368acaeb3591 100644 --- a/python/core/processing/qgsprocessingcontext.sip +++ b/python/core/processing/qgsprocessingcontext.sip @@ -214,6 +214,21 @@ Destination project and no errors will occur if feedback is deleted before the context. Ownership of ``feedback`` is not transferred. .. seealso:: setFeedback() +%End + + QThread *thread(); +%Docstring + Returns the thread in which the context lives. +.. seealso:: pushToThread() + :rtype: QThread +%End + + void pushToThread( QThread *thread ); +%Docstring + 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()). +.. seealso:: thread() %End private: diff --git a/src/core/processing/qgsprocessingcontext.h b/src/core/processing/qgsprocessingcontext.h index 4ba4fb5ad759..432ea13f0ebb 100644 --- a/src/core/processing/qgsprocessingcontext.h +++ b/src/core/processing/qgsprocessingcontext.h @@ -310,6 +310,24 @@ class CORE_EXPORT QgsProcessingContext */ void setFeedback( QgsProcessingFeedback *feedback ) { mFeedback = feedback; } + /** + * Returns the thread in which the context lives. + * \see pushToThread() + */ + QThread *thread() { return tempLayerStore.thread(); } + + /** + * Pushes the thread affinity for the context (including all layers contained in the temporaryLayerStore()) into + * another \a thread. This method is only safe to call when the current thread matches the existing thread + * affinity for the context (see thread()). + * \see thread() + */ + void pushToThread( QThread *thread ) + { + Q_ASSERTX( QThread::currentThread() == thread(), "QgsProcessingContext::pushToThread", "Cannot push context to another thread unless the current thread matches the existing context thread affinity" ); + tempLayerStore.moveToThread( thread ); + } + private: QgsProcessingContext::Flags mFlags = 0;