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 <[email protected]> > 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 [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
