Skip to content

Commit

Permalink
Merge pull request #9504 from m-kuhn/geometry_validator_zoom_to_impro…
Browse files Browse the repository at this point in the history
…vements

Disable automatic zoom to problem when fixing errors on geometries
  • Loading branch information
m-kuhn committed Mar 18, 2019
2 parents 7653e45 + d37546e commit 4e9c4b5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/qgsgeometryvalidationdock.cpp
Expand Up @@ -87,6 +87,11 @@ void QgsGeometryValidationDock::setGeometryValidationModel( QgsGeometryValidatio
connect( mGeometryValidationModel, &QgsGeometryValidationModel::dataChanged, this, &QgsGeometryValidationDock::onDataChanged );
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsRemoved, this, &QgsGeometryValidationDock::updateCurrentError );
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsInserted, this, &QgsGeometryValidationDock::onRowsInserted );

// We cannot connect to the regular aboutToRemoveRows signal, because we need this to happen
// before the currentIndex is changed.
connect( mGeometryValidationModel, &QgsGeometryValidationModel::aboutToRemoveSingleGeometryCheck, this, [this]() { mPreventZoomToError = true; } );
connect( mGeometryValidationModel, &QgsGeometryValidationModel::rowsRemoved, this, [this]() { mPreventZoomToError = false; } );
}

void QgsGeometryValidationDock::gotoNextError()
Expand Down Expand Up @@ -244,6 +249,20 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex &curren

bool hasFeature = !FID_IS_NULL( current.data( QgsGeometryValidationModel::ErrorFeatureIdRole ) );
mZoomToFeatureButton->setEnabled( hasFeature );

if ( !mPreventZoomToError )
{
switch ( mLastZoomToAction )
{
case ZoomToProblem:
zoomToProblem();
break;

case ZoomToFeature:
zoomToFeature();
break;
}
}
}

void QgsGeometryValidationDock::onCurrentLayerChanged( QgsMapLayer *layer )
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsgeometryvalidationdock.h
Expand Up @@ -80,6 +80,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
QgsRubberBand *mErrorRubberband = nullptr;
QgsRubberBand *mErrorLocationRubberband = nullptr;
QgsVectorLayer *mCurrentLayer = nullptr;
bool mPreventZoomToError = false;
};

#endif // QGSGEOMETRYVALIDATIONPANEL_H
4 changes: 4 additions & 0 deletions src/app/qgsgeometryvalidationmodel.cpp
Expand Up @@ -257,6 +257,7 @@ void QgsGeometryValidationModel::onSingleGeometryCheckCleared( QgsVectorLayer *l

if ( mCurrentLayer == layer && !layerErrors.empty() )
{
emit aboutToRemoveSingleGeometryCheck();
beginRemoveRows( QModelIndex(), 0, layerErrors.size() - 1 );
}

Expand All @@ -279,7 +280,10 @@ void QgsGeometryValidationModel::onGeometryCheckCompleted( QgsVectorLayer *layer
if ( featureIdx > -1 && errors.empty() ) // && !mGeometryValidationService->validationActive( layer, fid ) )
{
if ( mCurrentLayer == layer )
{
emit aboutToRemoveSingleGeometryCheck();
beginRemoveRows( QModelIndex(), featureIdx, featureIdx );
}

layerErrors.removeAt( featureIdx );

Expand Down
9 changes: 9 additions & 0 deletions src/app/qgsgeometryvalidationmodel.h
Expand Up @@ -49,6 +49,15 @@ class QgsGeometryValidationModel : public QAbstractItemModel

QgsVectorLayer *currentLayer() const;

signals:

/**
* Emitted before single geometry check results are removed.
* This is guaranteed to be emitted before the models regular
* aboutToRemoveRows() signal.
*/
void aboutToRemoveSingleGeometryCheck();

public slots:
void setCurrentLayer( QgsVectorLayer *currentLayer );

Expand Down

0 comments on commit 4e9c4b5

Please sign in to comment.