Bug report #7341

mapCanvas refresh does not show newly created features in memory layers

Added by Denis Rouzaud over 11 years ago. Updated almost 9 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Map Canvas
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:wontfix
Crashes QGIS or corrupts data:No Copied to github as #:16323

Description

In a plugin, I create a memory layer.

Then I add a feature in it (via python).

mapCanvas.refresh() does not make the feature visible but mapCanvas.zoomIn/Out() does.

This is truly weird, any hint?

History

#1 Updated by Denis Rouzaud over 11 years ago

calling vectorlayer.setCacheImage( None ) before refresh makes the feature appearing.

#2 Updated by Matthias Kuhn over 11 years ago

  • Target version changed from Version 2.0.0 to Future Release - Nice to have

This would require push-notification (Qt-terminology: signal) from dataprovider to vectorlayer.

#3 Updated by Jürgen Fischer over 11 years ago

did you add the features to the layer or to the provider? The former would probably have worked without clearing the layer cache manually.

#4 Updated by Denis Rouzaud over 11 years ago

yes to the provider, with addFeature

#5 Updated by Sebastian Dietrich almost 9 years ago

Jürgen Fischer wrote:

did you add the features to the layer or to the provider? The former would probably have worked without clearing the layer cache manually.

Denis Rouzaud wrote:

yes to the provider, with addFeature

Does that mean it was a misuse of QgsVectorDataProvider::addFeatures(), because this function should only be called from a layer and the correct way to add features to a layer in QGIS is to use QgsVectorLayer::addFeatures()?

Can this issue be closed then?

#6 Updated by Jürgen Fischer almost 9 years ago

  • Resolution set to wontfix
  • Status changed from Open to Closed

Sebastian Dietrich wrote:

Does that mean it was a misuse of QgsVectorDataProvider::addFeatures(), because this function should only be called from a layer and the correct way to add features to a layer in QGIS is to use QgsVectorLayer::addFeatures()?

Well, I wouldn't say misuse - but it's expected behaviour that the layer doesn't notice instantly that the data in the data provider changed. It should be added via vector layer if the intention is to see it right away.

Also available in: Atom PDF