Skip to content
Permalink
Browse files

Fix processing setting to use filename as layer name

  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent 7879c0a commit f1ac0be86769e924624cb87b48e0ef69a0da1387
@@ -58,7 +58,8 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
try:
layer = QgsProcessingUtils.mapLayerFromString(l, context)
if layer is not None:
layer.setName(details.name)
if not ProcessingConfig.getSetting(ProcessingConfig.USE_FILENAME_AS_LAYER_NAME):
layer.setName(details.name)

style = None
if details.outputName:
@@ -161,13 +161,16 @@ QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string )
ProjectionSettingRestorer restorer;
( void )restorer; // no warnings

QFileInfo fi( string );
QString name = fi.baseName();

// brute force attempt to load a matching layer
std::unique_ptr< QgsVectorLayer > layer( new QgsVectorLayer( string, QStringLiteral( "temp" ), QStringLiteral( "ogr" ), false ) );
std::unique_ptr< QgsVectorLayer > layer( new QgsVectorLayer( string, name, QStringLiteral( "ogr" ), false ) );
if ( layer->isValid() )
{
return layer.release();
}
std::unique_ptr< QgsRasterLayer > rasterLayer( new QgsRasterLayer( string, QStringLiteral( "temp" ), QStringLiteral( "gdal" ), false ) );
std::unique_ptr< QgsRasterLayer > rasterLayer( new QgsRasterLayer( string, name, QStringLiteral( "gdal" ), false ) );
if ( rasterLayer->isValid() )
{
return rasterLayer.release();
@@ -684,12 +684,15 @@ void TestQgsProcessing::mapLayers()
QgsMapLayer *l = QgsProcessingUtils::loadMapLayerFromString( raster );
QVERIFY( l->isValid() );
QCOMPARE( l->type(), QgsMapLayer::RasterLayer );
QCOMPARE( l->name(), QStringLiteral( "landsat" ) );

delete l;

//test with vector
l = QgsProcessingUtils::loadMapLayerFromString( vector );
QVERIFY( l->isValid() );
QCOMPARE( l->type(), QgsMapLayer::VectorLayer );
QCOMPARE( l->name(), QStringLiteral( "points" ) );
delete l;

l = QgsProcessingUtils::loadMapLayerFromString( QString() );
@@ -699,6 +702,7 @@ void TestQgsProcessing::mapLayers()
l = QgsProcessingUtils::loadMapLayerFromString( testDataDir + "multipoint.shp" );
QVERIFY( l->isValid() );
QCOMPARE( l->type(), QgsMapLayer::VectorLayer );
QCOMPARE( l->name(), QStringLiteral( "multipoint" ) );
delete l;
}

0 comments on commit f1ac0be

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