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

Sandro Santilli strk at keybit.net
Mon Dec 15 03:32:48 PST 2014


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 ?

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.

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

> 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 ?

--strk;

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


More information about the Qgis-developer mailing list