mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-31 00:03:42 -04:00
Fix vertextool's geometry cache invalidation
This a forward port from d79c212e7ba1e5 in PR #8724 Another fix is added here (which will be backported to 3.4): layer' signal connections must be destroyed when the cache for this layer is cleared (otherwise I got an "assertion failed" in onCacheGeometryXXXX)
This commit is contained in:
parent
c263750930
commit
a1970104d0
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user