Skip to content

Commit f99a911

Browse files
author
Hugo Mercier
committedJan 16, 2019
Fix geometry cache invalidation in vertex tool
Partial backport of 21a7e15
1 parent 7ab24c8 commit f99a911

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎src/app/vertextool/qgsvertextool.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,17 @@ void QgsVertexTool::keyPressEvent( QKeyEvent *e )
980980

981981
QgsGeometry QgsVertexTool::cachedGeometry( const QgsVectorLayer *layer, QgsFeatureId fid )
982982
{
983-
if ( !mCache.contains( layer ) )
983+
const bool layerWasNotInCache = !mCache.contains( layer );
984+
// insert if it was not in cache
985+
QHash<QgsFeatureId, QgsGeometry>& layerCache = mCache[layer];
986+
if ( layerWasNotInCache )
984987
{
985988
connect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVertexTool::onCachedGeometryChanged );
986989
connect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::onCachedGeometryDeleted );
987990
connect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsVertexTool::clearGeometryCache );
988991
connect( layer, &QgsVectorLayer::dataChanged, this, &QgsVertexTool::clearGeometryCache );
989992
}
990993

991-
QHash<QgsFeatureId, QgsGeometry> &layerCache = mCache[layer];
992994
if ( !layerCache.contains( fid ) )
993995
{
994996
QgsFeature f;
@@ -1008,6 +1010,10 @@ void QgsVertexTool::clearGeometryCache()
10081010
{
10091011
const QgsVectorLayer *layer = qobject_cast<const QgsVectorLayer *>( sender() );
10101012
mCache.remove( layer );
1013+
disconnect( layer, &QgsVectorLayer::geometryChanged, this, &QgsVertexTool::onCachedGeometryChanged );
1014+
disconnect( layer, &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::onCachedGeometryDeleted );
1015+
disconnect( layer, &QgsVectorLayer::willBeDeleted, this, &QgsVertexTool::clearGeometryCache );
1016+
disconnect( layer, &QgsVectorLayer::dataChanged, this, &QgsVertexTool::clearGeometryCache );
10111017
}
10121018

10131019
void QgsVertexTool::onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom )

0 commit comments

Comments
 (0)
Please sign in to comment.