diff --git a/src/app/vertextool/qgsvertextool.cpp b/src/app/vertextool/qgsvertextool.cpp index 7f85350ccc4d..ecc40d17a7e3 100644 --- a/src/app/vertextool/qgsvertextool.cpp +++ b/src/app/vertextool/qgsvertextool.cpp @@ -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 &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( sender() ); + mCache.remove( layer ); +} + void QgsVertexTool::onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom ) { QgsVectorLayer *layer = qobject_cast( sender() ); diff --git a/src/app/vertextool/qgsvertextool.h b/src/app/vertextool/qgsvertextool.h index e01334372a85..1ff394792c9d 100644 --- a/src/app/vertextool/qgsvertextool.h +++ b/src/app/vertextool/qgsvertextool.h @@ -97,6 +97,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing void onCachedGeometryDeleted( QgsFeatureId fid ); + void clearGeometryCache(); + void showVertexEditor(); //#spellok void deleteVertexEditorSelection();