Skip to content

Commit

Permalink
Add method to copy thread safe settings between processing contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 6c6f646 commit d20c68d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/core/processing/qgsprocessingcontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class QgsProcessingContext
%End


void copyThreadSafeSettings( const QgsProcessingContext &other );
%Docstring
Copies all settings which are safe for use across different threads from
``other`` to this context.
%End

QgsProcessingContext::Flags flags() const;
%Docstring
Returns any flags set in the context.
Expand Down
16 changes: 16 additions & 0 deletions src/core/processing/qgsprocessingcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ class CORE_EXPORT QgsProcessingContext
//! QgsProcessingContext cannot be copied
QgsProcessingContext &operator=( const QgsProcessingContext &other ) = delete;

/**
* Copies all settings which are safe for use across different threads from
* \a other to this context.
*/
void copyThreadSafeSettings( const QgsProcessingContext &other )
{
mFlags = other.mFlags;
mProject = other.mProject;
mExpressionContext = other.mExpressionContext;
mInvalidGeometryCallback = other.mInvalidGeometryCallback;
mInvalidGeometryCheck = other.mInvalidGeometryCheck;
mTransformErrorCallback = other.mTransformErrorCallback;
mDefaultEncoding = other.mDefaultEncoding;
mFeedback = other.mFeedback;
}

/**
* Returns any flags set in the context.
* \see setFlags()
Expand Down
7 changes: 7 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@ void TestQgsProcessing::context()
context.setInvalidGeometryCheck( QgsFeatureRequest::GeometrySkipInvalid );
QCOMPARE( context.invalidGeometryCheck(), QgsFeatureRequest::GeometrySkipInvalid );

QgsProcessingContext context2;
context2.copyThreadSafeSettings( context );
QCOMPARE( context2.defaultEncoding(), context.defaultEncoding() );
QCOMPARE( context2.invalidGeometryCheck(), context.invalidGeometryCheck() );
QCOMPARE( context2.flags(), context.flags() );
QCOMPARE( context2.project(), context.project() );

// layers to load on completion
QgsVectorLayer *v1 = new QgsVectorLayer( "Polygon", "V1", "memory" );
QgsVectorLayer *v2 = new QgsVectorLayer( "Polygon", "V2", "memory" );
Expand Down

0 comments on commit d20c68d

Please sign in to comment.