Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def populateLayerTree(self):
- myTree = self.dlg.ui.treeLayer
- myTree.headerItem().setText(0, 'Layer List')
- myDic = {}
- myGroups = self.iface.legendInterface().groups()
- for a in self.iface.legendInterface().groupLayerRelationship():
- # initialize values
- parentItem = None
- myId = a[0]
- # select an existing item, select the header item or create the item
- if myId in myDic:
- # if the item already exists in myDic, select it
- parentItem = myDic[myId]['item']
- elif myId == '':
- # if the id is empty string, this is a root layer, select the headerItem
- parentItem = myTree.headerItem()
- else:
- # else create the item and add it to the header item
- # add the item to the dictionary
- myDic[myId] = {'id' : myId}
- if myId in myGroups:
- # it's a group
- myDic[myId]['type'] = 'group'
- else:
- # it's a layer
- myDic[myId]['type'] = 'layer'
- parentItem = QTreeWidgetItem(['%s' % unicode(myId)])
- myTree.addTopLevelItem(parentItem)
- myDic[myId]['item'] = parentItem
- # loop through the children and add children to the parent item
- for b in a[1]:
- myDic[b] = {'id' : b}
- if b in myGroups:
- # it's a group
- myDic[b]['type'] = 'group'
- else:
- # it's a layer
- myDic[b]['type'] = 'layer'
- childItem = QTreeWidgetItem(['%s' % unicode(b)])
- if myId == '':
- myTree.addTopLevelItem(childItem)
- else:
- parentItem.addChild(childItem)
- myDic[b]['item'] = childItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement