Skip to content

Commit ff9da2f

Browse files
3nidsm-kuhn
authored andcommittedOct 15, 2018
nicer error reporting for overlap check
replace overlap feature QPair by a struct this allows using the layer name rather than its ID in the error description
1 parent 5a11b22 commit ff9da2f

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed
 

‎src/analysis/vector/geometry_checker/qgsgeometryoverlapcheck.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ void QgsGeometryOverlapCheck::fixError( const QMap<QString, QgsFeaturePool *> &f
9292
QgsGeometryOverlapCheckError *overlapError = static_cast<QgsGeometryOverlapCheckError *>( error );
9393

9494
QgsFeaturePool *featurePoolA = featurePools[ overlapError->layerId() ];
95-
QgsFeaturePool *featurePoolB = featurePools[ overlapError->overlappedFeature().first ];
95+
QgsFeaturePool *featurePoolB = featurePools[ overlapError->overlappedFeature().layerId() ];
9696
QgsFeature featureA;
9797
QgsFeature featureB;
9898
if ( !featurePoolA->getFeature( overlapError->featureId(), featureA ) ||
99-
!featurePoolB->getFeature( overlapError->overlappedFeature().second, featureB ) )
99+
!featurePoolB->getFeature( overlapError->overlappedFeature().featureId(), featureB ) )
100100
{
101101
error->setObsolete();
102102
return;
@@ -186,7 +186,7 @@ void QgsGeometryOverlapCheck::fixError( const QMap<QString, QgsFeaturePool *> &f
186186
diff2->transform( ct, QgsCoordinateTransform::ReverseTransform );
187187
featureB.setGeometry( QgsGeometry( std::move( diff2 ) ) );
188188

189-
changes[overlapError->overlappedFeature().first][featureB.id()].append( Change( ChangeFeature, ChangeChanged ) );
189+
changes[overlapError->overlappedFeature().layerId()][featureB.id()].append( Change( ChangeFeature, ChangeChanged ) );
190190
featurePoolB->updateFeature( featureB );
191191
}
192192

@@ -249,15 +249,14 @@ bool QgsGeometryOverlapCheck::factoryIsCompatible( QgsVectorLayer *layer ) SIP_S
249249

250250
QgsGeometryOverlapCheckError::QgsGeometryOverlapCheckError( const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsGeometry &geometry, const QgsPointXY &errorLocation, const QVariant &value, const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature )
251251
: QgsGeometryCheckError( check, layerFeature.layer()->id(), layerFeature.feature().id(), geometry, errorLocation, QgsVertexId(), value, ValueArea )
252-
, mOverlappedFeature( qMakePair( overlappedFeature.layer()->id(), overlappedFeature.feature().id() ) )
253-
252+
, mOverlappedFeature( OverLappedFeature( overlappedFeature.layer(), overlappedFeature.feature().id() ) )
254253
{
255254

256255
}
257256

258257
QString QgsGeometryOverlapCheckError::description() const
259258
{
260-
return QCoreApplication::translate( "QgsGeometryTypeCheckError", "Overlap with %1:%2" ).arg( mOverlappedFeature.first, QString::number( mOverlappedFeature.second ) );
259+
return QCoreApplication::translate( "QgsGeometryTypeCheckError", "Overlap with %1 at feature %2" ).arg( mOverlappedFeature.layerName(), QString::number( mOverlappedFeature.featureId() ) );
261260
}
262261

263262
QgsGeometryCheck::CheckType QgsGeometryOverlapCheck::factoryCheckType()

‎src/analysis/vector/geometry_checker/qgsgeometryoverlapcheck.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,34 @@
2525
class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckError
2626
{
2727
public:
28+
29+
struct OverLappedFeature
30+
{
31+
public:
32+
OverLappedFeature( QgsVectorLayer *vl, QgsFeatureId fid )
33+
: mLayerId( vl->id() )
34+
, mLayerName( vl->name() )
35+
, mFeatureId( fid )
36+
{}
37+
38+
QString layerId() const {return mLayerId;}
39+
QString layerName() const {return mLayerName;}
40+
QgsFeatureId featureId() const {return mFeatureId;}
41+
bool operator==( const OverLappedFeature &other ) const {return mLayerId == other.layerId() && mFeatureId == other.featureId();}
42+
43+
private:
44+
QString mLayerId;
45+
QString mLayerName;
46+
QgsFeatureId mFeatureId;
47+
};
48+
2849
QgsGeometryOverlapCheckError( const QgsGeometryCheck *check,
2950
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
3051
const QgsGeometry &geometry,
3152
const QgsPointXY &errorLocation,
3253
const QVariant &value,
3354
const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature );
34-
const QPair<QString, QgsFeatureId> &overlappedFeature() const { return mOverlappedFeature; }
55+
const OverLappedFeature &overlappedFeature() const { return mOverlappedFeature; }
3556

3657
bool isEqual( QgsGeometryCheckError *other ) const override
3758
{
@@ -56,7 +77,7 @@ class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckErro
5677
{
5778
return false;
5879
}
59-
if ( changes.value( mOverlappedFeature.first ).keys().contains( mOverlappedFeature.second ) )
80+
if ( changes.value( mOverlappedFeature.layerId() ).keys().contains( mOverlappedFeature.featureId() ) )
6081
{
6182
return false;
6283
}
@@ -66,7 +87,7 @@ class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckErro
6687
QString description() const override;
6788

6889
private:
69-
QPair<QString, QgsFeatureId> mOverlappedFeature;
90+
OverLappedFeature mOverlappedFeature;
7091
};
7192

7293
class ANALYSIS_EXPORT QgsGeometryOverlapCheck : public QgsGeometryCheck

0 commit comments

Comments
 (0)
Please sign in to comment.