Skip to content
Permalink
Browse files

Better UX in geometry validation panel

  • Loading branch information
m-kuhn committed Oct 1, 2018
1 parent baf1e52 commit 32c71b8a53556e5eee52de9c9f132653e76f9157
@@ -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 );
@@ -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 );
}


@@ -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() )
@@ -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();
@@ -47,6 +47,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
void gotoPreviousError();
void zoomToProblem();
void zoomToFeature();
void triggerTopologyChecks();
void updateLayerTransform();

private:
@@ -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!
@@ -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();
}
@@ -20,7 +20,8 @@ class QgsGeometryValidationModel : public QAbstractItemModel
ErrorGeometryRole,
FeatureGeometryRole,
ErrorLocationGeometryRole,
GeometryCheckErrorRole
GeometryCheckErrorRole,
DetailsRole
};

QgsGeometryValidationModel( QgsGeometryValidationService *geometryValidationService, QObject *parent = nullptr );
@@ -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 );
@@ -89,8 +91,6 @@ class QgsGeometryValidationService : public QObject

void processFeature( QgsVectorLayer *layer, QgsFeatureId fid );

void triggerTopologyChecks( QgsVectorLayer *layer );

QgsProject *mProject = nullptr;

struct VectorCheckState

0 comments on commit 32c71b8

Please sign in to comment.
You can’t perform that action at this time.