Skip to content

Commit

Permalink
QgsGeometryCheckError class requires context in constructor (not inhe…
Browse files Browse the repository at this point in the history
…rited classes yet)
  • Loading branch information
3nids authored and m-kuhn committed Oct 15, 2018
1 parent 7593d51 commit b0810b1
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 34 deletions.
Expand Up @@ -33,6 +33,7 @@ the Free Software Foundation; either version 2 of the License, or *
enum ValueType { ValueLength, ValueArea, ValueOther };

QgsGeometryCheckError( const QgsGeometryCheck *check,
const QgsGeometryCheckContext *context,
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
const QgsPointXY &errorLocation,
QgsVertexId vidx = QgsVertexId(),
Expand All @@ -43,6 +44,7 @@ the Free Software Foundation; either version 2 of the License, or *


const QgsGeometryCheck *check() const;
const QgsGeometryCheckContext *context() const;
const QString &layerId() const;
QgsFeatureId featureId() const;
QgsGeometry geometry() const;
Expand Down
Expand Up @@ -63,7 +63,7 @@ void QgsGeometryAngleCheck::collectErrors( const QMap<QString, QgsFeaturePool *>
double angle = std::acos( v21 * v23 ) / M_PI * 180.0;
if ( angle < mMinAngle )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, p2, QgsVertexId( iPart, iRing, iVert ), angle ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, p2, QgsVertexId( iPart, iRing, iVert ), angle ) );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/geometry_checker/qgsgeometryareacheck.cpp
Expand Up @@ -20,7 +20,7 @@
#include "qgsfeaturepool.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryAreaCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryAreaCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
Expand All @@ -35,7 +35,7 @@ void QgsGeometryAreaCheck::collectErrors( const QMap<QString, QgsFeaturePool *>
const QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( geom, iPart );
if ( checkThreshold( layerToMapUnits, part, value ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, part->centroid(), QgsVertexId( iPart ), value * layerToMapUnits * layerToMapUnits, QgsGeometryCheckError::ValueArea ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, part->centroid(), QgsVertexId( iPart ), value * layerToMapUnits * layerToMapUnits, QgsGeometryCheckError::ValueArea ) );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/vector/geometry_checker/qgsgeometrychecker.cpp
Expand Up @@ -200,14 +200,14 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
{
if ( !recheckAreaFeatures.isEmpty() )
{
check->collectErrors( mFeaturePools, recheckErrors, mMessages, nullptr, recheckAreaFeatures );
check->collectErrors( mFeaturePools, mContext, recheckErrors, mMessages, nullptr, recheckAreaFeatures );
}
}
else
{
if ( !recheckFeatures.isEmpty() )
{
check->collectErrors( mFeaturePools, recheckErrors, mMessages, nullptr, recheckFeatures );
check->collectErrors( mFeaturePools, mContext, recheckErrors, mMessages, nullptr, recheckFeatures );
}
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ void QgsGeometryChecker::runCheck( const QMap<QString, QgsFeaturePool *> &featur
// Run checks
QList<QgsGeometryCheckError *> errors;
QStringList messages;
check->collectErrors( featurePools, errors, messages, &mFeedback );
check->collectErrors( featurePools, mContext, errors, messages, &mFeedback );
mErrorListMutex.lock();
mCheckErrors.append( errors );
mMessages.append( messages );
Expand Down
3 changes: 3 additions & 0 deletions src/analysis/vector/geometry_checker/qgsgeometrycheckerror.h
Expand Up @@ -33,6 +33,7 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
enum ValueType { ValueLength, ValueArea, ValueOther };

QgsGeometryCheckError( const QgsGeometryCheck *check,
const QgsGeometryCheckContext *context,
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
const QgsPointXY &errorLocation,
QgsVertexId vidx = QgsVertexId(),
Expand All @@ -44,6 +45,7 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
const QgsGeometryCheckError &operator=( const QgsGeometryCheckError & ) = delete;

const QgsGeometryCheck *check() const { return mCheck; }
const QgsGeometryCheckContext *context() const {return mContext;}
const QString &layerId() const { return mLayerId; }
QgsFeatureId featureId() const { return mFeatureId; }
// In map units
Expand Down Expand Up @@ -99,6 +101,7 @@ class ANALYSIS_EXPORT QgsGeometryCheckError
ValueType valueType = ValueOther );

const QgsGeometryCheck *mCheck = nullptr;
const QgsGeometryCheckContext *mContext = nullptr;
QString mLayerId;
QgsFeatureId mFeatureId;
QgsGeometry mGeometry;
Expand Down
Expand Up @@ -20,7 +20,7 @@
#include "qgsvectorlayer.h"


void QgsGeometryContainedCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryContainedCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesA( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext );
Expand Down
Expand Up @@ -30,7 +30,7 @@ class ANALYSIS_EXPORT QgsGeometryContainedCheckError : public QgsGeometryCheckEr
const QgsPointXY &errorLocation,
const QgsGeometryCheckerUtils::LayerFeature &containingFeature
)
: QgsGeometryCheckError( check, layerFeature, errorLocation, QgsVertexId(), containingFeature.id(), ValueOther )
: QgsGeometryCheckError( check, check->context(), layerFeature, errorLocation, QgsVertexId(), containingFeature.id(), ValueOther )
, mContainingFeature( qMakePair( containingFeature.layer()->id(), containingFeature.feature().id() ) )
{ }
const QPair<QString, QgsFeatureId> &containingFeature() const { return mContainingFeature; }
Expand Down
Expand Up @@ -19,7 +19,7 @@
#include "qgsvectorlayer.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryDangleCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryDangleCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
Expand Down Expand Up @@ -84,11 +84,11 @@ void QgsGeometryDangleCheck::collectErrors( const QMap<QString, QgsFeaturePool *
}
if ( !p1touches )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, p1, QgsVertexId( iPart, 0, 0 ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, p1, QgsVertexId( iPart, 0, 0 ) ) );
}
if ( !p2touches )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, p2, QgsVertexId( iPart, 0, nVerts - 1 ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, p2, QgsVertexId( iPart, 0, nVerts - 1 ) ) );
}
}
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
#include "qgsgeometrycheckerror.h"


void QgsGeometryDegeneratePolygonCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryDegeneratePolygonCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand All @@ -35,7 +35,7 @@ void QgsGeometryDegeneratePolygonCheck::collectErrors( const QMap<QString, QgsFe
if ( QgsGeometryCheckerUtils::polyLineSize( geom, iPart, iRing ) < 3 )
{
QgsVertexId vidx( iPart, iRing );
errors.append( new QgsGeometryCheckError( this, layerFeature, geom->vertexAt( vidx ), vidx ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, geom->vertexAt( vidx ), vidx ) );
}
}
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ QString QgsGeometryDuplicateCheckError::duplicatesString( const QMap<QString, Qg
}


void QgsGeometryDuplicateCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryDuplicateCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesA( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext, true );
Expand Down
Expand Up @@ -19,7 +19,7 @@
#include "qgsfeaturepool.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryDuplicateNodesCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryDuplicateNodesCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand All @@ -41,7 +41,7 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( const QMap<QString, QgsFeatu
QgsPoint pj = geom->vertexAt( QgsVertexId( iPart, iRing, jVert ) );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) < mContext->tolerance )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, pj, QgsVertexId( iPart, iRing, jVert ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, pj, QgsVertexId( iPart, iRing, jVert ) ) );
}
}
}
Expand Down
Expand Up @@ -36,7 +36,7 @@ QgsGeometryFollowBoundariesCheck::~QgsGeometryFollowBoundariesCheck()
delete mIndex;
}

void QgsGeometryFollowBoundariesCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryFollowBoundariesCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand Down Expand Up @@ -70,7 +70,7 @@ void QgsGeometryFollowBoundariesCheck::collectErrors( const QMap<QString, QgsFea
if ( refFeatureIds.isEmpty() )
{
// If no potential reference features are found, the geometry is definitely not following boundaries of reference layer features
errors.append( new QgsGeometryCheckError( this, layerFeature, QgsPointXY( geom->centroid() ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, QgsPointXY( geom->centroid() ) ) );
}
else
{
Expand All @@ -83,7 +83,7 @@ void QgsGeometryFollowBoundariesCheck::collectErrors( const QMap<QString, QgsFea
QgsGeometry reducedRefGeom( refgeomEngine->buffer( -mContext->tolerance, 0 ) );
if ( !( geomEngine->contains( reducedRefGeom.constGet() ) || geomEngine->disjoint( reducedRefGeom.constGet() ) ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, QgsPointXY( geom->centroid() ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, QgsPointXY( geom->centroid() ) ) );
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/geometry_checker/qgsgeometryholecheck.cpp
Expand Up @@ -20,7 +20,7 @@
#include "qgsfeaturepool.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryHoleCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryHoleCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand All @@ -41,7 +41,7 @@ void QgsGeometryHoleCheck::collectErrors( const QMap<QString, QgsFeaturePool *>
{

QgsPoint pos = poly->interiorRing( iRing - 1 )->centroid();
errors.append( new QgsGeometryCheckError( this, layerFeature, pos, QgsVertexId( iPart, iRing ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, pos, QgsVertexId( iPart, iRing ) ) );
}
}
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
#include "qgsvectorlayer.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryLineIntersectionCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryLineIntersectionCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand Down Expand Up @@ -67,7 +67,7 @@ void QgsGeometryLineIntersectionCheck::collectErrors( const QMap<QString, QgsFea
const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance );
for ( const QgsPoint &inter : intersections )
{
errors.append( new QgsGeometryCheckError( this, layerFeatureA, inter, QgsVertexId( iPart ), layerFeatureB.id() ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeatureA, inter, QgsVertexId( iPart ), layerFeatureB.id() ) );
}
}
}
Expand Down
Expand Up @@ -20,7 +20,7 @@
#include "qgsfeaturepool.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryLineLayerIntersectionCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryLineLayerIntersectionCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand Down Expand Up @@ -52,7 +52,7 @@ void QgsGeometryLineLayerIntersectionCheck::collectErrors( const QMap<QString, Q
const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance );
for ( const QgsPoint &inter : intersections )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
}
}
else if ( const QgsPolygon *polygon = dynamic_cast<const QgsPolygon *>( part ) )
Expand All @@ -63,7 +63,7 @@ void QgsGeometryLineLayerIntersectionCheck::collectErrors( const QMap<QString, Q
const QList< QgsPoint > intersections = QgsGeometryCheckerUtils::lineIntersections( line, ring, mContext->tolerance );
for ( const QgsPoint &inter : intersections )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, inter, QgsVertexId( iPart ), checkFeature.id() ) );
}
}
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
#include "qgsfeaturepool.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryPointCoveredByLineCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryPointCoveredByLineCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand Down Expand Up @@ -66,7 +66,7 @@ void QgsGeometryPointCoveredByLineCheck::collectErrors( const QMap<QString, QgsF
{
continue;
}
errors.append( new QgsGeometryCheckError( this, layerFeature, *point, QgsVertexId( iPart, 0, 0 ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, *point, QgsVertexId( iPart, 0, 0 ) ) );
}
}
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
#include "qgsgeometryengine.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometryPointInPolygonCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometryPointInPolygonCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext, true );
Expand Down Expand Up @@ -58,7 +58,7 @@ void QgsGeometryPointInPolygonCheck::collectErrors( const QMap<QString, QgsFeatu
}
if ( nTested == 0 || nTested != nInside )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, *point, QgsVertexId( iPart, 0, 0 ) ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, *point, QgsVertexId( iPart, 0, 0 ) ) );
}
}
}
Expand Down
Expand Up @@ -19,7 +19,7 @@
#include "qgsfeaturepool.h"
#include "qgsgeometrycheckerror.h"

void QgsGeometrySegmentLengthCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
void QgsGeometrySegmentLengthCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, const QgsGeometryCheckContext *context, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
{
Q_UNUSED( messages )

Expand Down Expand Up @@ -50,7 +50,7 @@ void QgsGeometrySegmentLengthCheck::collectErrors( const QMap<QString, QgsFeatur
if ( dist < minLength && dist > mContext->tolerance )
{
QgsPointXY pos( 0.5 * ( pi.x() + pj.x() ), 0.5 * ( pi.y() + pj.y() ) );
errors.append( new QgsGeometryCheckError( this, layerFeature, pos, QgsVertexId( iPart, iRing, iVert ), dist * layerToMapUnits, QgsGeometryCheckError::ValueLength ) );
errors.append( new QgsGeometryCheckError( this, context, layerFeature, pos, QgsVertexId( iPart, iRing, iVert ), dist * layerToMapUnits, QgsGeometryCheckError::ValueLength ) );
}
}
}
Expand Down

0 comments on commit b0810b1

Please sign in to comment.