@@ -3947,6 +3947,9 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
39473947 QString layertype = layer->dataProvider ()->storageType ();
39483948
39493949 QgsSublayersDialog::LayerDefinitionList list;
3950+ QMap< QString, int > mapLayerNameToCount;
3951+ bool uniqueNames = true ;
3952+ int lastLayerId = -1 ;
39503953 Q_FOREACH ( const QString& sublayer, sublayers )
39513954 {
39523955 // OGR provider returns items in this format:
@@ -3967,6 +3970,13 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
39673970 def.layerName = elements[1 ];
39683971 def.count = elements[2 ].toInt ();
39693972 def.type = elements[3 ];
3973+ if ( lastLayerId != def.layerId )
3974+ {
3975+ int count = ++mapLayerNameToCount[def.layerName ];
3976+ if ( count > 1 || def.layerName .isEmpty () )
3977+ uniqueNames = false ;
3978+ lastLayerId = def.layerId ;
3979+ }
39703980 list << def;
39713981 }
39723982 else
@@ -4003,7 +4013,16 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
40034013 Q_FOREACH ( const QgsSublayersDialog::LayerDefinition& def, chooseSublayersDialog.selection () )
40044014 {
40054015 QString layerGeometryType = def.type ;
4006- QString composedURI = uri + " |layerid=" + QString::number ( def.layerId );
4016+ QString composedURI = uri;
4017+ if ( uniqueNames )
4018+ {
4019+ composedURI += " |layername=" + def.layerName ;
4020+ }
4021+ else
4022+ {
4023+ // Only use layerId if there are ambiguities with names
4024+ composedURI += " |layerid=" + QString::number ( def.layerId );
4025+ }
40074026
40084027 if ( !layerGeometryType.isEmpty () )
40094028 {
0 commit comments