@@ -3947,6 +3947,9 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
3947
3947
QString layertype = layer->dataProvider ()->storageType ();
3948
3948
3949
3949
QgsSublayersDialog::LayerDefinitionList list;
3950
+ QMap< QString, int > mapLayerNameToCount;
3951
+ bool uniqueNames = true ;
3952
+ int lastLayerId = -1 ;
3950
3953
Q_FOREACH ( const QString& sublayer, sublayers )
3951
3954
{
3952
3955
// OGR provider returns items in this format:
@@ -3967,6 +3970,13 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
3967
3970
def.layerName = elements[1 ];
3968
3971
def.count = elements[2 ].toInt ();
3969
3972
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
+ }
3970
3980
list << def;
3971
3981
}
3972
3982
else
@@ -4003,7 +4013,16 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
4003
4013
Q_FOREACH ( const QgsSublayersDialog::LayerDefinition& def, chooseSublayersDialog.selection () )
4004
4014
{
4005
4015
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
+ }
4007
4026
4008
4027
if ( !layerGeometryType.isEmpty () )
4009
4028
{
0 commit comments