In QGIS 2.18.19 I have a PostGIS Layer with a rule based render and activated
show feature count. The feature count does not change automatically when doing some
DELETEs as well) directly into the layers table in the database (likely same applies when e.g. replacing a source shapefile).
I think that such cases are handled with a
my_layer.dataProvider().forceReload() and there is a couple of ways as well to repaint the layer in the canvas like
iface.mapCanvas().refreshAllLayer()) and even refresh the layer symbology in the legend (
iface.layerTreeView().refreshLayerSymbology(my_layer.id())) but in all these refreshes there seems to be NO WAY to refresh the feature count.
Exception: I noticed, that over the GUI the only way to refresh feature count reliably for the layer itself and all its style rules is to go to Layer properties, set up a feature filter (simple expression
True) and then reset the filter. By clicking Ok or Apply feature count refreshes as desired, but I need to do this programmatically.
I tried reproducing the feature filter in PyQGIS like
with no effect.
After days and nights of reading source codes I was not able to figure out whats updating feature count when pressing Ok in the layer properties dialog, perhaps anyone could give me some advice...
Question: How can I generally update/refresh feature count in such case with PyQGIS?