Skip to content

Commit

Permalink
Merge pull request #9223 from m-kuhn/geometry_validator_summary_cleanup
Browse files Browse the repository at this point in the history
Geometry validator summary cleanup
  • Loading branch information
m-kuhn committed Feb 21, 2019
2 parents 9280a07 + 9c06061 commit 4d5dad8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
22 changes: 20 additions & 2 deletions python/core/auto_generated/qgsgeometryvalidator.sip.in
Expand Up @@ -28,11 +28,29 @@ Constructor for QgsGeometryValidator.

static void validateGeometry( const QgsGeometry &geometry, QVector<QgsGeometry::Error> &errors /Out/, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
%Docstring
Validate geometry and produce a list of geometry errors
Validate geometry and produce a list of geometry errors.
This method blocks the thread until the validation is finished.
%End

signals:
void errorFound( const QgsGeometry::Error & );

void errorFound( const QgsGeometry::Error &error );
%Docstring
Sent when an error has been found during the validation process.

The ``error`` contains details about the error.
%End

void validationFinished( const QString &summary );
%Docstring
Sent when the validation is finished.

The result is in a human readable ``summary``, mentioning
if the validation has been aborted, successfully been validated
or how many errors have been found.

.. versionadded:: 3.6
%End

public slots:
void addError( const QgsGeometry::Error & );
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/tests/CheckValidityAlgorithm.py
Expand Up @@ -116,7 +116,7 @@ def test_check_validity(self):
self.assertEqual(invalid_layer.featureCount(), 1)
f = next(invalid_layer.getFeatures())
self.assertEqual(f.attributes(), [
1, 'segments 0 and 2 of line 0 intersect at 1, 1\nGeometry has 1 errors.'])
1, 'segments 0 and 2 of line 0 intersect at 1, 1'])

# GEOS method
parameters['METHOD'] = 2
Expand Down
8 changes: 3 additions & 5 deletions src/core/qgsgeometryvalidator.cpp
Expand Up @@ -349,18 +349,16 @@ void QgsGeometryValidator::run()

if ( mStop )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "Geometry validation was aborted." ) ) );
emit validationFinished( QObject::tr( "Geometry validation was aborted." ) );
}
else if ( mErrorCount > 0 )
{
emit errorFound( QgsGeometry::Error( QObject::tr( "Geometry has %1 errors." ).arg( mErrorCount ) ) );
emit validationFinished( QObject::tr( "Geometry has %1 errors." ).arg( mErrorCount ) );
}
#if 0
else
{
emit errorFound( QgsGeometry::Error( QObject::tr( "Geometry is valid." ) ) );
emit validationFinished( QObject::tr( "Geometry is valid." ) );
}
#endif
break;
}
}
Expand Down
24 changes: 22 additions & 2 deletions src/core/qgsgeometryvalidator.h
Expand Up @@ -40,11 +40,31 @@ class CORE_EXPORT QgsGeometryValidator : public QThread
void run() override;
void stop();

//! Validate geometry and produce a list of geometry errors
/**
* Validate geometry and produce a list of geometry errors.
* This method blocks the thread until the validation is finished.
*/
static void validateGeometry( const QgsGeometry &geometry, QVector<QgsGeometry::Error> &errors SIP_OUT, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );

signals:
void errorFound( const QgsGeometry::Error & );

/**
* Sent when an error has been found during the validation process.
*
* The \a error contains details about the error.
*/
void errorFound( const QgsGeometry::Error &error );

/**
* Sent when the validation is finished.
*
* The result is in a human readable \a summary, mentioning
* if the validation has been aborted, successfully been validated
* or how many errors have been found.
*
* \since QGIS 3.6
*/
void validationFinished( const QString &summary );

public slots:
void addError( const QgsGeometry::Error & );
Expand Down

0 comments on commit 4d5dad8

Please sign in to comment.