Skip to content

Commit d87738b

Browse files
committed
Avoid some detaches in AFS iterator
1 parent 258527c commit d87738b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/providers/arcgisrest/qgsafsshareddata.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, bool fetchGeo
3535
return filterRect.isNull() || ( f.hasGeometry() && f.geometry().intersects( filterRect ) );
3636
}
3737

38-
// Determine attributes to fetch
39-
/*QStringList fetchAttribNames;
40-
foreach ( int idx, fetchAttributes )
41-
fetchAttribNames.append( mFields.at( idx ).name() );
42-
*/
43-
4438
// When fetching from server, fetch all attributes and geometry by default so that we can cache them
4539
QStringList fetchAttribNames;
4640
QList<int> fetchAttribIdx;
@@ -65,33 +59,33 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, bool fetchGeo
6559

6660
// Query
6761
QString errorTitle, errorMessage;
68-
QVariantMap queryData = QgsArcGisRestUtils::getObjects(
69-
mDataSource.param( QStringLiteral( "url" ) ), objectIds, mDataSource.param( QStringLiteral( "crs" ) ), fetchGeometry,
70-
fetchAttribNames, QgsWkbTypes::hasM( mGeometryType ), QgsWkbTypes::hasZ( mGeometryType ),
71-
filterRect, errorTitle, errorMessage );
62+
const QVariantMap queryData = QgsArcGisRestUtils::getObjects(
63+
mDataSource.param( QStringLiteral( "url" ) ), objectIds, mDataSource.param( QStringLiteral( "crs" ) ), fetchGeometry,
64+
fetchAttribNames, QgsWkbTypes::hasM( mGeometryType ), QgsWkbTypes::hasZ( mGeometryType ),
65+
filterRect, errorTitle, errorMessage );
7266
if ( queryData.isEmpty() )
7367
{
7468
// const_cast<QgsAfsProvider *>( this )->pushError( errorTitle + ": " + errorMessage );
7569
QgsDebugMsg( "Query returned empty result" );
7670
return false;
7771
}
7872

79-
QVariantList featuresData = queryData[QStringLiteral( "features" )].toList();
73+
const QVariantList featuresData = queryData[QStringLiteral( "features" )].toList();
8074
if ( featuresData.isEmpty() )
8175
{
8276
QgsDebugMsgLevel( "Query returned no features", 3 );
8377
return false;
8478
}
8579
for ( int i = 0, n = featuresData.size(); i < n; ++i )
8680
{
87-
QVariantMap featureData = featuresData[i].toMap();
81+
const QVariantMap featureData = featuresData[i].toMap();
8882
QgsFeature feature;
8983
int featureId = startId + i;
9084

9185
// Set attributes
9286
if ( !fetchAttribIdx.isEmpty() )
9387
{
94-
QVariantMap attributesData = featureData[QStringLiteral( "attributes" )].toMap();
88+
const QVariantMap attributesData = featureData[QStringLiteral( "attributes" )].toMap();
9589
feature.setFields( mFields );
9690
QgsAttributes attributes( mFields.size() );
9791
foreach ( int idx, fetchAttribIdx )
@@ -111,7 +105,7 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, bool fetchGeo
111105
// Set geometry
112106
if ( fetchGeometry )
113107
{
114-
QVariantMap geometryData = featureData[QStringLiteral( "geometry" )].toMap();
108+
const QVariantMap geometryData = featureData[QStringLiteral( "geometry" )].toMap();
115109
QgsAbstractGeometry *geometry = QgsArcGisRestUtils::parseEsriGeoJSON( geometryData, queryData[QStringLiteral( "geometryType" )].toString(),
116110
QgsWkbTypes::hasM( mGeometryType ), QgsWkbTypes::hasZ( mGeometryType ) );
117111
// Above might return 0, which is OK since in theory empty geometries are allowed

0 commit comments

Comments
 (0)