QGIS API Documentation  3.6.0-Noosa (5873452)
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 "geometry/qgsgeometry.h"
29 #include "qgssettings.h"
30 
32 class QgsFeaturePool;
33 
125 class ANALYSIS_EXPORT QgsGeometryCheck
126 {
127  Q_GADGET
128  Q_DECLARE_TR_FUNCTIONS( QgsGeometryCheck )
129 
130  public:
131 
139  struct ANALYSIS_EXPORT LayerFeatureIds
140  {
141  LayerFeatureIds() = default;
142  LayerFeatureIds( const QMap<QString, QgsFeatureIds> &ids ) SIP_SKIP;
143 
144  QMap<QString, QgsFeatureIds> ids SIP_SKIP;
145 
146 #ifndef SIP_RUN
147  QMap<QString, QgsFeatureIds> toMap() const
148  {
149  return ids;
150  }
151 
152  bool isEmpty() const
153  {
154  return ids.isEmpty();
155  }
156 #endif
157  };
158 
165  {
169  ChangeNode
170  };
171 
178  {
181  ChangeChanged
182  };
183 
190  {
193  LayerCheck
194  };
195 
199  enum Flag
200  {
201  AvailableInValidation = 1 << 1
202  };
203  Q_DECLARE_FLAGS( Flags, Flag )
204  Q_FLAG( Flags )
205 
206 
211  struct Change
212  {
213  Change() = default;
214 
219  : what( _what )
220  , type( _type )
221  , vidx( _vidx )
222  {}
223 
228 
233 
239  {
240  return what == other.what && type == other.type && vidx == other.vidx;
241  }
242  };
243 
248  typedef QMap<QString, QMap<QgsFeatureId, QList<QgsGeometryCheck::Change> > > Changes;
249 
253  QgsGeometryCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration );
254  virtual ~QgsGeometryCheck() = default;
255 
256 #ifndef SIP_RUN
257 
262  template <class T>
263  T configurationValue( const QString &name, const QVariant &defaultValue = QVariant() )
264  {
265  return mConfiguration.value( name, QgsSettings().value( "/geometry_checker/" + id() + "/" + name, defaultValue ) ).value<T>();
266  }
267 #endif
268 
275  virtual bool isCompatible( QgsVectorLayer *layer ) const;
276 
282  virtual QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const = 0;
283 
287  virtual QgsGeometryCheck::Flags flags() const;
288 
297  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;
298 
304  virtual void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes SIP_INOUT ) const SIP_SKIP;
305 
311  virtual QStringList resolutionMethods() const = 0;
312 
318  virtual QString description() const = 0;
319 
325  virtual QString id() const = 0;
326 
332  virtual CheckType checkType() const = 0;
333 
339  const QgsGeometryCheckContext *context() const { return mContext; }
340 
341  protected:
342 
349  QMap<QString, QgsFeatureIds> allLayerFeatureIds( const QMap<QString, QgsFeaturePool *> &featurePools ) const SIP_SKIP;
350 
357  void replaceFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, QgsAbstractGeometry *newPartGeom, Changes &changes ) const SIP_SKIP;
358 
365  void deleteFeatureGeometryPart( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, Changes &changes ) const SIP_SKIP;
366 
373  void deleteFeatureGeometryRing( const QMap<QString, QgsFeaturePool *> &featurePools, const QString &layerId, QgsFeature &feature, int partIdx, int ringIdx, Changes &changes ) const SIP_SKIP;
374 
376  QVariantMap mConfiguration;
377 
384  double scaleFactor( const QPointer<QgsVectorLayer> &layer ) const SIP_SKIP;
385 };
386 
387 #endif // QGS_GEOMETRY_CHECK_H
This change happens on part level.
Flag
Flags for geometry checks.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
Something has been added.
bool operator==(const QgsGeometryCheck::Change &other)
QMap< QString, QgsFeatureIds > toMap() const
CheckType
The type of a check.
#define SIP_INOUT
Definition: qgis_sip.h:64
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QgsVertexId vidx
The index of the part / ring / vertex, depending on.
ChangeWhat
Description of a change to indicate at which level a change occurred.
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...
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
Base configuration for geometry checks.
The check controls geometries as a whole.
Something has been removed.
This change happens on ring level.
Utility class for identifying a unique vertex within a geometry.
#define SIP_SKIP
Definition: qgis_sip.h:119
QgsGeometryCheck::ChangeType type
What action this change performs.
QVariantMap mConfiguration
This class implements a geometry check.
Abstract base class for all geometries.
const QgsGeometryCheckContext * mContext
A list of layers and feature ids for each of these layers.
Change(QgsGeometryCheck::ChangeWhat _what, QgsGeometryCheck::ChangeType _type, QgsVertexId _vidx=QgsVertexId())
Create a new Change.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
A feature pool is based on a vector layer and caches features.
Descripts a change to fix a geometry.
ChangeType
Description of the type of a change.
QgsGeometryCheck::ChangeWhat what
What level this change affects.
const QgsGeometryCheckContext * context() const
Returns the context.
This represents an error reported by a geometry check.
Represents a vector layer which manages a vector based data sets.
This change happens on feature level.
The check controls individual nodes.