Skip to content

Commit

Permalink
[FEATURE] [UI] OGR source select: add a dynamic layout to define open…
Browse files Browse the repository at this point in the history
… options
  • Loading branch information
rouault authored and nyalldawson committed Oct 5, 2020
1 parent f3476d9 commit 46ce308
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 39 deletions.
21 changes: 15 additions & 6 deletions src/app/qgisapp.cpp
Expand Up @@ -5434,8 +5434,9 @@ static void setupVectorLayer( const QString &vectorLayerPath,
{
auto uriParts = QgsProviderRegistry::instance()->decodeUri(
layer->providerType(), layer->dataProvider()->dataSourceUri() );
QString composedURI( uriParts.value( QStringLiteral( "path" ) ).toString() );
composedURI += "|layername=" + rawLayerName;
uriParts.insert( QStringLiteral( "layerName" ), rawLayerName );
QString composedURI = QgsProviderRegistry::instance()->encodeUri(
layer->providerType(), uriParts );

auto newLayer = qgis::make_unique<QgsVectorLayer>( composedURI, layer->name(), QStringLiteral( "ogr" ), options );
if ( newLayer && newLayer->isValid() )
Expand Down Expand Up @@ -6108,30 +6109,38 @@ QList<QgsMapLayer *> QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer, con
auto uriParts = QgsProviderRegistry::instance()->decodeUri(
layer->providerType(), layer->dataProvider()->dataSourceUri() );
QString uri( uriParts.value( QStringLiteral( "path" ) ).toString() );
QStringList openOptions( uriParts.value( QStringLiteral( "openOptions" ) ).toStringList() );

// The uri must contain the actual uri of the vectorLayer from which we are
// going to load the sublayers.
QString fileName = QFileInfo( uri ).baseName();
const auto constSelection = chooseSublayersDialog.selection();
for ( const QgsSublayersDialog::LayerDefinition &def : constSelection )
{
QVariantMap newUriParts;
newUriParts.insert( QStringLiteral( "path" ), uri );
QString layerGeometryType = def.type;
QString composedURI = uri;
if ( uniqueNames )
{
composedURI += "|layername=" + def.layerName;
newUriParts.insert( QStringLiteral( "layerName" ), def.layerName );
}
else
{
// Only use layerId if there are ambiguities with names
composedURI += "|layerid=" + QString::number( def.layerId );
newUriParts.insert( QStringLiteral( "layerId" ), QString::number( def.layerId ) );
}

if ( !layerGeometryType.isEmpty() )
{
composedURI += "|geometrytype=" + layerGeometryType;
newUriParts.insert( QStringLiteral( "geometryType" ), layerGeometryType );
}
if ( !openOptions.isEmpty() )
{
newUriParts.insert( QStringLiteral( "openOptions" ), openOptions );
}

QString composedURI = QgsProviderRegistry::instance()->encodeUri(
layer->providerType(), newUriParts );
QgsDebugMsgLevel( "Creating new vector layer using " + composedURI, 2 );

// if user has opted to add sublayers to a group, then we don't need to include the
Expand Down

0 comments on commit 46ce308

Please sign in to comment.