Skip to content
Permalink
Browse files

Better feedback for the user

  • Loading branch information
m-kuhn committed Oct 3, 2018
1 parent c0088f7 commit f64b1f1174f01682d34bae3d450390b9ffae52ec
Showing with 43 additions and 6 deletions.
  1. +1 −4 src/app/qgisapp.cpp
  2. +29 −2 src/app/qgsgeometryvalidationservice.cpp
  3. +13 −0 src/app/qgsgeometryvalidationservice.h
@@ -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 )
@@ -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>
@@ -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;
@@ -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 ) )
@@ -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 );
@@ -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;
} );

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

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