Skip to content

Commit 4d40d2f

Browse files
committed
Handle layer deleted
1 parent d0d08cc commit 4d40d2f

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/app/qgsgeometryvalidationservice.cpp

+23-7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ void QgsGeometryValidationService::onLayersAdded( const QList<QgsMapLayer *> &la
8181
enableLayerChecks( vectorLayer );
8282
}, Qt::UniqueConnection );
8383

84+
connect( vectorLayer, &QgsVectorLayer::destroyed, this, [vectorLayer, this]()
85+
{
86+
cleanupLayerChecks( vectorLayer );
87+
mLayerChecks.remove( vectorLayer );
88+
});
89+
8490
enableLayerChecks( vectorLayer );
8591
}
8692
}
@@ -100,8 +106,8 @@ void QgsGeometryValidationService::onGeometryChanged( QgsVectorLayer *layer, Qgs
100106
Q_UNUSED( geometry )
101107
// It would be nice to use the geometry here for the tests.
102108
// But:
103-
// 1. other codepaths to the checks also have no geometry (feature added / feature deleted)
104-
// 2. and looking it up from the edit buffer (in memory) is really fast.
109+
// 1. other codepaths to the checks also have no geometry (feature added / feature deleted)
110+
// 2. and looking it up from the edit buffer (in memory) is really fast.
105111
// so in short: it's still a good idea, but not as important as on first thought.
106112

107113
if ( !mLayerChecks[layer].topologyChecks.empty() )
@@ -135,9 +141,9 @@ void QgsGeometryValidationService::onBeforeCommitChanges( QgsVectorLayer *layer
135141
}
136142
}
137143

138-
void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
144+
void QgsGeometryValidationService::cleanupLayerChecks(QgsVectorLayer* layer)
139145
{
140-
if ( layer->geometryOptions()->geometryChecks().empty() && !mLayerChecks.contains( layer ) )
146+
if ( !mLayerChecks.contains( layer ) )
141147
return;
142148

143149
VectorLayerCheckInformation &checkInformation = mLayerChecks[layer];
@@ -146,7 +152,17 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
146152

147153
qDeleteAll( checkInformation.singleFeatureChecks );
148154
qDeleteAll( checkInformation.topologyChecks );
149-
delete checkInformation.context;
155+
checkInformation.context.reset();
156+
}
157+
158+
void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
159+
{
160+
if ( layer->geometryOptions()->geometryChecks().empty() && !mLayerChecks.contains( layer ) )
161+
return;
162+
163+
VectorLayerCheckInformation &checkInformation = mLayerChecks[layer];
164+
165+
cleanupLayerChecks( layer );
150166

151167
if ( layer->geometryOptions()->geometryChecks().empty() )
152168
{
@@ -174,7 +190,7 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
174190
if ( activeChecks.contains( checkId ) )
175191
{
176192
const QVariantMap checkConfiguration = layer->geometryOptions()->checkConfiguration( checkId );
177-
layerChecks.append( factory->createGeometryCheck( checkInformation.context, checkConfiguration ) );
193+
layerChecks.append( factory->createGeometryCheck( checkInformation.context.get(), checkConfiguration ) );
178194
}
179195
}
180196

@@ -197,7 +213,7 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
197213
if ( activeChecks.contains( checkId ) )
198214
{
199215
const QVariantMap checkConfiguration = layer->geometryOptions()->checkConfiguration( checkId );
200-
topologyChecks.append( factory->createGeometryCheck( checkInformation.context, checkConfiguration ) );
216+
topologyChecks.append( factory->createGeometryCheck( checkInformation.context.get(), checkConfiguration ) );
201217
}
202218
}
203219

src/app/qgsgeometryvalidationservice.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ email : matthias@opengis.ch
2222
#include <QReadWriteLock>
2323

2424
#include "qgsfeature.h"
25+
#include "qgsgeometrycheckcontext.h"
2526

2627
class QgsProject;
2728
class QgsMapLayer;
@@ -32,7 +33,6 @@ class QgsSingleGeometryCheckError;
3233
class QgsGeometryCheckError;
3334
class QgsFeedback;
3435
class QgsFeaturePool;
35-
struct QgsGeometryCheckContext;
3636

3737
/**
3838
* This service connects to all layers in a project and triggers validation
@@ -69,6 +69,7 @@ class QgsGeometryValidationService : public QObject
6969
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
7070
void topologyChecksUpdated( QgsVectorLayer *layer, const QList<std::shared_ptr<QgsGeometryCheckError> > &errors );
7171
void topologyChecksCleared( QgsVectorLayer *layer );
72+
void topologyErrorUpdated( QgsVectorLayer *layer, QgsGeometryCheckError *error );
7273

7374
void warning( const QString &message );
7475

@@ -80,6 +81,7 @@ class QgsGeometryValidationService : public QObject
8081
void onBeforeCommitChanges( QgsVectorLayer *layer );
8182

8283
private:
84+
void cleanupLayerChecks( QgsVectorLayer *layer );
8385
void enableLayerChecks( QgsVectorLayer *layer );
8486

8587
void cancelTopologyCheck( QgsVectorLayer *layer );
@@ -98,7 +100,7 @@ class QgsGeometryValidationService : public QObject
98100
QList<QgsFeedback *> topologyCheckFeedbacks; // will be deleted when topologyCheckFutureWatcher is delteed
99101
QList<std::shared_ptr<QgsGeometryCheckError>> topologyCheckErrors;
100102
QList<QMetaObject::Connection> connections;
101-
QgsGeometryCheckContext *context = nullptr;
103+
std::shared_ptr<QgsGeometryCheckContext> context;
102104
};
103105

104106
QReadWriteLock mTopologyCheckLock;

0 commit comments

Comments
 (0)