Skip to content

Commit

Permalink
Backport critical part of 1822b76 and 24de819 to 2.18 in order to pre…
Browse files Browse the repository at this point in the history
…vent gpkg layers from being accidentally corrupted.
  • Loading branch information
borysiasty committed Apr 19, 2018
1 parent 673fafb commit cdb4f85
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 cdb4f85

Please sign in to comment.