Skip to content

Commit

Permalink
Better UX in geometry validation panel
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent baf1e52 commit 32c71b8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
19 changes: 17 additions & 2 deletions src/app/qgsgeometryvalidationdock.cpp
Expand Up @@ -37,6 +37,7 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM
connect( mMapCanvas, &QgsMapCanvas::currentLayerChanged, this, &QgsGeometryValidationDock::updateLayerTransform );
connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsGeometryValidationDock::updateLayerTransform );
connect( mMapCanvas, &QgsMapCanvas::transformContextChanged, this, &QgsGeometryValidationDock::updateLayerTransform );
connect( mTopologyChecksPendingButton, &QToolButton::clicked, this, &QgsGeometryValidationDock::triggerTopologyChecks );

mFeatureRubberband = new QgsRubberBand( mMapCanvas );
mErrorRubberband = new QgsRubberBand( mMapCanvas );
Expand All @@ -54,6 +55,8 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM
mErrorLocationRubberband->setWidth( scaleFactor );
mErrorLocationRubberband->setIconSize( scaleFactor * 5 );
mErrorLocationRubberband->setColor( QColor( 50, 255, 50, 255 ) );

mProblemDetailWidget->setVisible( false );
}


Expand Down Expand Up @@ -104,6 +107,13 @@ void QgsGeometryValidationDock::zoomToFeature()
mMapCanvas->zoomToFeatureExtent( mapExtent );
}

void QgsGeometryValidationDock::triggerTopologyChecks()
{
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mMapCanvas->currentLayer() );
if ( layer )
mGeometryValidationService->triggerTopologyChecks( layer );
}

void QgsGeometryValidationDock::updateLayerTransform()
{
if ( !mMapCanvas->currentLayer() )
Expand All @@ -130,13 +140,18 @@ QModelIndex QgsGeometryValidationDock::currentIndex() const
void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex &current, const QModelIndex &previous )
{
Q_UNUSED( previous )

mProblemDetailWidget->setVisible( current.isValid() );

mNextButton->setEnabled( current.isValid() && current.row() < mGeometryValidationModel->rowCount() - 1 );
mPreviousButton->setEnabled( current.isValid() && current.row() > 0 );

mProblemDetailWidget->setVisible( current.isValid() );
mProblemDescriptionLabel->setText( current.data().toString() );
mProblemDescriptionLabel->setText( current.data( QgsGeometryValidationModel::DetailsRole ).toString() );

QgsGeometryCheckError *error = current.data( QgsGeometryValidationModel::GeometryCheckErrorRole ).value<QgsGeometryCheckError *>();
if ( error )
{
QgsGeometryCheckError *error = current.data( QgsGeometryValidationModel::GeometryCheckErrorRole ).value<QgsGeometryCheckError *>();
while ( QPushButton *btn = mResolutionWidget->findChild<QPushButton *>() )
delete btn;
const QStringList resolutionMethods = error->check()->resolutionMethods();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsgeometryvalidationdock.h
Expand Up @@ -47,6 +47,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
void gotoPreviousError();
void zoomToProblem();
void zoomToFeature();
void triggerTopologyChecks();
void updateLayerTransform();

private:
Expand Down
36 changes: 36 additions & 0 deletions src/app/qgsgeometryvalidationmodel.cpp
Expand Up @@ -52,6 +52,8 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
switch ( role )
{
case Qt::DisplayRole:
FALLTHROUGH;
case DetailsRole:
{
const QgsFeatureId fid = topologyError->featureId();
const QgsFeature feature = mCurrentLayer->getFeature( fid ); // TODO: this should be cached!
Expand Down Expand Up @@ -135,6 +137,40 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
return QVariant();
}

case GeometryCheckErrorRole:
{
// Not (yet?) used
break;
}

case FeatureExtentRole:
{
return mCurrentLayer->getFeature( featureItem.fid ).geometry().boundingBox();
}

case ErrorLocationGeometryRole:
{
QgsSingleGeometryCheckError *error = featureItem.errors.first().get();
return error->errorLocation();
}

case ProblemExtentRole:
{
QgsSingleGeometryCheckError *error = featureItem.errors.first().get();
return error->errorLocation().boundingBox();
}

case DetailsRole:
{
QStringList details;
for ( const std::shared_ptr<QgsSingleGeometryCheckError> &error : qgis::as_const( featureItem.errors ) )
{
details << error->description();
}

return details.join( '\n' );
}

default:
return QVariant();
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsgeometryvalidationmodel.h
Expand Up @@ -20,7 +20,8 @@ class QgsGeometryValidationModel : public QAbstractItemModel
ErrorGeometryRole,
FeatureGeometryRole,
ErrorLocationGeometryRole,
GeometryCheckErrorRole
GeometryCheckErrorRole,
DetailsRole
};

QgsGeometryValidationModel( QgsGeometryValidationService *geometryValidationService, QObject *parent = nullptr );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsgeometryvalidationservice.h
Expand Up @@ -67,6 +67,8 @@ class QgsGeometryValidationService : public QObject

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

void triggerTopologyChecks( QgsVectorLayer *layer );

signals:
void geometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
Expand All @@ -89,8 +91,6 @@ class QgsGeometryValidationService : public QObject

void processFeature( QgsVectorLayer *layer, QgsFeatureId fid );

void triggerTopologyChecks( QgsVectorLayer *layer );

QgsProject *mProject = nullptr;

struct VectorCheckState
Expand Down

0 comments on commit 32c71b8

Please sign in to comment.