[Qgis-developer] should legends be shown for invisible layers ?

Sandro Santilli strk at keybit.net
Sun Dec 14 10:03:23 PST 2014


On Sun, Dec 14, 2014 at 08:52:45AM +0700, Martin Dobias wrote:
> Hi Sandro
> 
> On Sun, Dec 14, 2014 at 6:40 AM, Sandro Santilli <strk at keybit.net> wrote:
> 
> > Does it make sense to show a layer's legend while the layer visibility is
> > off,
> > or should the legend nodes in the layertree really be removed ?
> 
> When map-based filtering is enabled, the legend nodes for invisible layers
> are not shown. Technically they are not deleted, they are just filtered out
> inside the layer tree model.

I do see calls to QgsLayerTreeModel::refreshLayerLegend, which seems to
be _removing_ and _adding_ legends nodes:

https://github.com/qgis/QGIS/blob/master/src/core/layertree/qgslayertreemodel.cpp#L500-L518

By "invisible" I mean layers with the checkbox unchecked, not those
which are outside of the extent.

> > I'm wondering as I move steps toward optimization of WMS legend construction
> > for cases in which it is not needed: http://hub.qgis.org/issues/11860
> >
> > You probably don't want to incur in the cost of new WMS GetLegendGraphics
> > requests as you pan and zoom while the layer is invisible, but then would
> > you still want the last fetched legend visible in that case ?
> 
> Indeed you don't want such extra cost. But as I noted in the ticket, if a
> legend node is filtered out or in a collapsed part of a tree, the model
> will not ask about its data(), so if fetching is implemented there, it will
> be done lazily only when required.

I'm guessing ::refreshLayerLegend is called to _force_ re-asking for
the data() whenever the map extent changes. Anyway I'll follow your
suggestion about implementing lazy load of the legend.

> > The same applies to vector layers too, except the cost is much much lower
> > there. Does it make sense for map dependent legends to update while their
> > corresponding layer is invisible ? And to show the legend at all ?
> 
> Map dependent legends for each layer are not re-created completely on every
> change of map extent: only the filtering part is applied - and when they
> are invisible all legend nodes are filtered out.

Again, this is not what I'm seeing. And the implementation of
QgsLayerTreeModel::setLegendFilterByMap seem to confirm that
the layer legend is "refreshed":
https://github.com/qgis/QGIS/blob/master/src/core/layertree/qgslayertreemodel.cpp#L606-L609

There's also a comment suggesting:
"this could be later done in more efficient way by just updating active
 legend nodes, without refreshing original legend nodes"

What am I missing ?

--strk; 

 ()  ASCII ribbon campaign  --  Keep it simple !
 /\  http://strk.keybit.net/rants/ascii_mails.txt  


More information about the Qgis-developer mailing list