-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsgeometryduplicatecheck.h
80 lines (70 loc) · 3.65 KB
/
qgsgeometryduplicatecheck.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***************************************************************************
qgsgeometryduplicatecheck.h
---------------------
begin : September 2015
copyright : (C) 2014 by Sandro Mani / Sourcepole AG
email : smani at sourcepole dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGS_GEOMETRY_DUPLICATE_CHECK_H
#define QGS_GEOMETRY_DUPLICATE_CHECK_H
#include "qgsgeometrycheck.h"
class QgsGeometryDuplicateCheckError : public QgsGeometryCheckError
{
public:
QgsGeometryDuplicateCheckError( const QgsGeometryCheck *check,
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
const QgsPointXY &errorLocation,
const QMap<QString, QList<QgsFeatureId>> &duplicates )
: QgsGeometryCheckError( check, layerFeature, errorLocation, QgsVertexId(), duplicatesString( duplicates ) )
, mDuplicates( duplicates )
{ }
QMap<QString, QList<QgsFeatureId>> duplicates() const { return mDuplicates; }
bool isEqual( QgsGeometryCheckError *other ) const override
{
return other->check() == check() &&
other->layerId() == layerId() &&
other->featureId() == featureId() &&
// static_cast: since other->checker() == checker is only true if the types are actually the same
static_cast<QgsGeometryDuplicateCheckError *>( other )->duplicates() == duplicates();
}
bool handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap ) override;
private:
QMap<QString, QList<QgsFeatureId>> mDuplicates;
static inline QString duplicatesString( const QMap<QString, QList<QgsFeatureId>> &duplicates )
{
QStringList str;
for ( const QString &layerId : duplicates.keys() )
{
str.append( layerId + ": " );
QStringList ids;
for ( QgsFeatureId id : duplicates[layerId] )
{
ids.append( QString::number( id ) );
}
str.append( ids.join( ", " ) );
}
return str.join( QStringLiteral( "; " ) );
}
};
class QgsGeometryDuplicateCheck : public QgsGeometryCheck
{
Q_OBJECT
public:
explicit QgsGeometryDuplicateCheck( QgsGeometryCheckerContext *context )
: QgsGeometryCheck( FeatureCheck, {QgsWkbTypes::PointGeometry, QgsWkbTypes::PolygonGeometry}, context ) {}
void collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter = nullptr, const QMap<QString, QgsFeatureIds> &ids = QMap<QString, QgsFeatureIds>() ) const override;
void fixError( QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
QStringList getResolutionMethods() const override;
QString errorDescription() const override { return tr( "Duplicate" ); }
QString errorName() const override { return QStringLiteral( "QgsGeometryDuplicateCheck" ); }
private:
enum ResolutionMethod { NoChange, RemoveDuplicates };
};
#endif // QGS_GEOMETRY_DUPLICATE_CHECK_H