Skip to content
Permalink
Browse files

Add a method to take result layers (and ownership) from processing co…

…ntext
  • Loading branch information
nyalldawson committed Jul 6, 2017
1 parent db816ec commit 70cc19687d4f681d218305fe3eb88dc6d718f5a7
@@ -245,6 +245,15 @@ Destination project
thread() affinity, and that thread is the current thread.
%End

QgsMapLayer *takeResultLayer( const QString &id ) /TransferBack/;
%Docstring
Takes the result map layer with matching ``id`` from the context and
transfers ownership of it back to the caller. This method can be used
to remove temporary layers which are not required for further processing
from a context.
:rtype: QgsMapLayer
%End

private:
QgsProcessingContext( const QgsProcessingContext &other );
};
@@ -356,6 +356,17 @@ class CORE_EXPORT QgsProcessingContext
tempLayerStore.transferLayersFromStore( context.temporaryLayerStore() );
}

/**
* Takes the result map layer with matching \a id from the context and
* transfers ownership of it back to the caller. This method can be used
* to remove temporary layers which are not required for further processing
* from a context.
*/
QgsMapLayer *takeResultLayer( const QString &id ) SIP_TRANSFERBACK
{
return tempLayerStore.takeMapLayer( tempLayerStore.mapLayer( id ) );
}

private:

QgsProcessingContext::Flags mFlags = 0;
@@ -639,6 +639,19 @@ void TestQgsProcessing::context()
QCOMPARE( context2.layersToLoadOnCompletion().count(), 2 );
QCOMPARE( context2.layersToLoadOnCompletion().keys().at( 0 ), v1->id() );
QCOMPARE( context2.layersToLoadOnCompletion().keys().at( 1 ), v2->id() );

// take result layer
QgsMapLayer *result = context2.takeResultLayer( v1->id() );
QCOMPARE( result, v1 );
QString id = v1->id();
delete v1;
QVERIFY( !context2.temporaryLayerStore()->mapLayer( id ) );
QVERIFY( !context2.takeResultLayer( v1->id() ) );
result = context2.takeResultLayer( v2->id() );
QCOMPARE( result, v2 );
id = v2->id();
delete v2;
QVERIFY( !context2.temporaryLayerStore()->mapLayer( id ) );
}

void TestQgsProcessing::mapLayers()

0 comments on commit 70cc196

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