[Qgis-developer] Need help with LayerTreeModel (legend node)

Sandro Santilli strk at keybit.net
Thu Dec 18 04:46:21 PST 2014

On Wed, Dec 17, 2014 at 03:34:47PM +0100, Sandro Santilli wrote:
> On Wed, Dec 17, 2014 at 01:13:31PM +0100, Sandro Santilli wrote:
> > In the "wmslegend" branch of my fork [1] I've a working wms legend node
> > that fetches the actual legend image lazily from the Model's data() method
> > when it is invoked with the role = Qt::DecorationRole.
> > 
> > But for some reason, if I also attempt to load the legend when data() method
> > is invoked with role = Qt::SizeHintRole, all kind of weird behavior happen,
> > like crashes or hangs.
> I'm wondering if we should avoid to use internal QEventLoops completely.
> They do look like hacks meant to implement blocking operations, which
> we'd better not have after all, right ?

I've a local version of the WMSLegendNode that uses async loading, so
that basically dataChanged is emitted later rather than immediately.

I confirm in that case there's no more crash.

But to my surprise the rendering of the legend fails to redraw on
dataChanged. This is a log of what happens:

 (data) [925ms] XXX data called with role 13 -- mImage size is 0x0
 (getLegendGraphicFinished) [0ms] XXX legend graphic finished, image is 462x113
 (getLegendGraphicFinished) [0ms] XXX emitting dataChanged
 (data) [1ms] XXX data called with role 13 -- mImage size is 462x113

The first call to data (13 is SizeHint) returns 0x0 but queues loading
of the legend graphic, which completes and emits dataChanged again, then
a new data() call arrives and this time gets the correct image size.

BUT the rendered layertree looks weird correct until I trigger a redraw
by moving the mouse over it or changing the focus.

The weird looking aspect seems to be due to a discrepancy between
the actual legend image size and the space reserved for it.
In practice I have 2 layers and the layer node for second one gets
rendered right below the first one, with the legend of the first one
being printed _over_ the layer node of the second, which moves down
to the correct place on next redraw.

Could this be a bug in the QgsLayerTreeView ?


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

More information about the Qgis-developer mailing list