QGIS API Documentation  3.6.0-Noosa (5873452)
qgsgeometryduplicatecheck.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometryduplicatecheck.h
3  ---------------------
4  begin : September 2015
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 #define SIP_NO_FILE
17 
18 #ifndef QGS_GEOMETRY_DUPLICATE_CHECK_H
19 #define QGS_GEOMETRY_DUPLICATE_CHECK_H
20 
22 #include "qgsgeometrycheck.h"
23 #include "qgsgeometrycheckerror.h"
24 
29 {
30  public:
32  const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
33  const QgsPointXY &errorLocation,
34  const QMap<QString, QgsFeaturePool *> &featurePools,
35  const QMap<QString, QList<QgsFeatureId>> &duplicates )
36  : QgsGeometryCheckError( check, layerFeature, errorLocation, QgsVertexId(), duplicatesString( featurePools, duplicates ) )
37  , mDuplicates( duplicates )
38  { }
39  QMap<QString, QList<QgsFeatureId>> duplicates() const { return mDuplicates; }
40 
41  bool isEqual( QgsGeometryCheckError *other ) const override
42  {
43  return other->check() == check() &&
44  other->layerId() == layerId() &&
45  other->featureId() == featureId() &&
46  // static_cast: since other->checker() == checker is only true if the types are actually the same
47  static_cast<QgsGeometryDuplicateCheckError *>( other )->duplicates() == duplicates();
48  }
49 
50  private:
51  QMap<QString, QList<QgsFeatureId>> mDuplicates;
52 
53  static QString duplicatesString( const QMap<QString, QgsFeaturePool *> &featurePools, const QMap<QString, QList<QgsFeatureId>> &duplicates );
54 };
55 
59 class ANALYSIS_EXPORT QgsGeometryDuplicateCheck : public QgsGeometryCheck
60 {
61  public:
62  explicit QgsGeometryDuplicateCheck( QgsGeometryCheckContext *context, const QVariantMap &configuration )
63  : QgsGeometryCheck( context, configuration ) {}
64  void collectErrors( const QMap<QString, QgsFeaturePool *> &featurePools, QList<QgsGeometryCheckError *> &errors, QStringList &messages, QgsFeedback *feedback, const LayerFeatureIds &ids = LayerFeatureIds() ) const override;
65  void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
66 
67  QList<QgsWkbTypes::GeometryType> compatibleGeometryTypes() const override { return factoryCompatibleGeometryTypes(); }
68  QStringList resolutionMethods() const override;
69  QString description() const override { return factoryDescription(); }
70  QString id() const override { return factoryId(); }
71  QgsGeometryCheck::CheckType checkType() const override { return factoryCheckType(); }
72 
74  static bool factoryIsCompatible( QgsVectorLayer *layer ) SIP_SKIP { return factoryCompatibleGeometryTypes().contains( layer->geometryType() ); }
75  static QString factoryDescription() { return tr( "Duplicate" ); }
76  static QString factoryId();
77  static QgsGeometryCheck::CheckType factoryCheckType();
78 
79  enum ResolutionMethod { NoChange, RemoveDuplicates };
80 };
81 
82 #endif // QGS_GEOMETRY_DUPLICATE_CHECK_H
static QList< QgsWkbTypes::GeometryType > factoryCompatibleGeometryTypes()
A class to represent a 2D point.
Definition: qgspointxy.h:43
CheckType
The type of a check.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
static bool factoryIsCompatible(QgsVectorLayer *layer)
Base configuration for geometry checks.
const QgsGeometryCheck * check() const
The geometry check that created this error.
Utility class for identifying a unique vertex within a geometry.
#define SIP_SKIP
Definition: qgis_sip.h:119
A layer feature combination to uniquely identify and access a feature in a set of layers...
This class implements a geometry check.
const QString & layerId() const
The id of the layer on which this error has been detected.
A list of layers and feature ids for each of these layers.
QString description() const override
Returns a human readable description for this check.
QMap< QString, QList< QgsFeatureId > > duplicates() const
QgsGeometryDuplicateCheck(QgsGeometryCheckContext *context, const QVariantMap &configuration)
bool isEqual(QgsGeometryCheckError *other) const override
Check if this error is equal to other.
QMap< QString, QMap< QgsFeatureId, QList< QgsGeometryCheck::Change > > > Changes
A collection of changes.
QList< QgsWkbTypes::GeometryType > compatibleGeometryTypes() const override
A list of geometry types for which this check can be performed.
virtual void fixError(const QMap< QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap< QString, int > &mergeAttributeIndices, Changes &changes) const
Fix the error error with the specified method.
QString id() const override
Returns an id for this check.
QgsGeometryDuplicateCheckError(const QgsGeometryCheck *check, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, const QgsPointXY &errorLocation, const QMap< QString, QgsFeaturePool *> &featurePools, const QMap< QString, QList< QgsFeatureId >> &duplicates)
virtual QStringList resolutionMethods() const =0
Returns a list of descriptions for available resolutions for errors.
QgsFeatureId featureId() const
The id of the feature on which this error has been detected.
QgsGeometryCheck::CheckType checkType() const override
Returns the check type.
This represents an error reported by a geometry check.
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.
Represents a vector layer which manages a vector based data sets.