Skip to content

Commit 42c3f45

Browse files
committed
Abort geometry checks if feedback is cancelled
1 parent e300387 commit 42c3f45

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ void QgsGeometryGapCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &
4444
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
4545
{
4646
geomList.append( layerFeature.geometry().constGet()->clone() );
47+
48+
if ( feedback->isCanceled() )
49+
{
50+
qDeleteAll( geomList );
51+
geomList.clear();
52+
break;
53+
}
4754
}
4855

4956
if ( geomList.isEmpty() )

src/analysis/vector/geometry_checker/qgsgeometrymissingvertexcheck.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ void QgsGeometryMissingVertexCheck::collectErrors( const QMap<QString, QgsFeatur
4343

4444
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
4545
{
46+
if ( feedback->isCanceled() )
47+
{
48+
break;
49+
}
50+
4651
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
4752

4853
if ( QgsCurvePolygon *polygon = qgsgeometry_cast<QgsCurvePolygon *>( geom ) )
4954
{
50-
processPolygon( polygon, featurePool, errors, layerFeature );
55+
processPolygon( polygon, featurePool, errors, layerFeature, feedback );
5156
}
5257
else if ( QgsGeometryCollection *collection = qgsgeometry_cast<QgsGeometryCollection *>( geom ) )
5358
{
@@ -56,7 +61,7 @@ void QgsGeometryMissingVertexCheck::collectErrors( const QMap<QString, QgsFeatur
5661
{
5762
if ( QgsCurvePolygon *polygon = qgsgeometry_cast<QgsCurvePolygon *>( collection->geometryN( i ) ) )
5863
{
59-
processPolygon( polygon, featurePool, errors, layerFeature );
64+
processPolygon( polygon, featurePool, errors, layerFeature, feedback );
6065
}
6166
}
6267
}
@@ -105,7 +110,7 @@ QString QgsGeometryMissingVertexCheck::description() const
105110
return factoryDescription();
106111
}
107112

108-
void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature ) const
113+
void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, QgsFeedback *feedback ) const
109114
{
110115
const QgsFeature &currentFeature = layerFeature.feature();
111116
std::unique_ptr<QgsMultiPolygon> boundaries = qgis::make_unique<QgsMultiPolygon>();
@@ -133,6 +138,9 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg
133138

134139
if ( featurePool->getFeature( fid, compareFeature ) )
135140
{
141+
if ( feedback->isCanceled() )
142+
break;
143+
136144
QgsVertexIterator vertexIterator = compareFeature.geometry().vertices();
137145
while ( vertexIterator.hasNext() )
138146
{

src/analysis/vector/geometry_checker/qgsgeometrymissingvertexcheck.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ANALYSIS_EXPORT QgsGeometryMissingVertexCheck : public QgsGeometryCheck
6262
///@endcond
6363

6464
private:
65-
void processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature ) const;
65+
void processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, QgsFeedback *feedback ) const;
6666
};
6767

6868

src/analysis/vector/geometry_checker/qgsgeometryoverlapcheck.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "qgsgeometryoverlapcheck.h"
1919
#include "qgsfeaturepool.h"
2020
#include "qgsvectorlayer.h"
21-
21+
#include "qgsfeedback.h"
2222

2323
QgsGeometryOverlapCheck::QgsGeometryOverlapCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration )
2424
: QgsGeometryCheck( context, configuration )
@@ -35,6 +35,9 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
3535
QList<QString> layerIds = featureIds.keys();
3636
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureA : layerFeaturesA )
3737
{
38+
if ( feedback->isCanceled() )
39+
break;
40+
3841
// Ensure each pair of layers only gets compared once: remove the current layer from the layerIds, but add it to the layerList for layerFeaturesB
3942
layerIds.removeOne( layerFeatureA.layer()->id() );
4043

@@ -49,6 +52,9 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
4952
const QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( featurePools, QList<QString>() << layerFeatureA.layer()->id() << layerIds, bboxA, compatibleGeometryTypes(), mContext );
5053
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureB : layerFeaturesB )
5154
{
55+
if ( feedback->isCanceled() )
56+
break;
57+
5258
// > : only report overlaps within same layer once
5359
if ( layerFeatureA.layer()->id() == layerFeatureB.layer()->id() && layerFeatureB.feature().id() >= layerFeatureA.feature().id() )
5460
{
@@ -57,13 +63,13 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
5763
QString errMsg;
5864
if ( geomEngineA->overlaps( layerFeatureB.geometry().constGet(), &errMsg ) )
5965
{
60-
QgsAbstractGeometry *interGeom = geomEngineA->intersection( layerFeatureB.geometry().constGet() );
66+
std::unique_ptr<QgsAbstractGeometry> interGeom( geomEngineA->intersection( layerFeatureB.geometry().constGet() ) );
6167
if ( interGeom && !interGeom->isEmpty() )
6268
{
63-
QgsGeometryCheckerUtils::filter1DTypes( interGeom );
69+
QgsGeometryCheckerUtils::filter1DTypes( interGeom.get() );
6470
for ( int iPart = 0, nParts = interGeom->partCount(); iPart < nParts; ++iPart )
6571
{
66-
QgsAbstractGeometry *interPart = QgsGeometryCheckerUtils::getGeomPart( interGeom, iPart );
72+
QgsAbstractGeometry *interPart = QgsGeometryCheckerUtils::getGeomPart( interGeom.get(), iPart );
6773
double area = interPart->area();
6874
if ( area > mContext->reducedTolerance && ( area < mOverlapThresholdMapUnits || mOverlapThresholdMapUnits == 0.0 ) )
6975
{
@@ -75,7 +81,6 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
7581
{
7682
messages.append( tr( "Overlap check between features %1 and %2 %3" ).arg( layerFeatureA.id(), layerFeatureB.id(), errMsg ) );
7783
}
78-
delete interGeom;
7984
}
8085
}
8186
}

0 commit comments

Comments
 (0)