Skip to content

Commit

Permalink
Better feedback for the user
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent c0088f7 commit f64b1f1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -927,10 +927,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
startProfile( QStringLiteral( "Geometry validation" ) );

mGeometryValidationService = qgis::make_unique<QgsGeometryValidationService>( QgsProject::instance() );
connect( mGeometryValidationService.get(), &QgsGeometryValidationService::warning, this, [this]( const QString & message )
{
mInfoBar->pushWarning( tr( "Geometry Validation" ), message );
} );
mGeometryValidationService->setMessageBar( mInfoBar );
mGeometryValidationDock = new QgsGeometryValidationDock( tr( "Geometry Validation" ), mMapCanvas, this );
mGeometryValidationModel = new QgsGeometryValidationModel( mGeometryValidationService.get(), mGeometryValidationDock );
connect( this, &QgisApp::activeLayerChanged, mGeometryValidationModel, [this]( QgsMapLayer * layer )
Expand Down
31 changes: 29 additions & 2 deletions src/app/qgsgeometryvalidationservice.cpp
Expand Up @@ -25,6 +25,8 @@ email : matthias@opengis.ch
#include "qgsvectorlayerfeaturepool.h"
#include "qgsfeedback.h"
#include "qgsreadwritelocker.h"
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"

#include <QtConcurrent>
#include <QFutureWatcher>
Expand Down Expand Up @@ -139,7 +141,7 @@ void QgsGeometryValidationService::onBeforeCommitChanges( QgsVectorLayer *layer
{
if ( !layer->allowCommit() )
{
emit warning( tr( "Can not save yet, we'll need to run some topology checks on your dataset first..." ) );
showMessage( tr( "Running geometry validation checks before saving ..." ) );
}

mLayerChecks[layer].commitPending = true;
Expand All @@ -154,6 +156,14 @@ void QgsGeometryValidationService::onEditingStopped( QgsVectorLayer *layer )
clearTopologyChecks( layer );
}

void QgsGeometryValidationService::showMessage( const QString &message )
{
mMessageBar->popWidget( mMessageBarItem );
mMessageBarItem = QgsMessageBar::createMessage( tr( "Geometry Validation" ), message );
mMessageBarItem->setDuration( 5 );
mMessageBar->pushItem( mMessageBarItem );
}

void QgsGeometryValidationService::cleanupLayerChecks( QgsVectorLayer *layer )
{
if ( !mLayerChecks.contains( layer ) )
Expand Down Expand Up @@ -335,6 +345,11 @@ void QgsGeometryValidationService::processFeature( QgsVectorLayer *layer, QgsFea
emit geometryCheckCompleted( layer, fid, allErrors );
}

void QgsGeometryValidationService::setMessageBar( QgsMessageBar *messageBar )
{
mMessageBar = messageBar;
}

void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer )
{
cancelTopologyCheck( layer );
Expand Down Expand Up @@ -418,8 +433,20 @@ void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer
if ( mLayerChecks[layer].topologyCheckFutureWatcher == futureWatcher )
mLayerChecks[layer].topologyCheckFutureWatcher = nullptr;

if ( allErrors.empty() && !mLayerChecks[layer].singleFeatureCheckErrors.empty() && mLayerChecks[layer].commitPending )
if ( !allErrors.empty() || !mLayerChecks[layer].singleFeatureCheckErrors.empty() )
{
if ( mLayerChecks[layer].commitPending )
showMessage( tr( "Geometry errors have been found. Please fix the errors before saving the layer." ) );
else
showMessage( tr( "Geometry errors have been found." ) );
}
if ( allErrors.empty() && mLayerChecks[layer].singleFeatureCheckErrors.empty() && mLayerChecks[layer].commitPending )
{
layer->commitChanges();
mMessageBar->popWidget( mMessageBarItem );
mMessageBarItem = nullptr;
}

mLayerChecks[layer].commitPending = false;
} );

Expand Down
13 changes: 13 additions & 0 deletions src/app/qgsgeometryvalidationservice.h
Expand Up @@ -33,10 +33,16 @@ class QgsSingleGeometryCheckError;
class QgsGeometryCheckError;
class QgsFeedback;
class QgsFeaturePool;
class QgsMessageBar;
class QgsMessageBarItem;

/**
* This service connects to all layers in a project and triggers validation
* of features whenever they are edited.
* It is responsible for executing validation checks and sending out signals
* upon failure and success.
* It will also make sure, that a layer can only be saved, if all errors have
* been resolved.
*/
class QgsGeometryValidationService : public QObject
{
Expand Down Expand Up @@ -64,6 +70,8 @@ class QgsGeometryValidationService : public QObject

void triggerTopologyChecks( QgsVectorLayer *layer );

void setMessageBar( QgsMessageBar *messageBar );

signals:
void geometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
Expand All @@ -72,6 +80,7 @@ class QgsGeometryValidationService : public QObject
void topologyErrorUpdated( QgsVectorLayer *layer, QgsGeometryCheckError *error );

void warning( const QString &message );
void clearWarning();

private slots:
void onLayersAdded( const QList<QgsMapLayer *> &layers );
Expand All @@ -82,6 +91,7 @@ class QgsGeometryValidationService : public QObject
void onEditingStopped( QgsVectorLayer *layer );

private:
void showMessage( const QString &message );
void cleanupLayerChecks( QgsVectorLayer *layer );
void enableLayerChecks( QgsVectorLayer *layer );

Expand Down Expand Up @@ -111,6 +121,9 @@ class QgsGeometryValidationService : public QObject
QReadWriteLock mTopologyCheckLock;
QHash<QgsVectorLayer *, VectorLayerCheckInformation> mLayerChecks;
QMap<QString, QgsFeaturePool *> mFeaturePools;
QgsMessageBar *mMessageBar = nullptr;
QgsMessageBarItem *mMessageBarItem = nullptr;

};

#endif // QGSGEOMETRYVALIDATIONSERVICE_H

0 comments on commit f64b1f1

Please sign in to comment.