Skip to content
Permalink
Browse files

Fix vertextool's geometry cache invalidation

The cache must be invalidated when the layer is deleted and also on dataChanged.
  • Loading branch information
Hugo Mercier
Hugo Mercier committed Dec 20, 2018
1 parent 381627e commit 0b29ed68cb2cc92de6d29efa6972e1922f51618a
Showing with 10 additions and 1 deletion.
  1. +8 −1 src/app/vertextool/qgsvertextool.cpp
  2. +2 −0 src/app/vertextool/qgsvertextool.h
@@ -984,7 +984,8 @@ QgsGeometry QgsVertexTool::cachedGeometry( const QgsVectorLayer *layer, QgsFeatu
{
connect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVertexTool::onCachedGeometryChanged );
connect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::onCachedGeometryDeleted );
// TODO: also clear cache when layer is deleted
connect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsVertexTool::clearGeometryCache );
connect( layer, &QgsVectorLayer::dataChanged, this, &QgsVertexTool::clearGeometryCache );
}

QHash<QgsFeatureId, QgsGeometry> &layerCache = mCache[layer];
@@ -1003,6 +1004,12 @@ QgsGeometry QgsVertexTool::cachedGeometryForVertex( const Vertex &vertex )
return cachedGeometry( vertex.layer, vertex.fid );
}

void QgsVertexTool::clearGeometryCache()
{
const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( sender() );
mCache.remove( layer );
}

void QgsVertexTool::onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom )
{
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( sender() );
@@ -97,6 +97,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

void onCachedGeometryDeleted( QgsFeatureId fid );

void clearGeometryCache();

void showVertexEditor(); //#spellok

void deleteVertexEditorSelection();

0 comments on commit 0b29ed6

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