Skip to content

Commit

Permalink
[geometry validation] Show context menu for stable problem resolution…
Browse files Browse the repository at this point in the history
… methods

And flag "add to allowed gaps" as stable
  • Loading branch information
m-kuhn committed Nov 12, 2020
1 parent 6e933e8 commit e4b209d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Expand Up @@ -444,7 +444,7 @@ QList<QgsGeometryCheckResolutionMethod> QgsGeometryGapCheck::availableResolution
};

if ( mAllowedGapsSource )
fixes << QgsGeometryCheckResolutionMethod( AddToAllowedGaps, tr( "Add gap to allowed exceptions" ), tr( "Create a new feature from the gap geometry on the allowed exceptions layer." ), false );
fixes << QgsGeometryCheckResolutionMethod( AddToAllowedGaps, tr( "Add Gap to Allowed Exceptions" ), tr( "Create a new feature from the gap geometry on the allowed exceptions layer." ), true );

fixes << QgsGeometryCheckResolutionMethod( NoChange, tr( "No action" ), tr( "Do not perform any action and mark this error as fixed." ), false );

Expand Down
37 changes: 35 additions & 2 deletions src/app/qgsgeometryvalidationdock.cpp
Expand Up @@ -41,6 +41,8 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM

mProblemDescriptionLabel->setStyleSheet( QStringLiteral( "font: bold" ) );
mErrorListView->setAlternatingRowColors( true );
mErrorListView->setContextMenuPolicy( Qt::CustomContextMenu );
connect( mErrorListView, &QWidget::customContextMenuRequested, this, &QgsGeometryValidationDock::showErrorContextMenu );

connect( mNextButton, &QToolButton::clicked, this, &QgsGeometryValidationDock::gotoNextError );
connect( mPreviousButton, &QToolButton::clicked, this, &QgsGeometryValidationDock::gotoPreviousError );
Expand All @@ -54,6 +56,7 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM
mFeatureRubberband = new QgsRubberBand( mMapCanvas );
mErrorRubberband = new QgsRubberBand( mMapCanvas );
mErrorLocationRubberband = new QgsRubberBand( mMapCanvas );
mGeometryErrorContextMenu = new QMenu( this );

double scaleFactor = mMapCanvas->fontMetrics().xHeight() * .4;

Expand All @@ -70,8 +73,9 @@ QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QgsM

mProblemDetailWidget->setVisible( false );

// Problem resolution is unstable and therefore disabled by default
mResolutionWidget->setVisible( QgsSettings().value( QStringLiteral( "geometry_validation/enable_problem_resolution" ) ) == QLatin1String( "true" ) );
// Some problem resolutions are unstable, show all of them only if the user opted in
bool showUnreliableResolutionMethods = QgsSettings().value( QStringLiteral( "geometry_validation/enable_problem_resolution" ) ).toString().compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;
mResolutionWidget->setVisible( showUnreliableResolutionMethods );
}

QgsGeometryValidationModel *QgsGeometryValidationDock::geometryValidationModel() const
Expand Down Expand Up @@ -159,6 +163,35 @@ void QgsGeometryValidationDock::onRowsInserted()
setUserVisible( true );
}

void QgsGeometryValidationDock::showErrorContextMenu( const QPoint &pos )
{
bool showUnreliableResolutionMethods = QgsSettings().value( QStringLiteral( "geometry_validation/enable_problem_resolution" ) ).toString().compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0;

QModelIndex index = mErrorListView->indexAt( pos );
QgsGeometryCheckError *error = index.data( QgsGeometryValidationModel::GeometryCheckErrorRole ).value<QgsGeometryCheckError *>();
if ( error )
{
const QList<QgsGeometryCheckResolutionMethod> resolutionMethods = error->check()->availableResolutionMethods();

mGeometryErrorContextMenu->clear();
for ( const QgsGeometryCheckResolutionMethod &resolutionMethod : resolutionMethods )
{
if ( resolutionMethod.isStable() || showUnreliableResolutionMethods )
{
QAction *action = new QAction( resolutionMethod.name(), mGeometryErrorContextMenu );
action->setToolTip( resolutionMethod.description() );
int fixId = resolutionMethod.id();
connect( action, &QAction::triggered, this, [ fixId, error, this ]()
{
mGeometryValidationService->fixError( error, fixId );
} );
mGeometryErrorContextMenu->addAction( action );
}
}
mGeometryErrorContextMenu->popup( mErrorListView->viewport()->mapToGlobal( pos ) );
}
}

QgsGeometryValidationService *QgsGeometryValidationDock::geometryValidationService() const
{
return mGeometryValidationService;
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsgeometryvalidationdock.h
Expand Up @@ -57,6 +57,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
void updateLayerTransform();
void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles );
void onRowsInserted();
void showErrorContextMenu( const QPoint &pos );

private:

Expand All @@ -81,6 +82,7 @@ class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryVal
QgsRubberBand *mErrorLocationRubberband = nullptr;
QgsVectorLayer *mCurrentLayer = nullptr;
bool mPreventZoomToError = false;
QMenu *mGeometryErrorContextMenu = nullptr;
};

#endif // QGSGEOMETRYVALIDATIONPANEL_H

0 comments on commit e4b209d

Please sign in to comment.