Skip to content

Commit 0b29ed6

Browse files
author
Hugo Mercier
committedDec 20, 2018
Fix vertextool's geometry cache invalidation
The cache must be invalidated when the layer is deleted and also on dataChanged.
1 parent 381627e commit 0b29ed6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎src/app/vertextool/qgsvertextool.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,8 @@ QgsGeometry QgsVertexTool::cachedGeometry( const QgsVectorLayer *layer, QgsFeatu
984984
{
985985
connect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVertexTool::onCachedGeometryChanged );
986986
connect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::onCachedGeometryDeleted );
987-
// TODO: also clear cache when layer is deleted
987+
connect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsVertexTool::clearGeometryCache );
988+
connect( layer, &QgsVectorLayer::dataChanged, this, &QgsVertexTool::clearGeometryCache );
988989
}
989990

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

1007+
void QgsVertexTool::clearGeometryCache()
1008+
{
1009+
const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( sender() );
1010+
mCache.remove( layer );
1011+
}
1012+
10061013
void QgsVertexTool::onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom )
10071014
{
10081015
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( sender() );

‎src/app/vertextool/qgsvertextool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
9797

9898
void onCachedGeometryDeleted( QgsFeatureId fid );
9999

100+
void clearGeometryCache();
101+
100102
void showVertexEditor(); //#spellok
101103

102104
void deleteVertexEditorSelection();

0 commit comments

Comments
 (0)
Please sign in to comment.