Skip to content

Commit

Permalink
More geometry fix goodness
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jan 14, 2020
1 parent 0bc8726 commit 6cdd75b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
Expand Up @@ -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"
Expand All @@ -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

};

Expand Down
Expand Up @@ -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 )
Expand Down
14 changes: 14 additions & 0 deletions src/analysis/vector/geometry_checker/qgsgeometrycheckfix.h
Expand Up @@ -5,17 +5,31 @@
#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:
QgsGeometryCheckFix( int id, const QString &name, const QString &description, bool isStable = true );

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:
Expand Down
24 changes: 20 additions & 4 deletions src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/vector/geometry_checker/qgsgeometrygapcheck.h
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions src/app/qgsgeometryvalidationdock.cpp
Expand Up @@ -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++;
}
Expand Down

0 comments on commit 6cdd75b

Please sign in to comment.