If all layer names are the same, remove them from the sub layer uris

This commit is contained in:
Nyall Dawson 2021-06-26 10:27:18 +10:00
parent 6a0497f58f
commit 9076e64afb

View File

@ -1077,6 +1077,26 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
res << QgsOgrProviderUtils::querySubLayerList( i, i == 0 ? firstLayer.get() : layer.get(), driverName, flags, false, uri, false, feedback );
}
// if all layernames are equal, we remove them from the uris
QSet< QString > layerNames;
for ( const QgsProviderSublayerDetails &details : std::as_const( res ) )
{
const QVariantMap parts = decodeUri( details.uri() );
layerNames.insert( parts.value( QStringLiteral( "layerName" ) ).toString() );
}
if ( layerNames.count() == 1 )
{
// all layer names are the same, so remove them from uris
for ( int i = 0; i < res.size(); ++i )
{
QVariantMap parts = decodeUri( res.at( i ).uri() );
parts.remove( QStringLiteral( "layerName" ) );
res[ i ].setUri( encodeUri( parts ) );
}
}
return res;
}
}