Advertisement
Guest User

Untitled

a guest
Jun 20th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1.   def populateLayerTree(self):
  2.     myTree = self.dlg.ui.treeLayer
  3.     myTree.headerItem().setText(0, 'Layer List')
  4.     myDic = {}
  5.     myGroups = self.iface.legendInterface().groups()
  6.     for a in self.iface.legendInterface().groupLayerRelationship():
  7.       # initialize values
  8.       parentItem = None
  9.       myId = a[0]
  10.      
  11.       # select an existing item, select the header item or create the item
  12.       if myId in myDic:
  13.         # if the item already exists in myDic, select it
  14.         parentItem = myDic[myId]['item']
  15.       elif myId == '':
  16.         # if the id is empty string, this is a root layer, select the headerItem
  17.         parentItem = myTree.headerItem()
  18.       else:
  19.         # else create the item and add it to the header item
  20.         # add the item to the dictionary
  21.         myDic[myId] = {'id' : myId}
  22.         if myId in myGroups:
  23.           # it's a group
  24.           myDic[myId]['type'] = 'group'
  25.         else:
  26.           # it's a layer
  27.           myDic[myId]['type'] = 'layer'
  28.         parentItem = QTreeWidgetItem(['%s' % unicode(myId)])
  29.         myTree.addTopLevelItem(parentItem)
  30.         myDic[myId]['item'] = parentItem
  31.      
  32.       # loop through the children and add children to the parent item
  33.       for b in a[1]:
  34.         myDic[b] = {'id' : b}
  35.         if b in myGroups:
  36.           # it's a group
  37.           myDic[b]['type'] = 'group'
  38.         else:
  39.           # it's a layer
  40.           myDic[b]['type'] = 'layer'
  41.                    
  42.         childItem = QTreeWidgetItem(['%s' % unicode(b)])
  43.         if myId == '':
  44.           myTree.addTopLevelItem(childItem)
  45.         else:
  46.           parentItem.addChild(childItem)
  47.         myDic[b]['item'] = childItem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement