Opened 14 years ago

Closed 14 years ago

#2492 closed patch (fixed)

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

Reported by: audun Owned by: mhugent
Priority: major: does not work as expected Milestone: Version 1.5.0
Component: Map Legend Version: Trunk
Keywords: Cc:
Must Fix for Release: No Platform: All
Platform Version: Awaiting user input: no

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.

Attachments (1)

checkstateupdate.patch (1.9 KB ) - added by audun 14 years ago.
Proposed fix

Download all attachments as: .zip

Change History (6)

by audun, 14 years ago

Attachment: checkstateupdate.patch added

Proposed fix

comment:1 by audun, 14 years ago

Owner: changed from nobody to mhugent

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

comment:2 by mhugent, 14 years ago

Type: bugpatch

comment:3 by mhugent, 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

comment:4 by audun, 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.

comment:5 by mhugent, 14 years ago

Resolution: fixed
Status: newclosed

Perfect, thanks! The patch is applied in r13048

Note: See TracTickets for help on using tickets.