QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsgeometrycheck.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometrycheck.h
3 ---------------------
4 begin : September 2014
5 copyright : (C) 2014 by Sandro Mani / Sourcepole AG
6 email : smani at sourcepole dot ch
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
16#ifndef QGS_GEOMETRY_CHECK_H
17#define QGS_GEOMETRY_CHECK_H
18
19#include <QApplication>
20#include <limits>
21#include <QStringList>
22#include <QPointer>
23
24#include "qgis_analysis.h"
25#include "qgsfeature.h"
26#include "qgsvectorlayer.h"
27#include "qgsgeometry.h"
30#include "qgssettings.h"
31
33class QgsFeaturePool;
34
91class ANALYSIS_EXPORT QgsGeometryCheck
92{
93 Q_GADGET
94
95 public:
103 struct ANALYSIS_EXPORT LayerFeatureIds
104 {
105 LayerFeatureIds() = default;
106 LayerFeatureIds( const QMap<QString, QgsFeatureIds> &idsIn ) SIP_SKIP;
107
108 QMap<QString, QgsFeatureIds> ids SIP_SKIP;
109
110#ifndef SIP_RUN
111 QMap<QString, QgsFeatureIds> toMap() const
112 {
113 return ids;
114 }
115
116 bool isEmpty() const
117 {
118 return ids.isEmpty();
119 }
120#endif
121 };
122
135
142 {
145 ChangeChanged
146 };
147
159
163 enum Flag SIP_ENUM_BASETYPE( IntFlag )
164 {
165 AvailableInValidation = 1 << 1
166 };
167 Q_DECLARE_FLAGS( Flags, Flag )
168 Q_FLAG( Flags )
169
170
175 struct Change
176 {
177 Change() = default;
178
183 : what( _what )
184 , type( _type )
185 , vidx( _vidx )
186 {}
187
192
197
202
203 // TODO c++20 - replace with = default
204 bool operator==( const QgsGeometryCheck::Change &other ) const
205 {
206 return what == other.what && type == other.type && vidx == other.vidx;
207 }
208
209 bool operator!=( const QgsGeometryCheck::Change &other ) const
210 {
211 return !( *this == other );
212 }
213 };
214
219 typedef QMap<QString, QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>>> Changes;
220
224 QgsGeometryCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
225 virtual ~QgsGeometryCheck() = default;
226
232 virtual void prepare( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
233
234#ifndef SIP_RUN
235
240 template<class T>
241 T configurationValue( const QString &name, const QVariant &defaultValue = QVariant() )
242 {
243 return mConfiguration.value( name, QgsSettings().value( "/geometry_checker/" + id() + "/" + name, defaultValue ) ).value<T>();
244 }
245#endif
246
253 virtual bool isCompatible( QgsVectorLayer *layer ) const;
254
260 virtual QList<Qgis::GeometryType> compatibleGeometryTypes() const = 0;
261
265 virtual QgsGeometryCheck::Flags flags() const;
266
275 virtual void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors SIP_INOUT, QStringList &messages SIP_INOUT, QgsFeedback *feedback, const LayerFeatureIds &ids = QgsGeometryCheck::LayerFeatureIds() ) const = 0;
276
284 virtual void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes SIP_INOUT ) const SIP_SKIP;
285
291 virtual QList<QgsGeometryCheckResolutionMethod> availableResolutionMethods() const;
292
300 Q_DECL_DEPRECATED virtual QStringList resolutionMethods() const SIP_DEPRECATED;
301
307 virtual QString description() const = 0;
308
314 virtual QString id() const = 0;
315
321 virtual CheckType checkType() const = 0;
322
328 const QgsGeometryCheckContext *context() const { return mContext; }
329
330 protected:
337 QMap<QString, QgsFeatureIds> allLayerFeatureIds( const QMap<QString, QgsFeaturePool *> &featurePools ) const SIP_SKIP;
338
345 void replaceFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, QgsAbstractGeometry *newPartGeom, Changes &changes ) const SIP_SKIP;
346
353 void deleteFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes ) const SIP_SKIP;
354
361 void deleteFeatureGeometryRing( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, int ringIdx, Changes &changes ) const SIP_SKIP;
362
364 QVariantMap mConfiguration;
365
372 double scaleFactor( const QPointer<QgsVectorLayer> &layer ) const SIP_SKIP;
373};
374
375#endif // QGS_GEOMETRY_CHECK_H
Abstract base class for all geometries.
A feature pool is based on a vector layer and caches features.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Base configuration for geometry checks.
This represents an error reported by a geometry check.
This class implements a geometry check.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
QFlags< Flag > Flags
virtual void collectErrors(const QMap< QString, QgsFeaturePool * > &featurePools, QList< QgsGeometryCheckError * > &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids=QgsGeometryCheck::LayerFeatureIds()) const =0
The main worker method.
T configurationValue(const QString &name, const QVariant &defaultValue=QVariant())
Returns the configuration value with the name, saved in the QGIS settings for this geometry check.
const QgsGeometryCheckContext * mContext
ChangeWhat
Description of a change to indicate at which level a change occurred.
@ ChangeRing
This change happens on ring level.
@ ChangeFeature
This change happens on feature level.
@ ChangePart
This change happens on part level.
Flag
Flags for geometry checks.
CheckType
The type of a check.
@ FeatureNodeCheck
The check controls individual nodes.
@ FeatureCheck
The check controls geometries as a whole.
QVariantMap mConfiguration
ChangeType
Description of the type of a change.
@ ChangeAdded
Something has been added.
@ ChangeRemoved
Something has been removed.
virtual ~QgsGeometryCheck()=default
virtual QList< Qgis::GeometryType > compatibleGeometryTypes() const =0
A list of geometry types for which this check can be performed.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
Represents a vector layer which manages a vector based data sets.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_INOUT
Definition qgis_sip.h:71
Descripts a change to fix a geometry.
Change(QgsGeometryCheck::ChangeWhat _what, QgsGeometryCheck::ChangeType _type, QgsVertexId _vidx=QgsVertexId())
Create a new Change.
QgsGeometryCheck::ChangeType type
What action this change performs.
QgsVertexId vidx
The index of the part / ring / vertex, depending on.
QgsGeometryCheck::ChangeWhat what
What level this change affects.
bool operator==(const QgsGeometryCheck::Change &other) const
bool operator!=(const QgsGeometryCheck::Change &other) const
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