Skip to content

Commit d20c68d

Browse files
committedJul 6, 2017
Add method to copy thread safe settings between processing contexts
1 parent 6c6f646 commit d20c68d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
 

‎python/core/processing/qgsprocessingcontext.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class QgsProcessingContext
3838
%End
3939

4040

41+
void copyThreadSafeSettings( const QgsProcessingContext &other );
42+
%Docstring
43+
Copies all settings which are safe for use across different threads from
44+
``other`` to this context.
45+
%End
46+
4147
QgsProcessingContext::Flags flags() const;
4248
%Docstring
4349
Returns any flags set in the context.

‎src/core/processing/qgsprocessingcontext.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ class CORE_EXPORT QgsProcessingContext
6666
//! QgsProcessingContext cannot be copied
6767
QgsProcessingContext &operator=( const QgsProcessingContext &other ) = delete;
6868

69+
/**
70+
* Copies all settings which are safe for use across different threads from
71+
* \a other to this context.
72+
*/
73+
void copyThreadSafeSettings( const QgsProcessingContext &other )
74+
{
75+
mFlags = other.mFlags;
76+
mProject = other.mProject;
77+
mExpressionContext = other.mExpressionContext;
78+
mInvalidGeometryCallback = other.mInvalidGeometryCallback;
79+
mInvalidGeometryCheck = other.mInvalidGeometryCheck;
80+
mTransformErrorCallback = other.mTransformErrorCallback;
81+
mDefaultEncoding = other.mDefaultEncoding;
82+
mFeedback = other.mFeedback;
83+
}
84+
6985
/**
7086
* Returns any flags set in the context.
7187
* \see setFlags()

‎tests/src/core/testqgsprocessing.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,13 @@ void TestQgsProcessing::context()
583583
context.setInvalidGeometryCheck( QgsFeatureRequest::GeometrySkipInvalid );
584584
QCOMPARE( context.invalidGeometryCheck(), QgsFeatureRequest::GeometrySkipInvalid );
585585

586+
QgsProcessingContext context2;
587+
context2.copyThreadSafeSettings( context );
588+
QCOMPARE( context2.defaultEncoding(), context.defaultEncoding() );
589+
QCOMPARE( context2.invalidGeometryCheck(), context.invalidGeometryCheck() );
590+
QCOMPARE( context2.flags(), context.flags() );
591+
QCOMPARE( context2.project(), context.project() );
592+
586593
// layers to load on completion
587594
QgsVectorLayer *v1 = new QgsVectorLayer( "Polygon", "V1", "memory" );
588595
QgsVectorLayer *v2 = new QgsVectorLayer( "Polygon", "V2", "memory" );

0 commit comments

Comments
 (0)
Please sign in to comment.