@@ -260,13 +260,33 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex ¤
260
260
261
261
void QgsGeometryValidationDock::onCurrentLayerChanged ( QgsMapLayer *layer )
262
262
{
263
- // activate icon
263
+ if ( layer == mCurrentLayer )
264
+ return ;
265
+
266
+ if ( mCurrentLayer )
267
+ {
268
+ disconnect ( mCurrentLayer , &QgsVectorLayer::editingStarted, this , &QgsGeometryValidationDock::onLayerEditingStatusChanged );
269
+ disconnect ( mCurrentLayer , &QgsVectorLayer::editingStopped, this , &QgsGeometryValidationDock::onLayerEditingStatusChanged );
270
+ }
271
+
272
+ mCurrentLayer = qobject_cast<QgsVectorLayer *>( layer );
273
+
274
+ if ( mCurrentLayer )
275
+ {
276
+ connect ( mCurrentLayer , &QgsVectorLayer::editingStarted, this , &QgsGeometryValidationDock::onLayerEditingStatusChanged );
277
+ connect ( mCurrentLayer , &QgsVectorLayer::editingStopped, this , &QgsGeometryValidationDock::onLayerEditingStatusChanged );
278
+ }
279
+
280
+ onLayerEditingStatusChanged ();
281
+ }
282
+
283
+ void QgsGeometryValidationDock::onLayerEditingStatusChanged ()
284
+ {
264
285
bool enabled = false ;
265
- QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
266
- if ( vl && vl->isSpatial () )
286
+ if ( mCurrentLayer && mCurrentLayer ->isSpatial () && mCurrentLayer ->isEditable () )
267
287
{
268
- const QList<QgsGeometryCheckFactory *> topologyCheckFactories = QgsAnalysis::instance ()->geometryCheckRegistry ()->geometryCheckFactories ( vl , QgsGeometryCheck::LayerCheck, QgsGeometryCheck::Flag::AvailableInValidation );
269
- const QStringList activeChecks = vl ->geometryOptions ()->geometryChecks ();
288
+ const QList<QgsGeometryCheckFactory *> topologyCheckFactories = QgsAnalysis::instance ()->geometryCheckRegistry ()->geometryCheckFactories ( mCurrentLayer , QgsGeometryCheck::LayerCheck, QgsGeometryCheck::Flag::AvailableInValidation );
289
+ const QStringList activeChecks = mCurrentLayer ->geometryOptions ()->geometryChecks ();
270
290
for ( const QgsGeometryCheckFactory *factory : topologyCheckFactories )
271
291
{
272
292
if ( activeChecks.contains ( factory->id () ) )
0 commit comments