Skip to content

Commit 4e9c4b5

Browse files
authored
Merge pull request #9504 from m-kuhn/geometry_validator_zoom_to_improvements
Disable automatic zoom to problem when fixing errors on geometries
2 parents 7653e45 + d37546e commit 4e9c4b5

4 files changed

+33
-0
lines changed

src/app/qgsgeometryvalidationdock.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void QgsGeometryValidationDock::setGeometryValidationModel( QgsGeometryValidatio
8787
connect( mGeometryValidationModel, &QgsGeometryValidationModel::dataChanged, this, &QgsGeometryValidationDock::onDataChanged );
8888
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsRemoved, this, &QgsGeometryValidationDock::updateCurrentError );
8989
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsInserted, this, &QgsGeometryValidationDock::onRowsInserted );
90+
91+
// We cannot connect to the regular aboutToRemoveRows signal, because we need this to happen
92+
// before the currentIndex is changed.
93+
connect( mGeometryValidationModel, &QgsGeometryValidationModel::aboutToRemoveSingleGeometryCheck, this, [this]() { mPreventZoomToError = true; } );
94+
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsRemoved, this, [this]() { mPreventZoomToError = false; } );
9095
}
9196

9297
void QgsGeometryValidationDock::gotoNextError()
@@ -244,6 +249,20 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex &curren
244249

245250
bool hasFeature = !FID_IS_NULL( current.data( QgsGeometryValidationModel::ErrorFeatureIdRole ) );
246251
mZoomToFeatureButton->setEnabled( hasFeature );
252+
253+
if ( !mPreventZoomToError )
254+
{
255+
switch ( mLastZoomToAction )
256+
{
257+
case ZoomToProblem:
258+
zoomToProblem();
259+
break;
260+
261+
case ZoomToFeature:
262+
zoomToFeature();
263+
break;
264+
}
265+
}
247266
}
248267

249268
void QgsGeometryValidationDock::onCurrentLayerChanged( QgsMapLayer *layer )

src/app/qgsgeometryvalidationdock.h

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
8080
QgsRubberBand *mErrorRubberband = nullptr;
8181
QgsRubberBand *mErrorLocationRubberband = nullptr;
8282
QgsVectorLayer *mCurrentLayer = nullptr;
83+
bool mPreventZoomToError = false;
8384
};
8485

8586
#endif // QGSGEOMETRYVALIDATIONPANEL_H

src/app/qgsgeometryvalidationmodel.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ void QgsGeometryValidationModel::onSingleGeometryCheckCleared( QgsVectorLayer *l
257257

258258
if ( mCurrentLayer == layer && !layerErrors.empty() )
259259
{
260+
emit aboutToRemoveSingleGeometryCheck();
260261
beginRemoveRows( QModelIndex(), 0, layerErrors.size() - 1 );
261262
}
262263

@@ -279,7 +280,10 @@ void QgsGeometryValidationModel::onGeometryCheckCompleted( QgsVectorLayer *layer
279280
if ( featureIdx > -1 && errors.empty() ) // && !mGeometryValidationService->validationActive( layer, fid ) )
280281
{
281282
if ( mCurrentLayer == layer )
283+
{
284+
emit aboutToRemoveSingleGeometryCheck();
282285
beginRemoveRows( QModelIndex(), featureIdx, featureIdx );
286+
}
283287

284288
layerErrors.removeAt( featureIdx );
285289

src/app/qgsgeometryvalidationmodel.h

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ class QgsGeometryValidationModel : public QAbstractItemModel
4949

5050
QgsVectorLayer *currentLayer() const;
5151

52+
signals:
53+
54+
/**
55+
* Emitted before single geometry check results are removed.
56+
* This is guaranteed to be emitted before the models regular
57+
* aboutToRemoveRows() signal.
58+
*/
59+
void aboutToRemoveSingleGeometryCheck();
60+
5261
public slots:
5362
void setCurrentLayer( QgsVectorLayer *currentLayer );
5463

0 commit comments

Comments
 (0)