Skip to content
Permalink
Browse files

Improve name of memory layers output from processing

  • Loading branch information
nyalldawson committed Nov 26, 2017
1 parent 7451422 commit 3d307b41090f3202a6090bdbf6544765168e0ec9
@@ -3163,7 +3163,7 @@ bool QgsProcessingParameterFeatureSink::fromVariantMap( const QVariantMap &map )
QString QgsProcessingParameterFeatureSink::generateTemporaryDestination() const
{
if ( supportsNonFileBasedOutputs() )
return QStringLiteral( "memory:" );
return QStringLiteral( "memory:%1" ).arg( description() );
else
return QgsProcessingDestinationParameter::generateTemporaryDestination();
}
@@ -371,6 +371,13 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs

if ( destination.isEmpty() || destination.startsWith( QStringLiteral( "memory:" ) ) )
{
// strip "memory:" from start of destination
if ( destination.startsWith( QStringLiteral( "memory:" ) ) )
destination = destination.mid( 7 );

if ( destination.isEmpty() )
destination = QStringLiteral( "output" );

// memory provider cannot be used with QgsVectorLayerImport - so create layer manually
std::unique_ptr< QgsVectorLayer > layer( QgsMemoryProviderUtils::createMemoryLayer( destination, fields, geometryType, crs ) );
if ( !layer || !layer->isValid() )
@@ -1308,7 +1308,24 @@ void TestQgsProcessing::createFeatureSink()
QVERIFY( layer );
QCOMPARE( static_cast< QgsProxyFeatureSink *>( sink.get() )->destinationSink(), layer->dataProvider() );
QCOMPARE( layer->dataProvider()->name(), QStringLiteral( "memory" ) );
QCOMPARE( layer->name(), QStringLiteral( "memory:mylayer" ) );
QCOMPARE( layer->name(), QStringLiteral( "mylayer" ) );
QCOMPARE( destination, layer->id() );
QCOMPARE( context.temporaryLayerStore()->mapLayer( layer->id() ), layer ); // layer should be in store
QCOMPARE( layer->featureCount(), 0L );
QVERIFY( sink->addFeature( f ) );
QCOMPARE( layer->featureCount(), 1L );
context.temporaryLayerStore()->removeAllMapLayers();
layer = nullptr;

// nameless memory layer
destination = QStringLiteral( "memory:" );
sink.reset( QgsProcessingUtils::createFeatureSink( destination, context, QgsFields(), QgsWkbTypes::Point, QgsCoordinateReferenceSystem() ) );
QVERIFY( sink.get() );
layer = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( destination, context, false ) );
QVERIFY( layer );
QCOMPARE( static_cast< QgsProxyFeatureSink *>( sink.get() )->destinationSink(), layer->dataProvider() );
QCOMPARE( layer->dataProvider()->name(), QStringLiteral( "memory" ) );
QCOMPARE( layer->name(), QString( "output" ) ); // should fall back to "output" name
QCOMPARE( destination, layer->id() );
QCOMPARE( context.temporaryLayerStore()->mapLayer( layer->id() ), layer ); // layer should be in store
QCOMPARE( layer->featureCount(), 0L );
@@ -1327,7 +1344,7 @@ void TestQgsProcessing::createFeatureSink()
QVERIFY( layer );
QCOMPARE( static_cast< QgsProxyFeatureSink *>( sink.get() )->destinationSink(), layer->dataProvider() );
QCOMPARE( layer->dataProvider()->name(), QStringLiteral( "memory" ) );
QCOMPARE( layer->name(), QStringLiteral( "memory:mylayer" ) );
QCOMPARE( layer->name(), QStringLiteral( "mylayer" ) );
QCOMPARE( layer->wkbType(), QgsWkbTypes::PointZM );
QCOMPARE( layer->crs().authid(), QStringLiteral( "EPSG:3111" ) );
QCOMPARE( layer->fields().size(), 1 );
@@ -5369,7 +5386,7 @@ void TestQgsProcessing::modelExecution()
model2.addChildAlgorithm( alg2c2 );
params = model2.parametersForChildAlgorithm( model2.childAlgorithm( "cx2" ), modelInputs, childResults, expContext );
QCOMPARE( params.value( "INPUT" ).toString(), QStringLiteral( "dest.shp" ) );
QCOMPARE( params.value( "OUTPUT" ).toString(), QStringLiteral( "memory:" ) );
QCOMPARE( params.value( "OUTPUT" ).toString(), QStringLiteral( "memory:Centroids" ) );
QCOMPARE( params.count(), 2 );

variables = model2.variablesForChildAlgorithm( "cx2", context );

0 comments on commit 3d307b4

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