Skip to content

Commit

Permalink
Autosave after successful check
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent 417fa06 commit d527fed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app/qgsgeometryvalidationservice.cpp
Expand Up @@ -139,6 +139,9 @@ void QgsGeometryValidationService::onBeforeCommitChanges( QgsVectorLayer *layer
{
emit warning( tr( "Can not save yet, we'll need to run some topology checks on your dataset first..." ) );
}

mLayerChecks[layer].commitPending = true;

triggerTopologyChecks( layer );
}
}
Expand Down Expand Up @@ -193,7 +196,7 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
precision = 8;
}

checkInformation.context = qgis::make_unique<QgsGeometryCheckContext>( precision, mProject->crs(), mProject->transformContext() );
checkInformation.context = qgis::make_unique<QgsGeometryCheckContext>( 10, mProject->crs(), mProject->transformContext() );

QList<QgsGeometryCheck *> layerChecks;

Expand Down Expand Up @@ -311,6 +314,7 @@ void QgsGeometryValidationService::processFeature( QgsVectorLayer *layer, QgsFea
QgsFeature feature = layer->getFeature( fid );

const auto &checks = mLayerChecks[layer].singleFeatureChecks;
mLayerChecks[layer].singleFeatureCheckErrors.remove( fid );

// The errors are going to be sent out via a signal. We cannot keep ownership in here (or can we?)
// nor can we be sure that a single slot is connected to the signal. So make it a shared_ptr.
Expand All @@ -323,6 +327,9 @@ void QgsGeometryValidationService::processFeature( QgsVectorLayer *layer, QgsFea
allErrors.append( std::shared_ptr<QgsSingleGeometryCheckError>( error ) );
}

if ( !allErrors.empty() )
mLayerChecks[layer].singleFeatureCheckErrors.insert( fid, allErrors );

emit geometryCheckCompleted( layer, fid, allErrors );
}

Expand Down Expand Up @@ -408,6 +415,10 @@ void QgsGeometryValidationService::triggerTopologyChecks( QgsVectorLayer *layer
futureWatcher->deleteLater();
if ( mLayerChecks[layer].topologyCheckFutureWatcher == futureWatcher )
mLayerChecks[layer].topologyCheckFutureWatcher = nullptr;

if ( allErrors.empty() && !mLayerChecks[layer].singleFeatureCheckErrors.empty() && mLayerChecks[layer].commitPending )
layer->commitChanges();
mLayerChecks[layer].commitPending = false;
} );

mLayerChecks[layer].topologyCheckFutureWatcher = futureWatcher;
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsgeometryvalidationservice.h
Expand Up @@ -98,12 +98,14 @@ class QgsGeometryValidationService : public QObject
struct VectorLayerCheckInformation
{
QList< QgsSingleGeometryCheck * > singleFeatureChecks;
QMap<QgsFeatureId, QList< std::shared_ptr<QgsSingleGeometryCheckError > > > singleFeatureCheckErrors;
QList< QgsGeometryCheck *> topologyChecks;
QFutureWatcher<void> *topologyCheckFutureWatcher = nullptr;
QList<QgsFeedback *> topologyCheckFeedbacks; // will be deleted when topologyCheckFutureWatcher is delteed
QList<std::shared_ptr<QgsGeometryCheckError>> topologyCheckErrors;
QList<QMetaObject::Connection> connections;
std::shared_ptr<QgsGeometryCheckContext> context;
bool commitPending = false;
};

QReadWriteLock mTopologyCheckLock;
Expand Down

0 comments on commit d527fed

Please sign in to comment.