QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
33 class QgsFeaturePool;
34 
91 class ANALYSIS_EXPORT QgsGeometryCheck
92 {
93  Q_GADGET
94  Q_DECLARE_TR_FUNCTIONS( QgsGeometryCheck )
95 
96  public:
97 
105  struct ANALYSIS_EXPORT LayerFeatureIds
106  {
107  LayerFeatureIds() = default;
108  LayerFeatureIds( const QMap<QString, QgsFeatureIds> &idsIn ) SIP_SKIP;
109 
110  QMap<QString, QgsFeatureIds> ids SIP_SKIP;
111 
112 #ifndef SIP_RUN
113  QMap<QString, QgsFeatureIds> toMap() const
114  {
115  return ids;
116  }
117 
118  bool isEmpty() const
119  {
120  return ids.isEmpty();
121  }
122 #endif
123  };
124 
131  {
135  ChangeNode
136  };
137 
144  {
147  ChangeChanged
148  };
149 
156  {
159  LayerCheck
160  };
161 
165  enum Flag
166  {
167  AvailableInValidation = 1 << 1
168  };
169  Q_DECLARE_FLAGS( Flags, Flag )
170  Q_FLAG( Flags )
171 
172 
177  struct Change
178  {
179  Change() = default;
180 
185  : what( _what )
186  , type( _type )
187  , vidx( _vidx )
188  {}
189 
194 
199 
205  {
206  return what == other.what && type == other.type && vidx == other.vidx;
207  }
208  };
209 
214  typedef QMap<QString, QMap<QgsFeatureId, QList<QgsGeometryCheck::Change> > > Changes;
215 
219  QgsGeometryCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
220  virtual ~QgsGeometryCheck() = default;
221 
227  virtual void prepare( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
228 
229 #ifndef SIP_RUN
230 
235  template <class T>
236  T configurationValue( const QString &name, const QVariant &defaultValue = QVariant() )
237  {
238  return mConfiguration.value( name, QgsSettings().value( "/geometry_checker/" + id() + "/" + name, defaultValue ) ).value<T>();
239  }
240 #endif
241 
248  virtual bool isCompatible( QgsVectorLayer *layer ) const;
249 
255  virtual QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const = 0;
256 
260  virtual QgsGeometryCheck::Flags flags() const;
261 
270  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;
271 
279  virtual void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes SIP_INOUT ) const SIP_SKIP;
280 
286  virtual QList<QgsGeometryCheckResolutionMethod> availableResolutionMethods() const;
287 
295  Q_DECL_DEPRECATED virtual QStringList resolutionMethods() const SIP_DEPRECATED;
296 
302  virtual QString description() const = 0;
303 
309  virtual QString id() const = 0;
310 
316  virtual CheckType checkType() const = 0;
317 
323  const QgsGeometryCheckContext *context() const { return mContext; }
324 
325  protected:
326 
333  QMap<QString, QgsFeatureIds> allLayerFeatureIds( const QMap<QString, QgsFeaturePool *> &featurePools ) const SIP_SKIP;
334 
341  void replaceFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, QgsAbstractGeometry *newPartGeom, Changes &changes ) const SIP_SKIP;
342 
349  void deleteFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes ) const SIP_SKIP;
350 
357  void deleteFeatureGeometryRing( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, int ringIdx, Changes &changes ) const SIP_SKIP;
358 
360  QVariantMap mConfiguration;
361 
368  double scaleFactor( const QPointer<QgsVectorLayer> &layer ) const SIP_SKIP;
369 };
370 
371 #endif // QGS_GEOMETRY_CHECK_H
QgsGeometryCheck::Change
Descripts a change to fix a geometry.
Definition: qgsgeometrycheck.h:177
QgsGeometryCheck::ChangeType
ChangeType
Description of the type of a change.
Definition: qgsgeometrycheck.h:143
QgsGeometryCheck::Flag
Flag
Flags for geometry checks.
Definition: qgsgeometrycheck.h:165
QgsGeometryCheck::ChangeAdded
@ ChangeAdded
Something has been added.
Definition: qgsgeometrycheck.h:145
QgsGeometryCheck::ChangeFeature
@ ChangeFeature
This change happens on feature level.
Definition: qgsgeometrycheck.h:132
QgsGeometryCheck::Change::Change
Change(QgsGeometryCheck::ChangeWhat _what, QgsGeometryCheck::ChangeType _type, QgsVertexId _vidx=QgsVertexId())
Create a new Change.
Definition: qgsgeometrycheck.h:184
QgsGeometryCheck::Change::what
QgsGeometryCheck::ChangeWhat what
What level this change affects.
Definition: qgsgeometrycheck.h:193
QgsGeometryCheck::Changes
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
Definition: qgsgeometrycheck.h:214
QgsGeometryCheck::LayerFeatureIds::isEmpty
bool isEmpty() const
Definition: qgsgeometrycheck.h:118
qgsfeature.h
QgsGeometryCheck::FeatureNodeCheck
@ FeatureNodeCheck
The check controls individual nodes.
Definition: qgsgeometrycheck.h:157
QgsGeometryCheck::mConfiguration
QVariantMap mConfiguration
Definition: qgsgeometrycheck.h:360
QgsSettings
Definition: qgssettings.h:61
QgsGeometryCheck::LayerFeatureIds::toMap
QMap< QString, QgsFeatureIds > toMap() const
Definition: qgsgeometrycheck.h:113
QgsGeometryCheck::ChangeRemoved
@ ChangeRemoved
Something has been removed.
Definition: qgsgeometrycheck.h:146
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsGeometryCheck
Definition: qgsgeometrycheck.h:91
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsFeedback
Definition: qgsfeedback.h:43
QgsGeometryCheck::configurationValue
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.
Definition: qgsgeometrycheck.h:236
QgsGeometryCheckContext
Definition: qgsgeometrycheckcontext.h:31
QgsGeometryCheck::ChangeWhat
ChangeWhat
Description of a change to indicate at which level a change occurred.
Definition: qgsgeometrycheck.h:130
QgsGeometryCheck::LayerFeatureIds
A list of layers and feature ids for each of these layers.
Definition: qgsgeometrycheck.h:105
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:71
QgsGeometryCheck::Change::operator==
bool operator==(const QgsGeometryCheck::Change &other)
Definition: qgsgeometrycheck.h:204
SIP_INOUT
#define SIP_INOUT
Definition: qgis_sip.h:71
QgsGeometryCheck::mContext
const QgsGeometryCheckContext * mContext
Definition: qgsgeometrycheck.h:359
qgsvectorlayer.h
QgsGeometryCheck::Change::vidx
QgsVertexId vidx
The index of the part / ring / vertex, depending on.
Definition: qgsgeometrycheck.h:203
qgsgeometry.h
QgsGeometryCheck::ChangePart
@ ChangePart
This change happens on part level.
Definition: qgsgeometrycheck.h:133
QgsGeometryCheck::ChangeRing
@ ChangeRing
This change happens on ring level.
Definition: qgsgeometrycheck.h:134
QgsGeometryCheck::Change::type
QgsGeometryCheck::ChangeType type
What action this change performs.
Definition: qgsgeometrycheck.h:198
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgsgeometrycheckerutils.h
QgsGeometryCheck::CheckType
CheckType
The type of a check.
Definition: qgsgeometrycheck.h:155
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsabstractgeometry.h:1033
qgssettings.h
QgsFeature
Definition: qgsfeature.h:55
QgsGeometryCheck::FeatureCheck
@ FeatureCheck
The check controls geometries as a whole.
Definition: qgsgeometrycheck.h:158
QgsGeometryCheckError
Definition: qgsgeometrycheckerror.h:35
qgsgeometrycheckresolutionmethod.h
QgsFeaturePool
Definition: qgsfeaturepool.h:37