Skip to content
Permalink
Browse files
Implement querySubLayers for OGR provider metadata
  • Loading branch information
nyalldawson committed Jun 28, 2021
1 parent a98411f commit 29c1dff13fb7e8ae538f4dad77e9bbc2c364bc68
@@ -27,6 +27,7 @@ email : nyall dot dawson at gmail dot com
#include "qgsprojectstorageregistry.h"
#include "qgsgeopackageproviderconnection.h"
#include "qgsogrdbconnection.h"
#include "qgsprovidersublayerdetails.h"

#include <QFileInfo>
#include <QFile>
@@ -1028,6 +1029,61 @@ bool QgsOgrProviderMetadata::uriIsBlocklisted( const QString &uri ) const
return false;
}

QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags, QgsFeedback * ) const
{
QStringList skippedLayerNames;

QStringList options { QStringLiteral( "@LIST_ALL_TABLES=YES" ) };

QString errCause;
QgsOgrLayerUniquePtr firstLayer = QgsOgrProviderUtils::getLayer( uri, false, options, 0, errCause, true );
if ( !firstLayer )
return {};

const QString driverName = firstLayer->driverName();
if ( driverName == QLatin1String( "SQLite" ) )
{
skippedLayerNames = QgsSqliteUtils::systemTables();
}

const unsigned int layerCount = firstLayer->GetLayerCount();

if ( layerCount == 1 )
{
return QgsOgrProviderUtils::querySubLayerList( 0, firstLayer.get(), driverName, flags, false, uri );
}
else
{
QList<QgsProviderSublayerDetails> res;
// In case there is no free opened dataset in the cache, keep the first
// layer alive while we iterate over the other layers, so that we can
// reuse the same dataset. Can help in a particular with a FileGDB with
// the FileGDB driver
for ( unsigned int i = 0; i < layerCount; i++ )
{
QString errCause;
QgsOgrLayerUniquePtr layer;

if ( i != 0 )
{
layer = QgsOgrProviderUtils::getLayer( firstLayer->datasetName(),
false,
firstLayer->options(),
i,
errCause,
// do not check timestamp beyond the first
// layer
firstLayer == nullptr );
if ( !layer )
continue;
}

res << QgsOgrProviderUtils::querySubLayerList( i, i == 0 ? firstLayer.get() : layer.get(), driverName, flags, false, uri );
}
return res;
}
}

QMap<QString, QgsAbstractProviderConnection *> QgsOgrProviderMetadata::connections( bool cached )
{
return connectionsProtected<QgsGeoPackageProviderConnection, QgsOgrDbConnection>( cached );
@@ -41,6 +41,7 @@ class QgsOgrProviderMetadata final: public QgsProviderMetadata
QString filters( FilterType type ) override;
ProviderCapabilities providerCapabilities() const override;
bool uriIsBlocklisted( const QString &uri ) const override;
QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const override;
Qgis::VectorExportResult createEmptyLayer(
const QString &uri,
const QgsFields &fields,

0 comments on commit 29c1dff

Please sign in to comment.