Skip to content

Commit

Permalink
Allow deactivating is valid checks in an edit session
Browse files Browse the repository at this point in the history
If an is valid check is deactivated in an ongoing edit session, all check results
are invalidated and removed. This will help a user to save his edits if he wants
to even if is valid checks have been activated before.
  • Loading branch information
m-kuhn committed Mar 18, 2019
1 parent de6a27d commit 146dca4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/qgsgeometryvalidationmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ QgsGeometryValidationModel::QgsGeometryValidationModel( QgsGeometryValidationSer
: QAbstractItemModel( parent )
, mGeometryValidationService( geometryValidationService )
{
connect( mGeometryValidationService, &QgsGeometryValidationService::singleGeometryCheckCleared, this, &QgsGeometryValidationModel::onSingleGeometryCheckCleared );
connect( mGeometryValidationService, &QgsGeometryValidationService::geometryCheckCompleted, this, &QgsGeometryValidationModel::onGeometryCheckCompleted );
connect( mGeometryValidationService, &QgsGeometryValidationService::geometryCheckStarted, this, &QgsGeometryValidationModel::onGeometryCheckStarted );
connect( mGeometryValidationService, &QgsGeometryValidationService::topologyChecksUpdated, this, &QgsGeometryValidationModel::onTopologyChecksUpdated );
Expand Down Expand Up @@ -248,6 +249,24 @@ void QgsGeometryValidationModel::setCurrentLayer( QgsVectorLayer *currentLayer )
endResetModel();
}

void QgsGeometryValidationModel::onSingleGeometryCheckCleared( QgsVectorLayer *layer )
{
auto &layerErrors = mErrorStorage[layer];

if ( mCurrentLayer == layer && !layerErrors.empty() )
{
beginRemoveRows( QModelIndex(), 0, layerErrors.size() - 1 );
}

layerErrors.clear();

if ( mCurrentLayer == layer && !layerErrors.empty() )
{
endRemoveRows();
}

}

void QgsGeometryValidationModel::onGeometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors )
{
auto &layerErrors = mErrorStorage[layer];
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsgeometryvalidationmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class QgsGeometryValidationModel : public QAbstractItemModel
void setCurrentLayer( QgsVectorLayer *currentLayer );

private slots:
void onSingleGeometryCheckCleared( QgsVectorLayer *layer );
void onGeometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError> > &errors );
void onGeometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
void onTopologyChecksUpdated( QgsVectorLayer *layer, const QList<std::shared_ptr<QgsGeometryCheckError> > &errors );
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsgeometryvalidationservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
singleGeometryChecks.append( dynamic_cast<QgsSingleGeometryCheck *>( check ) );
}

if ( singleGeometryChecks.empty() )
{
mLayerChecks[layer].singleFeatureCheckErrors.clear();
emit singleGeometryCheckCleared( layer );
}

checkInformation.singleFeatureChecks = singleGeometryChecks;

// Topology checks
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsgeometryvalidationservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class QgsGeometryValidationService : public QObject
void setMessageBar( QgsMessageBar *messageBar );

signals:

/**
* Emitted when geometry checks for this layer have been disabled and
* any existing cached result should be cleared.
*/
void singleGeometryCheckCleared( QgsVectorLayer *layer );

void geometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
void topologyChecksUpdated( QgsVectorLayer *layer, const QList<std::shared_ptr<QgsGeometryCheckError> > &errors );
Expand Down

0 comments on commit 146dca4

Please sign in to comment.