Skip to content

Commit

Permalink
Merge pull request #6827 from borysiasty/gpkgfix
Browse files Browse the repository at this point in the history
Backport 1822b76 & 24de819 - use layername instead of layerid in multilayer OGR source URI
  • Loading branch information
borysiasty authored Apr 20, 2018
2 parents c577b65 + cdb4f85 commit 6564aec
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3947,6 +3947,9 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
QString layertype = layer->dataProvider()->storageType();

QgsSublayersDialog::LayerDefinitionList list;
QMap< QString, int > mapLayerNameToCount;
bool uniqueNames = true;
int lastLayerId = -1;
Q_FOREACH ( const QString& sublayer, sublayers )
{
// OGR provider returns items in this format:
Expand All @@ -3967,6 +3970,13 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
def.layerName = elements[1];
def.count = elements[2].toInt();
def.type = elements[3];
if ( lastLayerId != def.layerId )
{
int count = ++mapLayerNameToCount[def.layerName];
if ( count > 1 || def.layerName.isEmpty() )
uniqueNames = false;
lastLayerId = def.layerId;
}
list << def;
}
else
Expand Down Expand Up @@ -4003,7 +4013,16 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
Q_FOREACH ( const QgsSublayersDialog::LayerDefinition& def, chooseSublayersDialog.selection() )
{
QString layerGeometryType = def.type;
QString composedURI = uri + "|layerid=" + QString::number( def.layerId );
QString composedURI = uri;
if ( uniqueNames )
{
composedURI += "|layername=" + def.layerName;
}
else
{
// Only use layerId if there are ambiguities with names
composedURI += "|layerid=" + QString::number( def.layerId );
}

if ( !layerGeometryType.isEmpty() )
{
Expand Down

0 comments on commit 6564aec

Please sign in to comment.