Skip to content

Commit f64b1f1

Browse files
committed
Better feedback for the user
1 parent c0088f7 commit f64b1f1

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

src/app/qgisapp.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
927927
startProfile( QStringLiteral( "Geometry validation" ) );
928928

929929
mGeometryValidationService = qgis::make_unique<QgsGeometryValidationService>( QgsProject::instance() );
930-
connect( mGeometryValidationService.get(), &QgsGeometryValidationService::warning, this, [this]( const QString & message )
931-
{
932-
mInfoBar->pushWarning( tr( "Geometry Validation" ), message );
933-
} );
930+
mGeometryValidationService->setMessageBar( mInfoBar );
934931
mGeometryValidationDock = new QgsGeometryValidationDock( tr( "Geometry Validation" ), mMapCanvas, this );
935932
mGeometryValidationModel = new QgsGeometryValidationModel( mGeometryValidationService.get(), mGeometryValidationDock );
936933
connect( this, &QgisApp::activeLayerChanged, mGeometryValidationModel, [this]( QgsMapLayer * layer )

src/app/qgsgeometryvalidationservice.cpp

+29-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ email : matthias@opengis.ch
2525
#include "qgsvectorlayerfeaturepool.h"
2626
#include "qgsfeedback.h"
2727
#include "qgsreadwritelocker.h"
28+
#include "qgsmessagebar.h"
29+
#include "qgsmessagebaritem.h"
2830

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

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

159+
void QgsGeometryValidationService::showMessage( const QString &message )
160+
{
161+
mMessageBar->popWidget( mMessageBarItem );
162+
mMessageBarItem = QgsMessageBar::createMessage( tr( "Geometry Validation" ), message );
163+
mMessageBarItem->setDuration( 5 );
164+
mMessageBar->pushItem( mMessageBarItem );
165+
}
166+
157167
void QgsGeometryValidationService::cleanupLayerChecks( QgsVectorLayer *layer )
158168
{
159169
if ( !mLayerChecks.contains( layer ) )
@@ -335,6 +345,11 @@ void QgsGeometryValidationService::processFeature( QgsVectorLayer *layer, QgsFea
335345
emit geometryCheckCompleted( layer, fid, allErrors );
336346
}
337347

348+
void QgsGeometryValidationService::setMessageBar( QgsMessageBar *messageBar )
349+
{
350+
mMessageBar = messageBar;
351+
}
352+
338353
void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer )
339354
{
340355
cancelTopologyCheck( layer );
@@ -418,8 +433,20 @@ void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer
418433
if ( mLayerChecks[layer].topologyCheckFutureWatcher == futureWatcher )
419434
mLayerChecks[layer].topologyCheckFutureWatcher = nullptr;
420435

421-
if ( allErrors.empty() && !mLayerChecks[layer].singleFeatureCheckErrors.empty() && mLayerChecks[layer].commitPending )
436+
if ( !allErrors.empty() || !mLayerChecks[layer].singleFeatureCheckErrors.empty() )
437+
{
438+
if ( mLayerChecks[layer].commitPending )
439+
showMessage( tr( "Geometry errors have been found. Please fix the errors before saving the layer." ) );
440+
else
441+
showMessage( tr( "Geometry errors have been found." ) );
442+
}
443+
if ( allErrors.empty() && mLayerChecks[layer].singleFeatureCheckErrors.empty() && mLayerChecks[layer].commitPending )
444+
{
422445
layer->commitChanges();
446+
mMessageBar->popWidget( mMessageBarItem );
447+
mMessageBarItem = nullptr;
448+
}
449+
423450
mLayerChecks[layer].commitPending = false;
424451
} );
425452

src/app/qgsgeometryvalidationservice.h

+13
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ class QgsSingleGeometryCheckError;
3333
class QgsGeometryCheckError;
3434
class QgsFeedback;
3535
class QgsFeaturePool;
36+
class QgsMessageBar;
37+
class QgsMessageBarItem;
3638

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

6571
void triggerTopologyChecks( QgsVectorLayer *layer );
6672

73+
void setMessageBar( QgsMessageBar *messageBar );
74+
6775
signals:
6876
void geometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
6977
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
@@ -72,6 +80,7 @@ class QgsGeometryValidationService : public QObject
7280
void topologyErrorUpdated( QgsVectorLayer *layer, QgsGeometryCheckError *error );
7381

7482
void warning( const QString &message );
83+
void clearWarning();
7584

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

8493
private:
94+
void showMessage( const QString &message );
8595
void cleanupLayerChecks( QgsVectorLayer *layer );
8696
void enableLayerChecks( QgsVectorLayer *layer );
8797

@@ -111,6 +121,9 @@ class QgsGeometryValidationService : public QObject
111121
QReadWriteLock mTopologyCheckLock;
112122
QHash<QgsVectorLayer *, VectorLayerCheckInformation> mLayerChecks;
113123
QMap<QString, QgsFeaturePool *> mFeaturePools;
124+
QgsMessageBar *mMessageBar = nullptr;
125+
QgsMessageBarItem *mMessageBarItem = nullptr;
126+
114127
};
115128

116129
#endif // QGSGEOMETRYVALIDATIONSERVICE_H

0 commit comments

Comments
 (0)