[Qgis-developer] Re: Python - recreate the exact Legend in a QTreeWidget

kimaidou kimaidou at gmail.com
Mon Jun 20 11:28:50 EDT 2011


Of course !

This is basically what I have done :

http://pastebin.com/1yhyuRxA

Regards,
Kimaidou

2011/6/20 Germán Carrillo <carrillo.german at gmail.com>

> Hi Kimaidou,
>
> may you share your solution? It may be useful for some people here
> (including myself).
>
> Regards,
>
> Germán
>
> 2011/6/20 kimaidou <kimaidou at gmail.com>
>
>> Hi all
>>
>> I managed to reconstruct my legend in my QTreeWidget by using a dictionary
>> to store the item I have already added in the tree while looping through
>> groupLayerRelationship !
>>
>> Cheers
>> Kimaidou
>>
>>
>> 2011/6/20 kimaidou <kimaidou at gmail.com>
>>
>>> Hi devs,
>>>
>>> I am a bit stuck here....
>>> I would like to recreate the complete legend tree inside a python plugin.
>>> I have chosen to use a QtreeWidget to do so.
>>>
>>> Imagine I have:
>>> *****************
>>> group 0 (empty)
>>>
>>> group 1
>>> |-- group 11
>>>    |-- layer 11a
>>>    |-- layer 11b
>>> |-- layer 1a
>>>
>>> layer a
>>>
>>> group 2
>>> |-- group 21
>>> |-- layer 2a
>>> ***********************
>>>
>>> I have seen the
>>>
>>> iface.legendInterface().groupLayerRelationship()
>>>
>>> returns usefull information, but in a flat "C-style" way like :
>>>
>>>
>>> [
>>>   ['group 0', [] ],
>>>   ['group 1', ['group 11', 'layer_1a_10020100526085601790'] ],
>>>   ['', ['layer_a_20110617181245226'] ],
>>>   ['group 2', ['groupe21', 'layer_2a_20110616121558434'] ],
>>>   ['group 11', ['layer_11a_20100526085601799',
>>> 'layer_11b_gen20100526100356932'] ],
>>>   ['groupe21', []]
>>> ]
>>>
>>>
>>> I would like to loop though this result and create my own hierarchical
>>> representation such as :
>>> [
>>>     'name' : 'group 0' , 'type' : 'group', 'children' : [],
>>>     'name' : 'group 1' , 'type' : 'group', 'children' : [
>>>         'name' : 'group 11' , 'type' : 'group', 'children' : [
>>>             'name' : 'layer 11a' , 'type' : 'layer', 'children' : [],
>>>             'name' : 'layer 11b' , 'type' : 'layer', 'children' : []
>>>         ],
>>>         'name' : 'layer 1a' , 'type' : 'layer', 'children' : []
>>>     ],
>>>     'name' : 'layer a' , 'type' : 'layer', 'children' : [],
>>>     'name' : 'group 2' , 'type' : 'group', 'children' : [
>>>         'name' : 'group 21' , 'type' : 'group', 'children' : [],
>>>         'name' : 'layer 2a' , 'type' : 'layer', 'children' : []
>>>     ]
>>> ]
>>>
>>> I have tried hard since yesterday, but have not succeeded... Has anyone
>>> already encoutered this need ?
>>>
>>> Thanks in advance,
>>> kimaidou
>>>
>>
>>
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>>
> --
> -----------
>   |\__
> (:>__)(
>   |/
>
> Soluciones Geoinformáticas Libres
> http://geotux.tuxfamily.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20110620/f368d9c2/attachment-0001.html


More information about the Qgis-developer mailing list