Skip to content

Commit e9e849a

Browse files
3nidsm-kuhn
authored andcommitted
disable topology check button if layer not editable
1 parent d527fed commit e9e849a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/app/qgsgeometryvalidationdock.cpp

+25-5
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,33 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex &curren
260260

261261
void QgsGeometryValidationDock::onCurrentLayerChanged( QgsMapLayer *layer )
262262
{
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+
{
264285
bool enabled = false;
265-
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
266-
if ( vl && vl->isSpatial() )
286+
if ( mCurrentLayer && mCurrentLayer->isSpatial() && mCurrentLayer->isEditable() )
267287
{
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();
270290
for ( const QgsGeometryCheckFactory *factory : topologyCheckFactories )
271291
{
272292
if ( activeChecks.contains( factory->id() ) )

src/app/qgsgeometryvalidationdock.h

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class QgsGeometryValidationModel;
2525
class QgsGeometryValidationService;
2626
class QgsRubberBand;
2727
class QgisApp;
28+
class QgsVectorLayer;
2829

2930
/**
3031
* @brief The QgsGeometryValidationDock class
@@ -46,6 +47,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
4647
void updateCurrentError();
4748
void onCurrentErrorChanged( const QModelIndex &current, const QModelIndex &previous );
4849
void onCurrentLayerChanged( QgsMapLayer *layer );
50+
void onLayerEditingStatusChanged();
4951
void gotoNextError();
5052
void gotoPreviousError();
5153
void zoomToProblem();
@@ -76,6 +78,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
7678
QgsRubberBand *mFeatureRubberband = nullptr;
7779
QgsRubberBand *mErrorRubberband = nullptr;
7880
QgsRubberBand *mErrorLocationRubberband = nullptr;
81+
QgsVectorLayer *mCurrentLayer;
7982
};
8083

8184
#endif // QGSGEOMETRYVALIDATIONPANEL_H

0 commit comments

Comments
 (0)