Skip to content

Commit 3d307b4

Browse files
committed
Improve name of memory layers output from processing
1 parent 7451422 commit 3d307b4

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/core/processing/qgsprocessingparameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3163,7 +3163,7 @@ bool QgsProcessingParameterFeatureSink::fromVariantMap( const QVariantMap &map )
31633163
QString QgsProcessingParameterFeatureSink::generateTemporaryDestination() const
31643164
{
31653165
if ( supportsNonFileBasedOutputs() )
3166-
return QStringLiteral( "memory:" );
3166+
return QStringLiteral( "memory:%1" ).arg( description() );
31673167
else
31683168
return QgsProcessingDestinationParameter::generateTemporaryDestination();
31693169
}

src/core/processing/qgsprocessingutils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
371371

372372
if ( destination.isEmpty() || destination.startsWith( QStringLiteral( "memory:" ) ) )
373373
{
374+
// strip "memory:" from start of destination
375+
if ( destination.startsWith( QStringLiteral( "memory:" ) ) )
376+
destination = destination.mid( 7 );
377+
378+
if ( destination.isEmpty() )
379+
destination = QStringLiteral( "output" );
380+
374381
// memory provider cannot be used with QgsVectorLayerImport - so create layer manually
375382
std::unique_ptr< QgsVectorLayer > layer( QgsMemoryProviderUtils::createMemoryLayer( destination, fields, geometryType, crs ) );
376383
if ( !layer || !layer->isValid() )

tests/src/analysis/testqgsprocessing.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,24 @@ void TestQgsProcessing::createFeatureSink()
13081308
QVERIFY( layer );
13091309
QCOMPARE( static_cast< QgsProxyFeatureSink *>( sink.get() )->destinationSink(), layer->dataProvider() );
13101310
QCOMPARE( layer->dataProvider()->name(), QStringLiteral( "memory" ) );
1311-
QCOMPARE( layer->name(), QStringLiteral( "memory:mylayer" ) );
1311+
QCOMPARE( layer->name(), QStringLiteral( "mylayer" ) );
1312+
QCOMPARE( destination, layer->id() );
1313+
QCOMPARE( context.temporaryLayerStore()->mapLayer( layer->id() ), layer ); // layer should be in store
1314+
QCOMPARE( layer->featureCount(), 0L );
1315+
QVERIFY( sink->addFeature( f ) );
1316+
QCOMPARE( layer->featureCount(), 1L );
1317+
context.temporaryLayerStore()->removeAllMapLayers();
1318+
layer = nullptr;
1319+
1320+
// nameless memory layer
1321+
destination = QStringLiteral( "memory:" );
1322+
sink.reset( QgsProcessingUtils::createFeatureSink( destination, context, QgsFields(), QgsWkbTypes::Point, QgsCoordinateReferenceSystem() ) );
1323+
QVERIFY( sink.get() );
1324+
layer = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::mapLayerFromString( destination, context, false ) );
1325+
QVERIFY( layer );
1326+
QCOMPARE( static_cast< QgsProxyFeatureSink *>( sink.get() )->destinationSink(), layer->dataProvider() );
1327+
QCOMPARE( layer->dataProvider()->name(), QStringLiteral( "memory" ) );
1328+
QCOMPARE( layer->name(), QString( "output" ) ); // should fall back to "output" name
13121329
QCOMPARE( destination, layer->id() );
13131330
QCOMPARE( context.temporaryLayerStore()->mapLayer( layer->id() ), layer ); // layer should be in store
13141331
QCOMPARE( layer->featureCount(), 0L );
@@ -1327,7 +1344,7 @@ void TestQgsProcessing::createFeatureSink()
13271344
QVERIFY( layer );
13281345
QCOMPARE( static_cast< QgsProxyFeatureSink *>( sink.get() )->destinationSink(), layer->dataProvider() );
13291346
QCOMPARE( layer->dataProvider()->name(), QStringLiteral( "memory" ) );
1330-
QCOMPARE( layer->name(), QStringLiteral( "memory:mylayer" ) );
1347+
QCOMPARE( layer->name(), QStringLiteral( "mylayer" ) );
13311348
QCOMPARE( layer->wkbType(), QgsWkbTypes::PointZM );
13321349
QCOMPARE( layer->crs().authid(), QStringLiteral( "EPSG:3111" ) );
13331350
QCOMPARE( layer->fields().size(), 1 );
@@ -5369,7 +5386,7 @@ void TestQgsProcessing::modelExecution()
53695386
model2.addChildAlgorithm( alg2c2 );
53705387
params = model2.parametersForChildAlgorithm( model2.childAlgorithm( "cx2" ), modelInputs, childResults, expContext );
53715388
QCOMPARE( params.value( "INPUT" ).toString(), QStringLiteral( "dest.shp" ) );
5372-
QCOMPARE( params.value( "OUTPUT" ).toString(), QStringLiteral( "memory:" ) );
5389+
QCOMPARE( params.value( "OUTPUT" ).toString(), QStringLiteral( "memory:Centroids" ) );
53735390
QCOMPARE( params.count(), 2 );
53745391

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

0 commit comments

Comments
 (0)