Skip to content
Permalink
Browse files

[geometry validation] Show context menu for stable problem resolution…

… methods

And flag "add to allowed gaps" as stable
  • Loading branch information
m-kuhn committed Nov 12, 2020
1 parent 6e933e8 commit e4b209d1565f849982cde8772df38a833c91b639
@@ -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 );

@@ -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 );
@@ -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;

@@ -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
@@ -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;
@@ -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:

@@ -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.
You can’t perform that action at this time.