Skip to content

Commit f1ac0be

Browse files
committed
Fix processing setting to use filename as layer name
1 parent 7879c0a commit f1ac0be

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

python/plugins/processing/gui/Postprocessing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
5858
try:
5959
layer = QgsProcessingUtils.mapLayerFromString(l, context)
6060
if layer is not None:
61-
layer.setName(details.name)
61+
if not ProcessingConfig.getSetting(ProcessingConfig.USE_FILENAME_AS_LAYER_NAME):
62+
layer.setName(details.name)
6263

6364
style = None
6465
if details.outputName:

src/core/processing/qgsprocessingutils.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,16 @@ QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string )
161161
ProjectionSettingRestorer restorer;
162162
( void )restorer; // no warnings
163163

164+
QFileInfo fi( string );
165+
QString name = fi.baseName();
166+
164167
// brute force attempt to load a matching layer
165-
std::unique_ptr< QgsVectorLayer > layer( new QgsVectorLayer( string, QStringLiteral( "temp" ), QStringLiteral( "ogr" ), false ) );
168+
std::unique_ptr< QgsVectorLayer > layer( new QgsVectorLayer( string, name, QStringLiteral( "ogr" ), false ) );
166169
if ( layer->isValid() )
167170
{
168171
return layer.release();
169172
}
170-
std::unique_ptr< QgsRasterLayer > rasterLayer( new QgsRasterLayer( string, QStringLiteral( "temp" ), QStringLiteral( "gdal" ), false ) );
173+
std::unique_ptr< QgsRasterLayer > rasterLayer( new QgsRasterLayer( string, name, QStringLiteral( "gdal" ), false ) );
171174
if ( rasterLayer->isValid() )
172175
{
173176
return rasterLayer.release();

tests/src/core/testqgsprocessing.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,15 @@ void TestQgsProcessing::mapLayers()
684684
QgsMapLayer *l = QgsProcessingUtils::loadMapLayerFromString( raster );
685685
QVERIFY( l->isValid() );
686686
QCOMPARE( l->type(), QgsMapLayer::RasterLayer );
687+
QCOMPARE( l->name(), QStringLiteral( "landsat" ) );
688+
687689
delete l;
688690

689691
//test with vector
690692
l = QgsProcessingUtils::loadMapLayerFromString( vector );
691693
QVERIFY( l->isValid() );
692694
QCOMPARE( l->type(), QgsMapLayer::VectorLayer );
695+
QCOMPARE( l->name(), QStringLiteral( "points" ) );
693696
delete l;
694697

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

0 commit comments

Comments
 (0)