Skip to content

Commit

Permalink
Special handling for aigrid base/group names
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 12, 2021
1 parent ecd185f commit e01dc5d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
21 changes: 8 additions & 13 deletions src/app/qgisapp.cpp
Expand Up @@ -7619,6 +7619,14 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )

const QFileInfo info( fileName );
QString base = info.completeBaseName();

// special handling for .adf files -- use directory as base name, not the unhelpful .adf file name
if ( info.suffix().compare( QLatin1String( "adf" ), Qt::CaseInsensitive ) == 0 )
{
const QString dirName = info.path();
base = QFileInfo( dirName ).completeBaseName();
}

if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
base = QgsMapLayer::formatLayerName( base );
Expand All @@ -7631,19 +7639,6 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
CPLPopErrorHandler();

#if 0
// try to load it as raster
if ( QgsRasterLayer::isValidRasterFileName( fileName ) )
{
// open .adf as a directory
if ( fileName.endsWith( QLatin1String( ".adf" ), Qt::CaseInsensitive ) )
{
QString dirName = fileInfo.path();
ok = addRasterLayer( dirName, QFileInfo( dirName ).completeBaseName() );
}
else
ok = addRasterLayer( fileName, fileInfo.completeBaseName() );
}

// try as a vector
if ( !ok || fileName.endsWith( QLatin1String( ".gpkg" ), Qt::CaseInsensitive ) )
{
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsprovidersublayersdialog.cpp
Expand Up @@ -207,6 +207,13 @@ QString QgsProviderSublayersDialog::groupName() const
const QFileInfo fi( mFilePath );
QString res = fi.completeBaseName();

// special handling for .adf files -- use directory as group name, not the unhelpful .adf file name
if ( fi.suffix().compare( QLatin1String( "adf" ), Qt::CaseInsensitive ) == 0 )
{
const QString dirName = fi.path();
res = QFileInfo( dirName ).completeBaseName();
}

QgsSettings settings;
if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
Expand Down
12 changes: 11 additions & 1 deletion src/providers/mdal/qgsmdalprovider.cpp
Expand Up @@ -1090,7 +1090,17 @@ QList<QgsProviderSublayerDetails> QgsMdalProviderMetadata::querySublayers( const
if ( details.name().isEmpty() )
{
// use file name as layer name if no layer name available from mdal
details.setName( info.completeBaseName() );

// special handling for .adf files -- use directory as group name, not the unhelpful .adf file name
if ( info.suffix().compare( QLatin1String( "adf" ), Qt::CaseInsensitive ) == 0 )
{
const QString dirName = info.path();
details.setName( QFileInfo( dirName ).completeBaseName() );
}
else
{
details.setName( info.completeBaseName() );
}
}

res << details;
Expand Down

0 comments on commit e01dc5d

Please sign in to comment.