[Qgis-developer] Legend refactoring branch merged

Hugo Mercier hugo.mercier at oslandia.com
Wed Jun 4 08:00:57 PDT 2014


Le 03/06/2014 20:01, Martin Dobias a écrit :

>>
>> After some more tests, it seems to happen when a layer is first removed.
>> To reproduce :
>> * start from a blank project,
>> * add a new layer,
>> * add another layer,
>> * remove the newly added,
>> * add another layer => it will be placed at the bottom, and if you do it
>> again, on top, and then at the bottom, etc.
> 
> Thanks for the test case. Should be fixed now, please check again with
> latest master.

Perfect, thanks !


> 
> You can reorder layers in map canvas by simply reordering the entries
> in the layer tree - the same way as done with drag'n'drop: 1. add a
> new node(s), 2. remove old node(s). Simply get the layer tree from
> project (QgsProject.instance().layerTreeRoot()) and then just call the
> root group's methods to add/remove nodes.

Ok, I am trying to use it.
Some issues :

- passing 'false' to the 'addToLegend' parameter of
QgsMapLayerRegistry::addMapLayer (in Python) still adds the layer to the
legend, apparently

- QgsLayerTreeGroup.insertLayer( 0, layer ) gives strange things in
Python (crash of qgis). Doing insertChildNode( 0, QgsLayerTreeLayer(
layer ) ), or storing the object returned by insertLayer solves the
problem. It seems to be related to the way Python garbage collects (?)

Just a remark on the API : if layers must be added first to the
MapLayerRegistry before being added to the legend, then why removing a
layer from the legend makes it removed from the registry and only if it
is the only one remaining ?

> 
> Alternatively one could use the map canvas bridge class and set a
> customized layer order in case the layer order in canvas should not be
> the same as in the tree. The bridge class is currently not exposed
> from QgisApp, though no problem to add it.
> 

Ok, no need for that yet for me, but that may be interesting.
Thanks



More information about the Qgis-developer mailing list