Skip to content
Permalink
Browse files

Add method to copy thread safe settings between processing contexts

  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent 6c6f646 commit d20c68d3f136d769d6933a09dd7400075cd96e86
@@ -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.
@@ -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()
@@ -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" );

0 comments on commit d20c68d

Please sign in to comment.
You can’t perform that action at this time.