@@ -81,6 +81,12 @@ void QgsGeometryValidationService::onLayersAdded( const QList<QgsMapLayer *> &la
81
81
enableLayerChecks ( vectorLayer );
82
82
}, Qt::UniqueConnection );
83
83
84
+ connect ( vectorLayer, &QgsVectorLayer::destroyed, this , [vectorLayer, this ]()
85
+ {
86
+ cleanupLayerChecks ( vectorLayer );
87
+ mLayerChecks .remove ( vectorLayer );
88
+ });
89
+
84
90
enableLayerChecks ( vectorLayer );
85
91
}
86
92
}
@@ -100,8 +106,8 @@ void QgsGeometryValidationService::onGeometryChanged( QgsVectorLayer *layer, Qgs
100
106
Q_UNUSED ( geometry )
101
107
// It would be nice to use the geometry here for the tests.
102
108
// 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.
105
111
// so in short: it's still a good idea, but not as important as on first thought.
106
112
107
113
if ( !mLayerChecks [layer].topologyChecks .empty () )
@@ -135,9 +141,9 @@ void QgsGeometryValidationService::onBeforeCommitChanges( QgsVectorLayer *layer
135
141
}
136
142
}
137
143
138
- void QgsGeometryValidationService::enableLayerChecks ( QgsVectorLayer *layer )
144
+ void QgsGeometryValidationService::cleanupLayerChecks ( QgsVectorLayer* layer )
139
145
{
140
- if ( layer-> geometryOptions ()-> geometryChecks (). empty () && !mLayerChecks .contains ( layer ) )
146
+ if ( !mLayerChecks .contains ( layer ) )
141
147
return ;
142
148
143
149
VectorLayerCheckInformation &checkInformation = mLayerChecks [layer];
@@ -146,7 +152,17 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
146
152
147
153
qDeleteAll ( checkInformation.singleFeatureChecks );
148
154
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 );
150
166
151
167
if ( layer->geometryOptions ()->geometryChecks ().empty () )
152
168
{
@@ -174,7 +190,7 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
174
190
if ( activeChecks.contains ( checkId ) )
175
191
{
176
192
const QVariantMap checkConfiguration = layer->geometryOptions ()->checkConfiguration ( checkId );
177
- layerChecks.append ( factory->createGeometryCheck ( checkInformation.context , checkConfiguration ) );
193
+ layerChecks.append ( factory->createGeometryCheck ( checkInformation.context . get () , checkConfiguration ) );
178
194
}
179
195
}
180
196
@@ -197,7 +213,7 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
197
213
if ( activeChecks.contains ( checkId ) )
198
214
{
199
215
const QVariantMap checkConfiguration = layer->geometryOptions ()->checkConfiguration ( checkId );
200
- topologyChecks.append ( factory->createGeometryCheck ( checkInformation.context , checkConfiguration ) );
216
+ topologyChecks.append ( factory->createGeometryCheck ( checkInformation.context . get () , checkConfiguration ) );
201
217
}
202
218
}
203
219
0 commit comments