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

Martin Dobias wonder.sk at gmail.com
Mon Dec 15 03:56:39 PST 2014

On Mon, Dec 15, 2014 at 6:32 PM, Sandro Santilli <strk at keybit.net> wrote:
> On Mon, Dec 15, 2014 at 03:21:15PM +0700, Martin Dobias wrote:
> > 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()).
> Ah, interesting. But I see invalidateMapBasedData is invoked on all legend
> nodes by QgsLayerTreeModel::setLegendMapViewData but not by
> QgsLayerTreeModel::setLegendFilterByMap. Should the latter also invoke
> the invalidation method ?

That sounds reasonably. The invalidateMapBasedData() could have optional
pointer to QgsMapSettings, so the WMS legend node would have a way to find
out about the details of the map view (bbox, dpi, etc).

Another thing. The QgsMapLayerLegend object is currently independent
> from a QgsMapCanvas, and thus from the settings of the map (extent).
> In my PR (#1735) I've added an optional QgsMapSetting parameter to
> the virtual QgsMapLayerLegend::createLayerTreeModelLegendNodes method.
> That way the settings can be embedded in the nodes, but if we have to
> rely on data() updating the legend, we'd need a way to pass the updated
> map settings again, or keep the old settings by pointer.

I'm not sure I like the fact that QgsMapSettings would be passed when
legend nodes are created. I guess with invalidateMapBasedData() having
QgsMapSettings pointer that would not be necessary.

Would it be inappropriate to store a pointer to the QgsLayerTreeModel
> into a QgsLayerTreeModelLegendNode ? Or is there already such link ?

Yes there is QgsLayerTreeModelLegendNode::model()

> > 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.
> Good idea, but also the "filtering" would need to be posibly done by
> nodes themself. I mean there would be a "removing nodes" kind of filtering
> and a "modify node contents" kind of filtering. Maybe there could be a
> QgsLayerTreeModelLegendNode::filterByMap() method that would return
> a value indicating if the node should be kept or removed, and would have
> a chance to update its contents. What would you think about that ?

That would be nice to have it directly inside legend nodes, but you would
still need something that would run QgsMapHitTest and then pass it to
individual nodes. So I am not sure if that would actually help.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141215/24ba6787/attachment.html>

More information about the Qgis-developer mailing list