Feature request #2492
Legend fails to update when layer visibility is changed during QgsMapCanvas::setLayerSet
|Pull Request or Patch supplied:||Resolution:||fixed|
|Easy fix?:||No||Copied to github as #:||12552|
This is a problem when writing plugins that toggle the visibility of layers for workflow or other purposes.
If visibility is changed using the legend afterwards, the visibilities are reverted to reflect the state in the legend.
#2 Updated by Marco Hugentobler almost 12 years ago
Could you test with your plugin the following case:
You have legend groups with several layers in it and you change the visibility of a layer inside the group by plugin. Let's say the layers are all visible, but the plugin changes one to not visible. Does the group check box change to partially checked (as it should)?
If yes, it's ok. If not, you might need to add, in the function 'refreshCheckStates()' another loop that goes through all the groups and calls QgsLegendGroup::updateCheckState() for each.
#3 Updated by audun - over 11 years ago
It works, but here's some code that proves it.
from qgis.utils import iface from qgis.gui import [[QgsMapCanvasLayer]] from ftools_utils import getMapLayerByName iface.mapCanvas().setLayerSet()
Now all layers are turned off.
Now layer1 will be turned on, and the group it was in would be partially checked. Note: If there are no layers called "layer1", bug #2543 will be triggered.