Skip to content
Permalink
Browse files
Support responsive cancelation of sub layers query for OGR provider
In some cases this code iterates through features, so early exit
paths are desirable
  • Loading branch information
nyalldawson committed Jun 28, 2021
1 parent 29c1dff commit 15e1e2373a983af06c07e45a835209bab452357e
@@ -1029,7 +1029,7 @@ bool QgsOgrProviderMetadata::uriIsBlocklisted( const QString &uri ) const
return false;
}

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

@@ -1050,7 +1050,7 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const

if ( layerCount == 1 )
{
return QgsOgrProviderUtils::querySubLayerList( 0, firstLayer.get(), driverName, flags, false, uri );
return QgsOgrProviderUtils::querySubLayerList( 0, firstLayer.get(), driverName, flags, false, uri, feedback );
}
else
{
@@ -1061,6 +1061,9 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
// the FileGDB driver
for ( unsigned int i = 0; i < layerCount; i++ )
{
if ( feedback && feedback->isCanceled() )
break;

QString errCause;
QgsOgrLayerUniquePtr layer;

@@ -1078,7 +1081,7 @@ QList<QgsProviderSublayerDetails> QgsOgrProviderMetadata::querySublayers( const
continue;
}

res << QgsOgrProviderUtils::querySubLayerList( i, i == 0 ? firstLayer.get() : layer.get(), driverName, flags, false, uri );
res << QgsOgrProviderUtils::querySubLayerList( i, i == 0 ? firstLayer.get() : layer.get(), driverName, flags, false, uri, feedback );
}
return res;
}
@@ -2292,7 +2292,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, bool isSubLayer, const QString &baseUri )
QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int i, QgsOgrLayer *layer, const QString &driverName, Qgis::SublayerQueryFlags flags, bool isSubLayer, const QString &baseUri, QgsFeedback *feedback )
{
QString layerName = QString::fromUtf8( layer->name() );

@@ -2367,6 +2367,9 @@ QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int
OGRwkbGeometryType gType = QgsOgrProviderUtils::ogrWkbSingleFlatten( OGR_G_GetGeometryType( geom ) );
fCount[gType] = fCount.value( gType ) + 1;
}

if ( feedback && feedback->isCanceled() )
break;
}
layer->ResetReading();
// it may happen that there are no features in the layer, in that case add unknown type
@@ -2412,6 +2415,9 @@ QList< QgsProviderSublayerDetails > QgsOgrProviderUtils::querySubLayerList( int
QMap<OGRwkbGeometryType, int>::const_iterator countIt = fCount.constBegin();
for ( ; countIt != fCount.constEnd(); ++countIt )
{
if ( feedback && feedback->isCanceled() )
break;

QgsProviderSublayerDetails details;
details.setLayerNumber( i );
details.setName( layerName );
@@ -257,7 +257,7 @@ class CORE_EXPORT QgsOgrProviderUtils
bool updateMode,
const QString &dsName );

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

};

0 comments on commit 15e1e23

Please sign in to comment.