Skip to content
Permalink
Browse files

Merge pull request #8851 from mhugo/fix_vertex_tool_cache

Fix vertextool's geometry cache invalidation
  • Loading branch information
Hugo Mercier
Hugo Mercier committed Jan 16, 2019
2 parents a6f2618 + a197010 commit 21a7e154a388bac859934c4c34d7772b78ef7694
Showing with 18 additions and 3 deletions.
  1. +16 −3 src/app/vertextool/qgsvertextool.cpp
  2. +2 −0 src/app/vertextool/qgsvertextool.h
@@ -980,14 +980,17 @@ void QgsVertexTool::keyPressEvent( QKeyEvent *e )

QgsGeometry QgsVertexTool::cachedGeometry( const QgsVectorLayer *layer, QgsFeatureId fid )
{
if ( !mCache.contains( layer ) )
const bool layerWasNotInCache = !mCache.contains( layer );
// insert if it was not in cache
QHash<QgsFeatureId, QgsGeometry> &layerCache = mCache[layer];
if ( layerWasNotInCache )
{
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];
if ( !layerCache.contains( fid ) )
{
QgsFeature f;
@@ -1003,6 +1006,16 @@ 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 );
disconnect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVertexTool::onCachedGeometryChanged );
disconnect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::onCachedGeometryDeleted );
disconnect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsVertexTool::clearGeometryCache );
disconnect( layer, &QgsVectorLayer::dataChanged, this, &QgsVertexTool::clearGeometryCache );
}

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 21a7e15

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