<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 15, 2014 at 1:03 AM, Sandro Santilli <span dir="ltr"><<a href="mailto:strk@keybit.net" target="_blank">strk@keybit.net</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I'm guessing ::refreshLayerLegend is called to _force_ re-asking for<br>
the data() whenever the map extent changes. Anyway I'll follow your<br>
suggestion about implementing lazy load of the legend.<br></blockquote><br>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()).<br> <div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">> > The same applies to vector layers too, except the cost is much much lower<br>
> > there. Does it make sense for map dependent legends to update while their<br>
> > corresponding layer is invisible ? And to show the legend at all ?<br>
><br>
> Map dependent legends for each layer are not re-created completely on every<br>
> change of map extent: only the filtering part is applied - and when they<br>
> are invisible all legend nodes are filtered out.<br>
<br>
</span>Again, this is not what I'm seeing. And the implementation of<br>
QgsLayerTreeModel::setLegendFilterByMap seem to confirm that<br>
the layer legend is "refreshed":<br>
<a href="https://github.com/qgis/QGIS/blob/master/src/core/layertree/qgslayertreemodel.cpp#L606-L609" target="_blank">https://github.com/qgis/QGIS/blob/master/src/core/layertree/qgslayertreemodel.cpp#L606-L609</a><br>
<br>
There's also a comment suggesting:<br>
"this could be later done in more efficient way by just updating active<br>
 legend nodes, without refreshing original legend nodes"<br></blockquote><div><br></div><div>Oh sorry for adding confusion. In my previous mail I was writing what I _thought_ I did instead of what I have actually done.</div><br>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.</div><div class="gmail_quote"><br></div><div class="gmail_quote">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.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Cheers</div><div class="gmail_quote">Martin</div><div class="gmail_quote"><br></div></div></div>