Skip to content

Commit

Permalink
Fix processing setting to use filename as layer name
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent 7879c0a commit f1ac0be
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion python/plugins/processing/gui/Postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions src/core/processing/qgsprocessingutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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;
}

Expand Down

0 comments on commit f1ac0be

Please sign in to comment.