Example #1
0
 def __init__(self, availableItems):
     """ Initializes the model with the given items. """
     
     QStandardItemModel.__init__(self)
     
     self.activeIndex = QModelIndex()
     
     # Determine all nested items
     self._parentChildMap = dict()
     self._allItems = dict()
     root = None
     for item in availableItems:
         self._parentChildMap[item.path] = list()
         currentItem = item
         while not currentItem is None:
             self._parentChildMap[item.path].append(currentItem)
             if currentItem.parent is None:
                 root = currentItem
                 self._parentChildMap[item.path].reverse()
             currentItem = currentItem.parent
     self._parentChildMap[root.path] = [root]
     
     # Initializing the model
     sRoot = self.invisibleRootItem()
     sRoot.item = root
     root.sItem = sRoot
     self._allItems[root.path] = root
     for items in self._parentChildMap.values():
         parent = sRoot
         for item in items:
             if root != item:
                 sItem = QStandardItem(item.name)
                 sItem.item = item
                 item.sItem = sItem
                 self._allItems[item.path] = item
                 parent.appendRow(sItem)
                 parent = sItem
Example #2
0
    def __init__(self, availableItems):
        """ Initializes the model with the given items. """

        QStandardItemModel.__init__(self)

        self.activeIndex = QModelIndex()

        # Determine all nested items
        self._parentChildMap = dict()
        self._allItems = dict()
        root = None
        for item in availableItems:
            self._parentChildMap[item.path] = list()
            currentItem = item
            while not currentItem is None:
                self._parentChildMap[item.path].append(currentItem)
                if currentItem.parent is None:
                    root = currentItem
                    self._parentChildMap[item.path].reverse()
                currentItem = currentItem.parent
        self._parentChildMap[root.path] = [root]

        # Initializing the model
        sRoot = self.invisibleRootItem()
        sRoot.item = root
        root.sItem = sRoot
        self._allItems[root.path] = root
        for items in self._parentChildMap.values():
            parent = sRoot
            for item in items:
                if root != item:
                    sItem = QStandardItem(item.name)
                    sItem.item = item
                    item.sItem = sItem
                    self._allItems[item.path] = item
                    parent.appendRow(sItem)
                    parent = sItem