Skip to content
Permalink
Browse files

Handle layer deleted

  • Loading branch information
m-kuhn committed Oct 2, 2018
1 parent d0d08cc commit 4d40d2fe80906b960f9a2729bc69d1110e09ebe3
Showing with 27 additions and 9 deletions.
  1. +23 −7 src/app/qgsgeometryvalidationservice.cpp
  2. +4 −2 src/app/qgsgeometryvalidationservice.h
@@ -81,6 +81,12 @@ void QgsGeometryValidationService::onLayersAdded( const QList<QgsMapLayer *> &la
enableLayerChecks( vectorLayer );
}, Qt::UniqueConnection );

connect( vectorLayer, &QgsVectorLayer::destroyed, this, [vectorLayer, this]()
{
cleanupLayerChecks( vectorLayer );
mLayerChecks.remove( vectorLayer );
});

enableLayerChecks( vectorLayer );
}
}
@@ -100,8 +106,8 @@ void QgsGeometryValidationService::onGeometryChanged( QgsVectorLayer *layer, Qgs
Q_UNUSED( geometry )
// It would be nice to use the geometry here for the tests.
// But:
// 1. other codepaths to the checks also have no geometry (feature added / feature deleted)
// 2. and looking it up from the edit buffer (in memory) is really fast.
// 1. other codepaths to the checks also have no geometry (feature added / feature deleted)
// 2. and looking it up from the edit buffer (in memory) is really fast.
// so in short: it's still a good idea, but not as important as on first thought.

if ( !mLayerChecks[layer].topologyChecks.empty() )
@@ -135,9 +141,9 @@ void QgsGeometryValidationService::onBeforeCommitChanges( QgsVectorLayer *layer
}
}

void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
void QgsGeometryValidationService::cleanupLayerChecks(QgsVectorLayer* layer)
{
if ( layer->geometryOptions()->geometryChecks().empty() && !mLayerChecks.contains( layer ) )
if ( !mLayerChecks.contains( layer ) )
return;

VectorLayerCheckInformation &checkInformation = mLayerChecks[layer];
@@ -146,7 +152,17 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )

qDeleteAll( checkInformation.singleFeatureChecks );
qDeleteAll( checkInformation.topologyChecks );
delete checkInformation.context;
checkInformation.context.reset();
}

void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
{
if ( layer->geometryOptions()->geometryChecks().empty() && !mLayerChecks.contains( layer ) )
return;

VectorLayerCheckInformation &checkInformation = mLayerChecks[layer];

cleanupLayerChecks( layer );

if ( layer->geometryOptions()->geometryChecks().empty() )
{
@@ -174,7 +190,7 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
if ( activeChecks.contains( checkId ) )
{
const QVariantMap checkConfiguration = layer->geometryOptions()->checkConfiguration( checkId );
layerChecks.append( factory->createGeometryCheck( checkInformation.context, checkConfiguration ) );
layerChecks.append( factory->createGeometryCheck( checkInformation.context.get(), checkConfiguration ) );
}
}

@@ -197,7 +213,7 @@ void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
if ( activeChecks.contains( checkId ) )
{
const QVariantMap checkConfiguration = layer->geometryOptions()->checkConfiguration( checkId );
topologyChecks.append( factory->createGeometryCheck( checkInformation.context, checkConfiguration ) );
topologyChecks.append( factory->createGeometryCheck( checkInformation.context.get(), checkConfiguration ) );
}
}

@@ -22,6 +22,7 @@ email : matthias@opengis.ch
#include <QReadWriteLock>

#include "qgsfeature.h"
#include "qgsgeometrycheckcontext.h"

class QgsProject;
class QgsMapLayer;
@@ -32,7 +33,6 @@ class QgsSingleGeometryCheckError;
class QgsGeometryCheckError;
class QgsFeedback;
class QgsFeaturePool;
struct QgsGeometryCheckContext;

/**
* This service connects to all layers in a project and triggers validation
@@ -69,6 +69,7 @@ class QgsGeometryValidationService : public QObject
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
void topologyChecksUpdated( QgsVectorLayer *layer, const QList<std::shared_ptr<QgsGeometryCheckError> > &errors );
void topologyChecksCleared( QgsVectorLayer *layer );
void topologyErrorUpdated( QgsVectorLayer *layer, QgsGeometryCheckError *error );

void warning( const QString &message );

@@ -80,6 +81,7 @@ class QgsGeometryValidationService : public QObject
void onBeforeCommitChanges( QgsVectorLayer *layer );

private:
void cleanupLayerChecks( QgsVectorLayer *layer );
void enableLayerChecks( QgsVectorLayer *layer );

void cancelTopologyCheck( QgsVectorLayer *layer );
@@ -98,7 +100,7 @@ class QgsGeometryValidationService : public QObject
QList<QgsFeedback *> topologyCheckFeedbacks; // will be deleted when topologyCheckFutureWatcher is delteed
QList<std::shared_ptr<QgsGeometryCheckError>> topologyCheckErrors;
QList<QMetaObject::Connection> connections;
QgsGeometryCheckContext *context = nullptr;
std::shared_ptr<QgsGeometryCheckContext> context;
};

QReadWriteLock mTopologyCheckLock;

0 comments on commit 4d40d2f

Please sign in to comment.
You can’t perform that action at this time.