Skip to content

Commit 732ce4c

Browse files
committed
[Geometry checker] Handle fid changes
1 parent 9cbaebe commit 732ce4c

16 files changed

+146
-4
lines changed

src/plugins/geometry_checker/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ SET (geometrychecker_HDRS
3939
checks/qgsgeometrycheck.h
4040
qgsgeometrycheckerplugin.h
4141
qgsgeometrycheckfactory.h
42-
utils/qgsfeaturepool.h
4342
utils/qgsgeometrycheckerutils.h
4443
)
4544

@@ -71,6 +70,7 @@ SET (geometrychecker_MOC_HDRS
7170
ui/qgsgeometrycheckerresulttab.h
7271
ui/qgsgeometrycheckfixdialog.h
7372
ui/qgsgeometrycheckerfixsummarydialog.h
73+
utils/qgsfeaturepool.h
7474
)
7575

7676
SET (geometrychecker_UIS

src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes &chan
143143
return true;
144144
}
145145

146+
bool QgsGeometryCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
147+
{
148+
if ( layerId == mLayerId )
149+
{
150+
QgsFeatureId oldId = mFeatureId;
151+
mFeatureId = oldNewFidMap.value( mFeatureId, mFeatureId );
152+
return oldId != mFeatureId;
153+
}
154+
return false;
155+
}
156+
146157
QMap<QString, QgsFeatureIds> QgsGeometryCheck::allLayerFeatureIds() const
147158
{
148159
QMap<QString, QgsFeatureIds> featureIds;

src/plugins/geometry_checker/checks/qgsgeometrycheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class QgsGeometryCheckError
159159
}
160160

161161
virtual bool handleChanges( const QgsGeometryCheck::Changes &changes );
162+
virtual bool handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap );
162163

163164
protected:
164165
// Users of this constructor must ensure geometry and errorLocation are in map coordinates

src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
#include "qgsgeometrycontainedcheck.h"
1818
#include "../utils/qgsfeaturepool.h"
1919

20+
21+
bool QgsGeometryContainedCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
22+
{
23+
bool changed = QgsGeometryCheckError::handleFidChanges( layerId, oldNewFidMap );
24+
if ( mContainingFeature.first == layerId )
25+
{
26+
QgsFeatureId oldId = mContainingFeature.second;
27+
mContainingFeature.second = oldNewFidMap.value( mContainingFeature.second, mContainingFeature.second );
28+
changed |= ( oldId != mContainingFeature.second );
29+
}
30+
return changed;
31+
}
32+
2033
void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
2134
{
2235
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds() : ids;

src/plugins/geometry_checker/checks/qgsgeometrycontainedcheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class QgsGeometryContainedCheckError : public QgsGeometryCheckError
3939
}
4040

4141
virtual QString description() const override { return QApplication::translate( "QgsGeometryContainedCheckError", "Within feature" ); }
42+
bool handleFidChanges( const QString& layerId, const QMap<QgsFeatureId, QgsFeatureId>& oldNewFidMap) override;
4243

4344
private:
4445
QPair<QString, QgsFeatureId> mContainingFeature;

src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
#include "qgsgeometry.h"
2020
#include "../utils/qgsfeaturepool.h"
2121

22+
23+
bool QgsGeometryDuplicateCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
24+
{
25+
bool changed = QgsGeometryCheckError::handleFidChanges( layerId, oldNewFidMap );
26+
if ( mDuplicates.contains( layerId ) )
27+
{
28+
QList<QgsFeatureId> &fids = mDuplicates[layerId];
29+
for ( int i = 0, n = fids.size(); i < n; ++i )
30+
{
31+
QgsFeatureId oldId = fids[i];
32+
fids[i] = oldNewFidMap.value( fids[i], fids[i] );
33+
changed |= ( oldId != fids[i] );
34+
}
35+
}
36+
return changed;
37+
}
38+
39+
2240
void QgsGeometryDuplicateCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
2341
{
2442
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds() : ids;

src/plugins/geometry_checker/checks/qgsgeometryduplicatecheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QgsGeometryDuplicateCheckError : public QgsGeometryCheckError
3838
// static_cast: since other->checker() == checker is only true if the types are actually the same
3939
static_cast<QgsGeometryDuplicateCheckError *>( other )->duplicates() == duplicates();
4040
}
41+
bool handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap ) override;
4142

4243
private:
4344
QMap<QString, QList<QgsFeatureId>> mDuplicates;

src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@
1818
#include "qgsgeometrycollection.h"
1919
#include "../utils/qgsfeaturepool.h"
2020

21+
bool QgsGeometryGapCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
22+
{
23+
bool changed = false;
24+
if ( mNeighbors.contains( layerId ) )
25+
{
26+
QgsFeatureIds &fids = mNeighbors[layerId];
27+
QgsFeatureIds newIds;
28+
for ( auto it = fids.begin(), itEnd = fids.end(); it != itEnd; ++it )
29+
{
30+
const QgsFeatureId &fid = *it;
31+
QgsFeatureId newId = oldNewFidMap.value( fid, fid );
32+
if ( fid != newId )
33+
{
34+
it = fids.erase( it );
35+
newIds.insert( newId );
36+
changed = true;
37+
}
38+
}
39+
fids.unite( newIds );
40+
}
41+
return changed;
42+
}
43+
2144

2245
void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
2346
{

src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class QgsGeometryGapCheckError : public QgsGeometryCheckError
6666
return mGapAreaBBox;
6767
}
6868

69+
bool handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap ) override;
70+
6971
private:
7072
QMap<QString, QgsFeatureIds> mNeighbors;
7173
QgsRectangle mGapAreaBBox;

src/plugins/geometry_checker/checks/qgsgeometryoverlapcheck.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
#include "qgsgeometryoverlapcheck.h"
1818
#include "../utils/qgsfeaturepool.h"
1919

20+
21+
bool QgsGeometryOverlapCheckError::handleFidChanges( const QString &layerId, const QMap<QgsFeatureId, QgsFeatureId> &oldNewFidMap )
22+
{
23+
bool changed = QgsGeometryCheckError::handleFidChanges( layerId, oldNewFidMap );
24+
if ( mOverlappedFeature.first == layerId )
25+
{
26+
QgsFeatureId oldId = mOverlappedFeature.second;
27+
mOverlappedFeature.second = oldNewFidMap.value( mOverlappedFeature.second, mOverlappedFeature.second );
28+
changed |= ( oldId != mOverlappedFeature.second );
29+
}
30+
return changed;
31+
}
32+
2033
void QgsGeometryOverlapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &messages, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
2134
{
2235
double overlapThreshold = mThresholdMapUnits;

0 commit comments

Comments
 (0)