From e77bab9d2c8fbb929b994a6e1692c22eb629beec Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 1 Oct 2018 14:37:38 -0400 Subject: [PATCH] enable zoom button only if error has feature --- src/app/qgsgeometryvalidationdock.cpp | 3 +++ src/app/qgsgeometryvalidationmodel.cpp | 18 ++++++++++++++++-- src/app/qgsgeometryvalidationmodel.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/app/qgsgeometryvalidationdock.cpp b/src/app/qgsgeometryvalidationdock.cpp index ade12df8a99..68530d12a7e 100644 --- a/src/app/qgsgeometryvalidationdock.cpp +++ b/src/app/qgsgeometryvalidationdock.cpp @@ -178,6 +178,9 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex ¤ } } + bool hasFeature = !FID_IS_NULL( current.data( QgsGeometryValidationModel::ErrorFeatureIdRole ) ); + mZoomToFeatureButton->setEnabled( hasFeature ); + showHighlight( current ); switch ( mLastZoomToAction ) diff --git a/src/app/qgsgeometryvalidationmodel.cpp b/src/app/qgsgeometryvalidationmodel.cpp index d826affd1ba..e34a33a124a 100644 --- a/src/app/qgsgeometryvalidationmodel.cpp +++ b/src/app/qgsgeometryvalidationmodel.cpp @@ -91,11 +91,20 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role ) return topologyError->geometry(); } + case ErrorFeatureIdRole: + { + return topologyError->featureId(); + } + case FeatureGeometryRole: { const QgsFeatureId fid = topologyError->featureId(); - const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached! - return feature.geometry(); + if ( !FID_IS_NULL( fid ) ) + { + const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached! + return feature.geometry(); + } + return QgsGeometry(); } case ErrorLocationGeometryRole: @@ -149,6 +158,11 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role ) break; } + case ErrorFeatureIdRole: + { + return featureItem.fid; + } + case FeatureExtentRole: { return mCurrentLayer->getFeature( featureItem.fid ).geometry().boundingBox(); diff --git a/src/app/qgsgeometryvalidationmodel.h b/src/app/qgsgeometryvalidationmodel.h index 96fb136e18b..b3cf0908275 100644 --- a/src/app/qgsgeometryvalidationmodel.h +++ b/src/app/qgsgeometryvalidationmodel.h @@ -18,6 +18,7 @@ class QgsGeometryValidationModel : public QAbstractItemModel FeatureExtentRole = Qt::UserRole, ProblemExtentRole, ErrorGeometryRole, + ErrorFeatureIdRole, FeatureGeometryRole, ErrorLocationGeometryRole, GeometryCheckErrorRole,