More geometry fix goodness

This commit is contained in:
Matthias Kuhn 2020-01-05 23:00:52 +01:00
parent 0bc8726f4f
commit 6cdd75bbab
6 changed files with 64 additions and 11 deletions

View File

@ -9,6 +9,11 @@
class QgsGeometryCheckFix
{
%Docstring
This class implements a fix for problems detected in geometry checks.
.. versionadded:: 3.12
%End
%TypeHeaderCode
#include "qgsgeometrycheckfix.h"
@ -19,10 +24,19 @@ class QgsGeometryCheckFix
int id() const;
bool isStable() const;
%Docstring
If this fix is stable enough to be listed by default.
%End
QString name() const;
%Docstring
A human readable and translated name for this fix.
%End
QString description() const;
%Docstring
A human readable and translated description for this fix.
%End
};

View File

@ -98,8 +98,12 @@ QgsRectangle QgsGeometryCheckError::affectedAreaBBox() const
void QgsGeometryCheckError::setFixed( int method )
{
mStatus = StatusFixed;
const QStringList methods = mCheck->resolutionMethods();
mResolutionMessage = methods[method];
const QList<QgsGeometryCheckFix> methods = mCheck->availableResolutionMethods();
for ( const QgsGeometryCheckFix &fix : methods )
{
if ( fix.id() == method )
mResolutionMessage = fix.name();
}
}
void QgsGeometryCheckError::setFixFailed( const QString &reason )

View File

@ -5,6 +5,11 @@
#include <QString>
#include "qgis_analysis.h"
/**
* This class implements a fix for problems detected in geometry checks.
*
* \since QGIS 3.12
*/
class ANALYSIS_EXPORT QgsGeometryCheckFix
{
public:
@ -12,10 +17,19 @@ class ANALYSIS_EXPORT QgsGeometryCheckFix
int id() const;
/**
* If this fix is stable enough to be listed by default.
*/
bool isStable() const;
/**
* A human readable and translated name for this fix.
*/
QString name() const;
/**
* A human readable and translated description for this fix.
*/
QString description() const;
private:

View File

@ -252,8 +252,9 @@ void QgsGeometryGapCheck::fixError( const QMap<QString, QgsFeaturePool *> &featu
case CreateNewFeature:
{
QgsGeometryGapCheckError *gapCheckError = dynamic_cast<QgsGeometryGapCheckError *>( error );
QgsProject *project = QgsProject::instance();
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( project->mapLayer( error->layerId() ) );
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( project->mapLayer( gapCheckError->neighbors().keys().first() ) );
if ( layer )
{
const QgsGeometry geometry = error->geometry();
@ -377,15 +378,30 @@ QStringList QgsGeometryGapCheck::resolutionMethods() const
{
QStringList methods = QStringList()
<< tr( "Add gap area to neighboring polygon with longest shared edge" )
<< tr( "No action" )
<< tr( "TODO" )
<< tr( "TODO" );
<< tr( "No action" );
if ( mAllowedGapsSource )
methods << tr( "Add gap to allowed exceptions" );
return methods;
}
QList<QgsGeometryCheckFix> QgsGeometryGapCheck::availableResolutionMethods() const
{
QList<QgsGeometryCheckFix> fixes
{
QgsGeometryCheckFix( MergeLongestEdge, tr( "Add to longest shared edge" ), tr( "Add the gap area to the neighbouring polygon with the longest shared edge." ), false ),
QgsGeometryCheckFix( CreateNewFeature, tr( "Create new feature" ), tr( "Create a new feature from the gap area." ), false ),
QgsGeometryCheckFix( MergeLargestArea, tr( "Add to largest neighbouring area" ), tr( "Add the gap area to the neighbouring polygon with the largest area." ), false )
};
if ( mAllowedGapsSource )
fixes << QgsGeometryCheckFix( AddToAllowedGaps, tr( "Add gap to allowed exceptions" ), tr( "Create a new feature from the gap geometry on the allowed exceptions layer." ), false );
fixes << QgsGeometryCheckFix( NoChange, tr( "No action" ), tr( "Do not perform any action and mark this error as fixed." ), false );
return fixes;
}
QString QgsGeometryGapCheck::description() const
{
return factoryDescription();

View File

@ -116,6 +116,8 @@ class ANALYSIS_EXPORT QgsGeometryGapCheck : public QgsGeometryCheck
void fixError( const QMap<QString, QgsFeaturePool *> &featurePools, QgsGeometryCheckError *error, int method, const QMap<QString, int> &mergeAttributeIndices, Changes &changes ) const override;
QStringList resolutionMethods() const override;
QList<QgsGeometryCheckFix> availableResolutionMethods() const override;
QString description() const override;
QString id() const override;
QgsGeometryCheck::Flags flags() const override;

View File

@ -218,20 +218,23 @@ void QgsGeometryValidationDock::onCurrentErrorChanged( const QModelIndex &curren
if ( error->status() != QgsGeometryCheckError::StatusFixed )
{
const QStringList resolutionMethods = error->check()->resolutionMethods();
const QList<QgsGeometryCheckFix> resolutionMethods = error->check()->availableResolutionMethods();
QGridLayout *layout = new QGridLayout( mResolutionWidget );
int resolutionIndex = 0;
for ( const QString &resolutionMethod : resolutionMethods )
for ( const QgsGeometryCheckFix &resolutionMethod : resolutionMethods )
{
QToolButton *resolveBtn = new QToolButton( mResolutionWidget );
resolveBtn->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmCheckGeometry.svg" ) ) );
resolveBtn->setToolTip( resolutionMethod.description() );
layout->addWidget( resolveBtn, resolutionIndex, 0 );
QLabel *resolveLabel = new QLabel( resolutionMethod, mResolutionWidget );
QLabel *resolveLabel = new QLabel( resolutionMethod.name(), mResolutionWidget );
resolveLabel->setToolTip( resolutionMethod.description() );
resolveLabel->setWordWrap( true );
layout->addWidget( resolveLabel, resolutionIndex, 1 );
connect( resolveBtn, &QToolButton::clicked, this, [resolutionIndex, error, this]()
int fixId = resolutionMethod.id();
connect( resolveBtn, &QToolButton::clicked, this, [fixId, error, this]()
{
mGeometryValidationService->fixError( error, resolutionIndex );
mGeometryValidationService->fixError( error, fixId );
} );
resolutionIndex++;
}