Skip to content

Commit

Permalink
nicer error reporting for overlap check
Browse files Browse the repository at this point in the history
replace overlap feature QPair by a struct
this allows using the layer name rather than its ID in the error description
  • Loading branch information
3nids authored and m-kuhn committed Oct 15, 2018
1 parent 5a11b22 commit ff9da2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/analysis/vector/geometry_checker/qgsgeometryoverlapcheck.cpp
Expand Up @@ -92,11 +92,11 @@ void QgsGeometryOverlapCheck::fixError( const QMap<QString, QgsFeaturePool *> &f
QgsGeometryOverlapCheckError *overlapError = static_cast<QgsGeometryOverlapCheckError *>( error );

QgsFeaturePool *featurePoolA = featurePools[ overlapError->layerId() ];
QgsFeaturePool *featurePoolB = featurePools[ overlapError->overlappedFeature().first ];
QgsFeaturePool *featurePoolB = featurePools[ overlapError->overlappedFeature().layerId() ];
QgsFeature featureA;
QgsFeature featureB;
if ( !featurePoolA->getFeature( overlapError->featureId(), featureA ) ||
!featurePoolB->getFeature( overlapError->overlappedFeature().second, featureB ) )
!featurePoolB->getFeature( overlapError->overlappedFeature().featureId(), featureB ) )
{
error->setObsolete();
return;
Expand Down Expand Up @@ -186,7 +186,7 @@ void QgsGeometryOverlapCheck::fixError( const QMap<QString, QgsFeaturePool *> &f
diff2->transform( ct, QgsCoordinateTransform::ReverseTransform );
featureB.setGeometry( QgsGeometry( std::move( diff2 ) ) );

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

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

QgsGeometryOverlapCheckError::QgsGeometryOverlapCheckError( const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsGeometry &geometry, const QgsPointXY &errorLocation, const QVariant &value, const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature )
: QgsGeometryCheckError( check, layerFeature.layer()->id(), layerFeature.feature().id(), geometry, errorLocation, QgsVertexId(), value, ValueArea )
, mOverlappedFeature( qMakePair( overlappedFeature.layer()->id(), overlappedFeature.feature().id() ) )

, mOverlappedFeature( OverLappedFeature( overlappedFeature.layer(), overlappedFeature.feature().id() ) )
{

}

QString QgsGeometryOverlapCheckError::description() const
{
return QCoreApplication::translate( "QgsGeometryTypeCheckError", "Overlap with %1:%2" ).arg( mOverlappedFeature.first, QString::number( mOverlappedFeature.second ) );
return QCoreApplication::translate( "QgsGeometryTypeCheckError", "Overlap with %1 at feature %2" ).arg( mOverlappedFeature.layerName(), QString::number( mOverlappedFeature.featureId() ) );
}

QgsGeometryCheck::CheckType QgsGeometryOverlapCheck::factoryCheckType()
Expand Down
27 changes: 24 additions & 3 deletions src/analysis/vector/geometry_checker/qgsgeometryoverlapcheck.h
Expand Up @@ -25,13 +25,34 @@
class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckError
{
public:

struct OverLappedFeature
{
public:
OverLappedFeature( QgsVectorLayer *vl, QgsFeatureId fid )
: mLayerId( vl->id() )
, mLayerName( vl->name() )
, mFeatureId( fid )
{}

QString layerId() const {return mLayerId;}
QString layerName() const {return mLayerName;}
QgsFeatureId featureId() const {return mFeatureId;}
bool operator==( const OverLappedFeature &other ) const {return mLayerId == other.layerId() && mFeatureId == other.featureId();}

private:
QString mLayerId;
QString mLayerName;
QgsFeatureId mFeatureId;
};

QgsGeometryOverlapCheckError( const QgsGeometryCheck *check,
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
const QgsGeometry &geometry,
const QgsPointXY &errorLocation,
const QVariant &value,
const QgsGeometryCheckerUtils::LayerFeature &overlappedFeature );
const QPair<QString, QgsFeatureId> &overlappedFeature() const { return mOverlappedFeature; }
const OverLappedFeature &overlappedFeature() const { return mOverlappedFeature; }

bool isEqual( QgsGeometryCheckError *other ) const override
{
Expand All @@ -56,7 +77,7 @@ class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckErro
{
return false;
}
if ( changes.value( mOverlappedFeature.first ).keys().contains( mOverlappedFeature.second ) )
if ( changes.value( mOverlappedFeature.layerId() ).keys().contains( mOverlappedFeature.featureId() ) )
{
return false;
}
Expand All @@ -66,7 +87,7 @@ class ANALYSIS_EXPORT QgsGeometryOverlapCheckError : public QgsGeometryCheckErro
QString description() const override;

private:
QPair<QString, QgsFeatureId> mOverlappedFeature;
OverLappedFeature mOverlappedFeature;
};

class ANALYSIS_EXPORT QgsGeometryOverlapCheck : public QgsGeometryCheck
Expand Down

0 comments on commit ff9da2f

Please sign in to comment.