def index(self, row, column, parent): if not self.hasIndex(row, column, parent): return Q.QModelIndex() if not parent.isValid(): parentItem = self._rootItem else: parentItem = parent.internalPointer() childItem = parentItem.child(row) if childItem: return self.createIndex(row, column, childItem) else: return Q.QModelIndex()
def parent(self, index): if not index: return Q.QModelIndex() if not index.isValid(): return Q.QModelIndex() childItem = index.internalPointer() if not childItem: return Q.QModelIndex() parentItem = childItem.parent if not parentItem: return Q.QModelIndex() if parentItem is self._rootItem: return Q.QModelIndex() return self.indexForItem(parentItem)
def __init__(self, *args, **kwargs): player = kwargs.pop('player', None) self._player = player super().__init__(*args, **kwargs) self._headerData = ["name", "value"] self._rootItem = TreeItem(name='root', player=player) self.setupModelData(player) print(self.__class__.__name__, 'rowCount() is ', self.rowCount(Q.QModelIndex()))
def rowCount(self, parent=Q.QModelIndex()): return len(self._props)
def columnCount(self, parent=Q.QModelIndex()): return 2