[Qgis-developer] should legends be shown for invisible layers ?
Martin Dobias
wonder.sk at gmail.com
Mon Dec 15 00:21:15 PST 2014
On Mon, Dec 15, 2014 at 1:03 AM, Sandro Santilli <strk at keybit.net> wrote:
>
>
> 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.
>
There is a softer way to ask to call legend node's data() again - the
legend node can emit dataChanged() signal. This is used e.g. for symbols
defined in map units - when the scale changes they will tell the model to
update (QgsSymbolV2LegendNode::invalidateMapBasedData()).
> > 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"
>
Oh sorry for adding confusion. In my previous mail I was writing what I
_thought_ I did instead of what I have actually done.
Indeed the filter-by-map removes all legend nodes and re-adds them - the
comment is valid that ideally we should do less work and not request all
legend nodes again from QgsMapLayerLegend. We already keep the legend nodes
in mOriginalLegendNodes, so it is mainly about writing a new function to
reuse them when filtering by map content. One could go even further and not
to do a bulk remove+insert rows operations - instead one could just compare
two lists "before" and "after" and insert/remove rows only where needed.
In the initial implementation I was not having any performance problems
with the simple approach - obviously it would be nicer not to recreate the
legend nodes when not necessary.
Cheers
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141215/f1769f2b/attachment.html>
More information about the Qgis-developer
mailing list