Skip to content
Permalink
Browse files
Use GDAL 3.4+ API to flag sublayers as system tables
  • Loading branch information
nyalldawson committed Aug 30, 2021
1 parent d42dab9 commit fd7601d154965ab63a02105c9338b740be1698e2
@@ -630,7 +630,7 @@ QList<QgsProviderSublayerDetails> QgsOgrProvider::_subLayers( Qgis::SublayerQuer
const size_t totalLayerCount = layerCount();
if ( mOgrLayer && ( mIsSubLayer || totalLayerCount == 1 ) )
{
mSubLayerList << QgsOgrProviderUtils::querySubLayerList( mLayerIndex, mOgrLayer, mGDALDriverName, flags, dataSourceUri(), totalLayerCount == 1 );
mSubLayerList << QgsOgrProviderUtils::querySubLayerList( mLayerIndex, mOgrLayer, nullptr, mGDALDriverName, flags, dataSourceUri(), totalLayerCount == 1 );
}
else
{
@@ -653,7 +653,7 @@ QList<QgsProviderSublayerDetails> QgsOgrProvider::_subLayers( Qgis::SublayerQuer
if ( !layer )
continue;

mSubLayerList << QgsOgrProviderUtils::querySubLayerList( i, layer.get(), mGDALDriverName, flags, dataSourceUri(), totalLayerCount == 1 );
mSubLayerList << QgsOgrProviderUtils::querySubLayerList( i, layer.get(), nullptr, mGDALDriverName, flags, dataSourceUri(), totalLayerCount == 1 );
if ( firstLayer == nullptr )
{
firstLayer = std::move( layer );
@@ -1191,14 +1191,22 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
if ( !firstLayer )
return {};

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QMutex *mutex = nullptr;
#else
QRecursiveMutex *mutex = nullptr;
#endif
GDALDatasetH hDS = firstLayer->getDatasetHandleAndMutex( mutex );
QMutexLocker locker( mutex );

const QString driverName = firstLayer->driverName();

const int layerCount = firstLayer->GetLayerCount();

QList<QgsProviderSublayerDetails> res;
if ( layerCount == 1 )
{
res << QgsOgrProviderUtils::querySubLayerList( 0, firstLayer.get(), driverName, flags, uri, true, feedback );
res << QgsOgrProviderUtils::querySubLayerList( 0, firstLayer.get(), hDS, driverName, flags, uri, true, feedback );
}
else
{
@@ -1239,7 +1247,7 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
if ( !originalUriLayerName.isEmpty() && layerName != originalUriLayerName )
continue;

res << QgsOgrProviderUtils::querySubLayerList( i, sublayer, driverName, flags, uri, false, feedback );
res << QgsOgrProviderUtils::querySubLayerList( i, sublayer, hDS, driverName, flags, uri, false, feedback );
}
}

@@ -1307,14 +1315,7 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
}

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0)

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QMutex *mutex = nullptr;
#else
QRecursiveMutex *mutex = nullptr;
#endif
GDALDatasetH hDS = firstLayer->getDatasetHandleAndMutex( mutex );
QMutexLocker locker( mutex );
// retrieve layer paths
if ( GDALGroupH rootGroup = GDALDatasetGetRootGroup( hDS ) )
{
std::function< void( GDALGroupH, const QStringList & ) > recurseGroup;
@@ -2313,7 +2313,7 @@ bool QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( const QString &d
!( updateMode && dsName.endsWith( QLatin1String( ".shp.zip" ), Qt::CaseInsensitive ) );
}

QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int i, QgsOgrLayer *layer, const QString &driverName, Qgis::SublayerQueryFlags flags, const QString &baseUri, bool hasSingleLayerOnly, QgsFeedback *feedback )
QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int i, QgsOgrLayer *layer, GDALDatasetH hDS, const QString &driverName, Qgis::SublayerQueryFlags flags, const QString &baseUri, bool hasSingleLayerOnly, QgsFeedback *feedback )
{
const QString layerName = QString::fromUtf8( layer->name() );

@@ -2331,6 +2331,16 @@ QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int
layerFlags |= Qgis::SublayerFlag::SystemTable;
}

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,4,0)
// mark private layers, using GDAL API
if ( hDS && GDALDatasetIsLayerPrivate( hDS, i ) )
{
layerFlags |= Qgis::SublayerFlag::SystemTable;
}
#else
( void )hDS;
#endif

if ( !( flags & Qgis::SublayerQueryFlag::IncludeSystemTables ) && ( layerFlags & Qgis::SublayerFlag::SystemTable ) )
{
// layer is a system table, and we are not scanning for them
@@ -260,7 +260,7 @@ class CORE_EXPORT QgsOgrProviderUtils
bool updateMode,
const QString &dsName );

static QList<QgsProviderSublayerDetails> querySubLayerList( int i, QgsOgrLayer *layer, const QString &driverName, Qgis::SublayerQueryFlags flags,
static QList<QgsProviderSublayerDetails> querySubLayerList( int i, QgsOgrLayer *layer, GDALDatasetH hDS, const QString &driverName, Qgis::SublayerQueryFlags flags,
const QString &baseUri, bool hasSingleLayerOnly, QgsFeedback *feedback = nullptr );

/**

0 comments on commit fd7601d

Please sign in to comment.