QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgssinglegeometrycheck.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssinglegeometrycheck.cpp
3 --------------------------------------
4Date : 6.9.2018
5Copyright : (C) 2018 by Matthias Kuhn
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
18#include "qgspoint.h"
19
20
21void QgsSingleGeometryCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids ) const
22{
23 Q_UNUSED( messages )
24 const QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
25 const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext );
26 for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
27 {
28 const auto singleErrors = processGeometry( layerFeature.geometry() );
29 for ( const auto error : singleErrors )
30 errors.append( convertToGeometryCheckError( error, layerFeature ) );
31 }
32}
33
34QgsGeometryCheckErrorSingle *QgsSingleGeometryCheck::convertToGeometryCheckError( QgsSingleGeometryCheckError *singleGeometryCheckError, const QgsGeometryCheckerUtils::LayerFeature &layerFeature ) const
35{
36 return new QgsGeometryCheckErrorSingle( singleGeometryCheckError, layerFeature );
37}
38
40{
41 Q_ASSERT( mCheck == other->mCheck );
43 mVertexId = other->mVertexId;
44 mGeometry = other->mGeometry;
45}
46
48{
49 return mGeometry.equals( other->mGeometry )
50 && mCheck == other->mCheck
52 && mVertexId == other->mVertexId;
53}
54
55bool QgsSingleGeometryCheckError::handleChanges( const QList<QgsGeometryCheck::Change> &changes )
56{
57 Q_UNUSED( changes )
58 return true;
59}
60
62{
63 return mCheck->description();
64}
65
70
75
80
82 : QgsGeometryCheckError( error->check(), layerFeature, QgsPointXY( error->errorLocation().constGet()->centroid() ), error->vertexId() ) // TODO: should send geometry to QgsGeometryCheckError
83 , mError( error )
84{
85}
86
91
93{
95 return false;
96
97 return mError->handleChanges( changes.value( layerId() ).value( featureId() ) );
98}
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Wraps a QgsSingleGeometryError into a standard QgsGeometryCheckError.
QgsGeometryCheckErrorSingle(QgsSingleGeometryCheckError *singleError, const QgsGeometryCheckerUtils::LayerFeature &layerFeature)
Creates a new error for a QgsSingleGeometryCheck.
bool handleChanges(const QgsGeometryCheck::Changes &changes) override
Apply a list of changes.
QgsSingleGeometryCheckError * singleError() const
The underlying single error.
This represents an error reported by a geometry check.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
QVariant value() const
An additional value for the error.
const QString & layerId() const
The id of the layer on which this error has been detected.
virtual bool handleChanges(const QgsGeometryCheck::Changes &changes)
Apply a list of changes.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
const QgsGeometryCheckContext * mContext
QMap< QString, QgsFeatureIds > allLayerFeatureIds(const QMap< QString, QgsFeaturePool * > &featurePools) const
Returns all layers and feature ids.
virtual QString description() const =0
Returns a human readable description for this check.
virtual QList< Qgis::GeometryType > compatibleGeometryTypes() const =0
A list of geometry types for which this check can be performed.
A layer feature combination to uniquely identify and access a feature in a set of layers.
Contains a set of layers and feature ids in those layers to pass to a geometry check.
A geometry is the spatial representation of a feature.
bool equals(const QgsGeometry &geometry) const
Test if this geometry is exactly equal to another geometry.
A class to represent a 2D point.
Definition qgspointxy.h:60
An error from a QgsSingleGeometryCheck.
QgsGeometry errorLocation() const
The exact location of the error.
const QgsSingleGeometryCheck * mCheck
virtual bool isEqual(const QgsSingleGeometryCheckError *other) const
Check if this error is equal to other.
virtual QString description() const
A human readable description of this error.
virtual bool handleChanges(const QList< QgsGeometryCheck::Change > &changes)
Apply a list of changes.
const QgsSingleGeometryCheck * check() const
The check that created this error.
QgsVertexId vertexId() const
The vertex id of the error.
virtual void update(const QgsSingleGeometryCheckError *other)
Update this error with the information from other.
Base class for geometry checks for a single geometry without any context of the layer or other layers...
void collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback=nullptr, const QgsGeometryCheck::LayerFeatureIds &ids=QgsGeometryCheck::LayerFeatureIds()) const FINAL
The main worker method.
virtual QList< QgsSingleGeometryCheckError * > processGeometry(const QgsGeometry &geometry) const =0
Check the geometry for errors.
A list of layers and feature ids for each of these layers.
QMap< QString, QgsFeatureIds > toMap() const
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30