[Qgis-developer] iface.mapCanvas().setCurrentLayer does not update legend

Martin Dobias wonder.sk at gmail.com
Mon Feb 27 19:51:00 PST 2017


Hi Richard

On Mon, Feb 27, 2017 at 8:46 PM, Richard Duivenvoorde
<rdmailings at duif.net> wrote:
> Hi Devs,
>
> using:
>
> iface.mapCanvas().setCurrentLayer(l)
>
> in a python plugin works (as calling 'currentLayer()' returns l as active
> layer),
> BUT the legend is showing that l is the currentLayer (it does not make the
> background bleu)..
>
> I found that:
>
> iface.legendInterface().setCurrentLayer(l)
>
> works though.
>
> So Question: is this a bug in the first call?
> Or is that not to be used (anymore, after the legend overhaul)?

Map canvas and layer tree view (aka legend) are two separate widgets
which may have different "current" layers assigned. In QGIS main
window we have a mechanism that propagates current layer from layer
tree to canvas (just like it sets layers for rendering). This is a
one-way synchronization, so current layer from map canvas is not
propagated back (just like if someone changes list of layers for
rendering directly in map canvas, that will not affect checked items
in layer tree).

In theory we could have propagation of current layer from map canvas
back to layer tree view too, but it is not 1:1 relationship (e.g.
layer tree view can have a group selected rather than a layer, or
multiple items may be selected), so I am not so keen to have that in
place...


> And then there is also:
>
> iface.activeLayer() ?
>
> Is there a difference between active and currentlayer?
>
> If not, this is maybe a place to get a cleanup for 3.0?

It's the same thing and yes, it is a good candidate for renaming
(together with other occurrences of 'active' instead of 'current')

Cheers
Martin


More information about the Qgis-developer mailing list