Skip to content

Commit 32c71b8

Browse files
committed
Better UX in geometry validation panel
1 parent baf1e52 commit 32c71b8

5 files changed

+58
-5
lines changed

src/app/qgsgeometryvalidationdock.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM
3737
connect( mMapCanvas, &QgsMapCanvas::currentLayerChanged, this, &QgsGeometryValidationDock::updateLayerTransform );
3838
connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsGeometryValidationDock::updateLayerTransform );
3939
connect( mMapCanvas, &QgsMapCanvas::transformContextChanged, this, &QgsGeometryValidationDock::updateLayerTransform );
40+
connect( mTopologyChecksPendingButton, &QToolButton::clicked, this, &QgsGeometryValidationDock::triggerTopologyChecks );
4041

4142
mFeatureRubberband = new QgsRubberBand( mMapCanvas );
4243
mErrorRubberband = new QgsRubberBand( mMapCanvas );
@@ -54,6 +55,8 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM
5455
mErrorLocationRubberband->setWidth( scaleFactor );
5556
mErrorLocationRubberband->setIconSize( scaleFactor * 5 );
5657
mErrorLocationRubberband->setColor( QColor( 50, 255, 50, 255 ) );
58+
59+
mProblemDetailWidget->setVisible( false );
5760
}
5861

5962

@@ -104,6 +107,13 @@ void QgsGeometryValidationDock::zoomToFeature()
104107
mMapCanvas->zoomToFeatureExtent( mapExtent );
105108
}
106109

110+
void QgsGeometryValidationDock::triggerTopologyChecks()
111+
{
112+
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
113+
if ( layer )
114+
mGeometryValidationService->triggerTopologyChecks( layer );
115+
}
116+
107117
void QgsGeometryValidationDock::updateLayerTransform()
108118
{
109119
if ( !mMapCanvas->currentLayer() )
@@ -130,13 +140,18 @@ QModelIndex QgsGeometryValidationDock::currentIndex() const
130140
void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex &current, const QModelIndex &previous )
131141
{
132142
Q_UNUSED( previous )
143+
144+
mProblemDetailWidget->setVisible( current.isValid() );
145+
133146
mNextButton->setEnabled( current.isValid() && current.row() < mGeometryValidationModel->rowCount() - 1 );
134147
mPreviousButton->setEnabled( current.isValid() && current.row() > 0 );
135148

136149
mProblemDetailWidget->setVisible( current.isValid() );
137-
mProblemDescriptionLabel->setText( current.data().toString() );
150+
mProblemDescriptionLabel->setText( current.data( QgsGeometryValidationModel::DetailsRole ).toString() );
151+
152+
QgsGeometryCheckError *error = current.data( QgsGeometryValidationModel::GeometryCheckErrorRole ).value<QgsGeometryCheckError *>();
153+
if ( error )
138154
{
139-
QgsGeometryCheckError *error = current.data( QgsGeometryValidationModel::GeometryCheckErrorRole ).value<QgsGeometryCheckError *>();
140155
while ( QPushButton *btn = mResolutionWidget->findChild<QPushButton *>() )
141156
delete btn;
142157
const QStringList resolutionMethods = error->check()->resolutionMethods();

src/app/qgsgeometryvalidationdock.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
4747
void gotoPreviousError();
4848
void zoomToProblem();
4949
void zoomToFeature();
50+
void triggerTopologyChecks();
5051
void updateLayerTransform();
5152

5253
private:

src/app/qgsgeometryvalidationmodel.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
5252
switch ( role )
5353
{
5454
case Qt::DisplayRole:
55+
FALLTHROUGH;
56+
case DetailsRole:
5557
{
5658
const QgsFeatureId fid = topologyError->featureId();
5759
const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached!
@@ -135,6 +137,40 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
135137
return QVariant();
136138
}
137139

140+
case GeometryCheckErrorRole:
141+
{
142+
// Not (yet?) used
143+
break;
144+
}
145+
146+
case FeatureExtentRole:
147+
{
148+
return mCurrentLayer->getFeature( featureItem.fid ).geometry().boundingBox();
149+
}
150+
151+
case ErrorLocationGeometryRole:
152+
{
153+
QgsSingleGeometryCheckError *error = featureItem.errors.first().get();
154+
return error->errorLocation();
155+
}
156+
157+
case ProblemExtentRole:
158+
{
159+
QgsSingleGeometryCheckError *error = featureItem.errors.first().get();
160+
return error->errorLocation().boundingBox();
161+
}
162+
163+
case DetailsRole:
164+
{
165+
QStringList details;
166+
for ( const std::shared_ptr<QgsSingleGeometryCheckError> &error : qgis::as_const( featureItem.errors ) )
167+
{
168+
details << error->description();
169+
}
170+
171+
return details.join( '\n' );
172+
}
173+
138174
default:
139175
return QVariant();
140176
}

src/app/qgsgeometryvalidationmodel.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class QgsGeometryValidationModel : public QAbstractItemModel
2020
ErrorGeometryRole,
2121
FeatureGeometryRole,
2222
ErrorLocationGeometryRole,
23-
GeometryCheckErrorRole
23+
GeometryCheckErrorRole,
24+
DetailsRole
2425
};
2526

2627
QgsGeometryValidationModel( QgsGeometryValidationService *geometryValidationService, QObject *parent = nullptr );

src/app/qgsgeometryvalidationservice.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class QgsGeometryValidationService : public QObject
6767

6868
void fixError( const QgsGeometryCheckError *error, int method );
6969

70+
void triggerTopologyChecks( QgsVectorLayer *layer );
71+
7072
signals:
7173
void geometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
7274
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
@@ -89,8 +91,6 @@ class QgsGeometryValidationService : public QObject
8991

9092
void processFeature( QgsVectorLayer *layer, QgsFeatureId fid );
9193

92-
void triggerTopologyChecks( QgsVectorLayer *layer );
93-
9494
QgsProject *mProject = nullptr;
9595

9696
struct VectorCheckState

0 commit comments

Comments
 (0)