[Qgis-developer] Moving a layer with PyQGIS using the new layer tree

Germán Carrillo carrillo.german at gmail.com
Thu Dec 18 06:50:18 PST 2014


Thank you Luigi.

So, I guess the following code would be enough to make the example given in
[1] much more generic:

#######
cloned_group1 = node_group1.clone()
root.insertChildNode(0, cloned_group1)

parent = node_group1.parent()                   # new code

parent.removeChildNode(node_group1)     # replace root by parent
#######


Wouldn't make sense to post such modified example instead?

Regards,

Germán
---
[1]
http://www.lutraconsulting.co.uk/blog/2014/07/25/qgis-layer-tree-api-part-2/




2014-12-17 17:39 GMT-05:00 Luigi Pirelli <luipir at gmail.com>:
>
> You have to refer to the group as root to remove his child
>
> Regards Luigi Pirelli
>
> On Wednesday, 17 December 2014, Germán Carrillo <carrillo.german at gmail.com>
> wrote:
>
>> Hi all (and Martin D.),
>>
>>
>> I've been trying to reproduce the instructions given here [1] for moving
>> layers. It seems that the code doesn't work if the layer to be moved is
>> inside a group.
>>
>> Specifically, trying to move a layer that is inside a group, I can add
>> the clonned layer to the layer tree but I cannot get the original layer
>> removed, i.e., the following command doesn't work:
>>
>>    root.removeChildNode( originalLayer )
>>
>> It doesn't throw any message nor change the map/ToC status.
>>
>>
>> Can you reproduce the problem? I'm using QGIS 2.6.1 on Ubuntu.
>>
>>
>> Regards,
>>
>> Germán Carrillo
>> --
>> [1]
>> http://www.lutraconsulting.co.uk/blog/2014/07/25/qgis-layer-tree-api-part-2/
>>
>>
>> --
>> -----------
>>    |\__
>> (:>__)(
>>    |/
>>
>> Soluciones Geoinformáticas Libres
>> http://geotux.tuxfamily.org/
>> http://twitter.com/GeoTux2
>>
>

-- 
-----------
   |\__
(:>__)(
   |/

Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
http://twitter.com/GeoTux2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141218/ecad4966/attachment-0001.html>


More information about the Qgis-developer mailing list