Пример #1
0
    def test_recursiveCheck(self):
        self.populateTree()
        rootnode = self.session.query(GenericSystemTreeNode).filter_by(
            parent_id=None).one()
        model = GenericTreeModel(rootnode, treenode=GenericSystemTreeNode)
        self.logger.info('setting parent index')
        parent_index = model.index(0, 0, QtCore.QModelIndex())
        self.logger.info('setting parent checked')
        model.setData(parent_index, QtCore.Qt.Checked,
                      QtCore.Qt.CheckStateRole)
        state = model.data(parent_index, QtCore.Qt.CheckStateRole)
        self.logger.info('Validating that state is checked')
        self.assertTrue(state)

        self.logger.info('Validating that all children are checked')
        for childnr in range(model.rowCount(parent_index)):
            subindex = model.index(childnr, 0, parent_index)
            state = model.data(subindex, QtCore.Qt.CheckStateRole)
            self.assertTrue(state)

        self.logger.info('testing unchecking')
        model.setData(parent_index, QtCore.Qt.Unchecked,
                      QtCore.Qt.CheckStateRole)
        state = model.data(parent_index, QtCore.Qt.CheckStateRole)
        self.logger.info('Validating that state is unchecked')
        self.assertFalse(state)

        self.logger.info('Validating that all children are unchecked')
        for childnr in range(model.rowCount(parent_index)):
            subindex = model.index(childnr, 0, parent_index)
            state = model.data(subindex, QtCore.Qt.CheckStateRole)
            self.assertFalse(state)
    def test_filterAcceptsRow(self):
        populateChecksTree(self.session)
        rootnode = self.session.query(Check).filter_by(parent_id=None).first()
        model = GenericTreeModel(rootnode, treenode=Check)

        filter_model=PolyMorphicFilterProxyModel(filterClasses=self.filter)
        filter_model.setSourceModel(model)

        rootindex=QtCore.QModelIndex()
        self.assertEqual(model.rowCount(rootindex), 2)
        self.assertEqual(filter_model.rowCount(rootindex), 2)
        index=model.index(1, 0, rootindex)  #Folder "Basis"
        self.assertEqual(model.rowCount(index), 1)
        self.assertEqual(model.data(index, QtCore.Qt.DisplayRole), 'Basis')
        self.assertEqual(model.rowCount(index), 1)
        index=model.index(0, 0, index)
        self.assertEqual(model.data(index, QtCore.Qt.DisplayRole), 'Post Install')
        self.assertEqual(model.rowCount(index), 1)
        index=model.index(0, 0, index)
        self.assertEqual(model.data(index, QtCore.Qt.DisplayRole), 'Clients 001 and 066 removed')

        filter_index=filter_model.index(1, 0, rootindex)
        self.assertEqual(filter_model.data(filter_index, QtCore.Qt.DisplayRole), 'Basis')
        filter_index=filter_model.index(0, 0, filter_index)
        self.assertEqual(filter_model.data(filter_index, QtCore.Qt.DisplayRole), 'Post Install')
        self.assertEqual(filter_model.rowCount(filter_index), 0)
Пример #3
0
 def test_setData(self):
     rootnode = self.session.query(Check).filter_by(parent_id=None).first()
     model = GenericTreeModel(rootnode, treenode=Check)
     index = model.createIndex(0, 0, rootnode)
     self.assertTrue(index.isValid())
     name = model.data(index, QtCore.Qt.DisplayRole)
     self.assertEqual(name, 'RootNode')
     model.setData(index, 'StillRootNode')
     name = model.data(index, QtCore.Qt.DisplayRole)
     self.assertEqual(name, 'StillRootNode')
Пример #4
0
 def test_data(self):
     self.populateTree()
     rootnode = self.session.query(GenericSystemTreeNode).filter_by(
         parent_id=None).one()
     model = GenericTreeModel(rootnode)
     index = model.createIndex(0, 0, rootnode)
     self.assertTrue(index.isValid())
     name = model.data(index, QtCore.Qt.DisplayRole)
     self.assertEqual(name, 'RootNode')
Пример #5
0
 def test_columnCount(self):
     rootnode = self.session.query(Check).filter_by(parent_id=None).one()
     model = GenericTreeModel(rootnode, treenode=Check)
     column_count = model.columnCount()
     self.assertEqual(column_count, 2)
     rootindex = model.createIndex(0, 0, rootnode)
     self.assertTrue(rootindex.isValid())
     name = model.data(rootindex, QtCore.Qt.DisplayRole)
     assert name == 'RootNode'
Пример #6
0
    def test_parent(self):
        self.populateTree()
        rootnode = self.session.query(GenericSystemTreeNode).filter_by(
            parent_id=None).one()
        model = GenericTreeModel(rootnode, treenode=GenericSystemTreeNode)

        node1index = model.index(0, 0, QtCore.QModelIndex())
        node2index = model.index(0, 0, node1index)

        self.assertEqual(model.data(node1index, QtCore.Qt.DisplayRole), 'DEV')
        self.assertEqual(model.data(node2index, QtCore.Qt.DisplayRole), 'E1D')

        data_node1 = model.data(node1index, QtCore.Qt.DisplayRole)

        node1_node = node1index.internalPointer()
        self.assertEqual(node1_node.name, 'DEV')
        node2_node = node2index.internalPointer()
        self.assertEqual(node2_node.name, 'E1D')
        node2_parent_index = model.parent(node2index)
        node2_parent_node = node2_parent_index.internalPointer()
        self.assertEqual(node2_parent_node.name, 'DEV')
Пример #7
0
    def test_parent(self):
        self.populateTree()
        rootnode = self.session.query(Check).filter_by(parent_id=None).first()
        model = GenericTreeModel(rootnode, treenode=Check)

        node1index = model.index(1, 0, QtCore.QModelIndex())
        node2index = model.index(0, 0, node1index)

        self.assertEqual(model.data(node1index, QtCore.Qt.DisplayRole),
                         'Basis')
        self.assertEqual(model.data(node2index, QtCore.Qt.DisplayRole),
                         'Post Install')

        data_node1 = model.data(node1index, QtCore.Qt.DisplayRole)

        node1_node = node1index.internalPointer()
        self.assertEqual(node1_node.name, 'Basis')
        node2_node = node2index.internalPointer()
        self.assertEqual(node2_node.name, 'Post Install')
        node2_parent_index = model.parent(node2index)
        node2_parent_node = node2_parent_index.internalPointer()
        self.assertEqual(node2_parent_node.name, 'Basis')