Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Put topology check cancelation into its own routine
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent fe5a80c commit 273d3c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/app/qgsgeometryvalidationservice.cpp
Expand Up @@ -174,6 +174,27 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
mLayerCheckStates[layer].topologyChecks = topologyChecks;
}

void QgsGeometryValidationService::cancelTopologyCheck( QgsVectorLayer *layer )
{
QFutureWatcher<void> *futureWatcher = mLayerCheckStates[layer].topologyCheckFutureWatcher;
if ( futureWatcher )
{
// Make sure no more checks are started first
futureWatcher->cancel();

// Tell all checks to stop asap
const auto feedbacks = mLayerCheckStates[layer].topologyCheckFeedbacks;
for ( QgsFeedback *feedback : feedbacks )
{
if ( feedback )
feedback->cancel();
}

futureWatcher->waitForFinished();
mLayerCheckStates[layer].topologyCheckFutureWatcher = nullptr;
}
}

void QgsGeometryValidationService::cancelChecks( QgsVectorLayer *layer, QgsFeatureId fid )
{

Expand Down Expand Up @@ -204,24 +225,7 @@ void QgsGeometryValidationService::processFeature( QgsVectorLayer *layer, QgsFea
void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer )
{
emit topologyChecksCleared( layer );

QFutureWatcher<void> *futureWatcher = mLayerCheckStates[layer].topologyCheckFutureWatcher;
if ( futureWatcher )
{
// Make sure no more checks are started first
futureWatcher->cancel();

// Tell all checks to stop asap
const auto feedbacks = mLayerCheckStates[layer].topologyCheckFeedbacks;
for ( QgsFeedback *feedback : feedbacks )
{
if ( feedback )
feedback->cancel();
}

// The future watcher will take care of deleting
mLayerCheckStates[layer].topologyCheckFeedbacks.clear();
}
cancelTopologyCheck( layer );

QgsFeatureIds affectedFeatureIds = layer->editBuffer()->changedGeometries().keys().toSet();
affectedFeatureIds.unite( layer->editBuffer()->addedFeatures().keys().toSet() );
Expand Down Expand Up @@ -282,7 +286,7 @@ void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer
errorLocker.unlock();
} );

futureWatcher = new QFutureWatcher<void>();
QFutureWatcher<void> *futureWatcher = new QFutureWatcher<void>();
futureWatcher->setFuture( future );

connect( futureWatcher, &QFutureWatcherBase::finished, this, [&allErrors, layer, feedbacks, futureWatcher, this]()
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsgeometryvalidationservice.h
Expand Up @@ -87,6 +87,8 @@ class QgsGeometryValidationService : public QObject
private:
void enableLayerChecks( QgsVectorLayer *layer );

void cancelTopologyCheck( QgsVectorLayer *layer );

void cancelChecks( QgsVectorLayer *layer, QgsFeatureId fid );

void processFeature( QgsVectorLayer *layer, QgsFeatureId fid );
Expand Down

0 comments on commit 273d3c8

Please sign in to comment.