Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_40] qgsvectorlayer: Properly invalidate extent cache on feature addition or deletion #60504

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

qgis-bot
Copy link
Collaborator

@qgis-bot qgis-bot commented Feb 7, 2025

Backport #60431
Authored by: @ptitjano

When a new feature is added to a `QgsVectorLayer`
`QgsVectorLayer::addFeature` is called. This function makes mostly 2
things in case of a successful operation:
1. it calls `QgsVectorLayerEditBuffer::addFeature` which itself will
   emit the `QgsVectorLayerEditBuffer::featureAdded` signal. Finally,
   `QgsVectorLayer` listend to this signal to directly emit the
   `QgsVectorLayer::featureAdded` signal
2. Call `QgsVectorLayer::updateExtents()` to invalidate the cache of
   the extent

In practice, this means that the `QgsVectorLayer::featureAdded` signal
may be emitted before the cache of the extent is invalidated. This can
cause some issues.

For example, in the elevation profile tool,
`QgsElevationProfileCanvas` listens to the
`QgsVectorLayer::featureAdded` signal in order to regenerate the
profile of a vector layer when a feature is added. This causes the
creation of a new `QgsVectorLayerProfileGenerator` which needs to copy
the extent of the vector layer. However,
`QgsVectorLayer::updateExtents()` has not been called yet. Thus, it
will use an outdated version of the extent.

This issue is solved by calling `updateExtents()` before emitting the
`featureAdded` signal.
This change is similar to the previous commit on feature addition.

When a feature is removed from a `QgsVectorLayer`
`QgsVectorLayer::deleteFeature` is called. This function makes mostly
2 things in case of a successful operation:
1. it calls `QgsVectorLayerEditBuffer::deleteFeature` which itself
   will emit the `QgsVectorLayerEditBuffer::featureDeleted`
   signal. Finally, `QgsVectorLayer` listend to this signal to
   directly emit the `QgsVectorLayer::featureDeleted` signal
2. Call `QgsVectorLayer::updateExtents()` to invalidate the cache of
   the extent

In practice, this means that the `QgsVectorLayer::featureDeleted`
signal may be emitted before the cache of the extent is
invalidated. This can cause some issues.

This issue is solved by calling `updateExtents()` before emitting the
`featureDeleted` signal.
@github-actions github-actions bot added this to the 3.40.4 milestone Feb 7, 2025
Copy link

github-actions bot commented Feb 7, 2025

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit bdaff94)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit bdaff94)

@nyalldawson nyalldawson merged commit fdc7475 into release-3_40 Feb 7, 2025
35 checks passed
@nyalldawson nyalldawson deleted the backport-60431-to-release-3_40 branch February 7, 2025 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants