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_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')