Feature request #2492

Legend fails to update when layer visibility is changed during QgsMapCanvas::setLayerSet

Added by audun - over 14 years ago. Updated over 14 years ago.

Status:Closed
Priority:Low
Assignee:Marco Hugentobler
Category:Map Legend
Pull Request or Patch supplied: Resolution:fixed
Easy fix?:No Copied to github as #:12552

Description

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.

checkstateupdate.patch Magnifier - Proposed fix (1.91 KB) audun -, 2010-03-06 10:12 AM

History

#1 Updated by audun - over 14 years ago

Gary Sherman said Marco were the one testing and checking in patches, so I'll reassign it to him.

#2 Updated by Marco Hugentobler over 14 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.

Regards,
Marco

#3 Updated by audun - over 14 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.

iface.mapCanvas().setLayerSet([QgsMapCanvasLayer(getMapLayerByName("layer1"))])

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.

#4 Updated by Marco Hugentobler over 14 years ago

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

Perfect, thanks!
The patch is applied in d80c2f55 (SVN r13049)

Also available in: Atom PDF