Ejemplo n.º 1
0
    def setUp(self):

        self.rootItem = BaseTreeItem('root')
        self.item0 = self.rootItem.insertChild(BaseTreeItem('item0'))
        self.item1 = self.item0.insertChild(BaseTreeItem('item1'))
        self.item1a = self.item0.insertChild(BaseTreeItem('item1a'))
        self.item2 = self.item1.insertChild(BaseTreeItem('item2'))
        self.item3 = self.rootItem.insertChild(BaseTreeItem('item3'))
Ejemplo n.º 2
0
    def setUp(self):

        self.rootItem = BaseTreeItem('root')
        self.item0 = self.rootItem.insertChild(BaseTreeItem('item0'))
        self.item1 = self.item0.insertChild(BaseTreeItem('item1'))
        self.item1a = self.item0.insertChild(BaseTreeItem('item1a'))
        self.item2 = self.item1.insertChild(BaseTreeItem('item2'))
        self.item3 = self.rootItem.insertChild(BaseTreeItem('item3'))
Ejemplo n.º 3
0
    def __init__(self, parent=None):
        """ Constructor
        """
        super(BaseTreeModel, self).__init__(parent)

        # The root item is invisible in the tree but is the parent of all items.
        # This way you can have a tree with multiple items at the top level.
        # The root item also is returned by getItem in case of an invalid index.
        # Finally, it is used to store the header data.
        #self._horizontalHeaders = [header for header in headers]
        self._invisibleRootItem = BaseTreeItem(nodeName=INVISIBLE_ROOT_NAME)

        self.cellSizeHint = TREE_CELL_SIZE_HINT  # Default cell size, can be overridden by items
Ejemplo n.º 4
0
    def setInvisibleRootItem(self, treeItem=None):
        """ SetsReplaces the invisible root item, which contains no actual data

             If baseRti is None it is set to a place holder BaseTreeItem.
             Note that this resets the model
         """
        treeItem = BaseTreeItem(
            nodeName=INVISIBLE_ROOT_NAME) if treeItem is None else treeItem

        self.beginResetModel()
        try:
            self._invisibleRootTreeItem = treeItem
            self._invisibleRootTreeItem.model = self
        finally:
            self.endResetModel()
Ejemplo n.º 5
0
class TestTreeItemGetByPath(unittest.TestCase):


    def setUp(self):

        self.rootItem = BaseTreeItem('root')
        self.item0 = self.rootItem.insertChild(BaseTreeItem('item0'))
        self.item1 = self.item0.insertChild(BaseTreeItem('item1'))
        self.item1a = self.item0.insertChild(BaseTreeItem('item1a'))
        self.item2 = self.item1.insertChild(BaseTreeItem('item2'))
        self.item3 = self.rootItem.insertChild(BaseTreeItem('item3'))


    def testStartAtItem(self):

        # Normal use
        checkItem = self.rootItem.findByNodePath('item3')
        self.assertIs(checkItem, self.item3)

        # Long path
        checkItem = self.rootItem.findByNodePath('item0/item1/item2')
        self.assertIs(checkItem, self.item2)

        # Leading slash
        self.assertRaises(AssertionError, self.rootItem.findByNodePath, '/item3')

        # Trailing slash
        checkItem = self.rootItem.findByNodePath('item3/')
        self.assertIs(checkItem, self.item3)

        # Long path with double slashes
        checkItem = self.rootItem.findByNodePath('item0///item1//')
        self.assertIs(checkItem, self.item1)

        # Item not found
        self.assertRaises(IndexError, self.rootItem.findByNodePath, 'item0/narf//')

        # Empty string
        self.assertRaises(IndexError, self.rootItem.findByNodePath, '')

        # None-strings
        self.assertRaises(TypeError, self.rootItem.findByNodePath, 444)
Ejemplo n.º 6
0
 def insertBaseTreeItem(self, nodeName, parentIndex=None):
     "Inserts a new BaseTreeItem item in the model"
     item = BaseTreeItem(nodeName=nodeName)
     index = self.model.insertItem(item, parentIndex=parentIndex)
     return item, index