def index(self, row: int, column: int, parent: core.ModelIndex | None = None) -> core.ModelIndex: if parent is None: logger.debug("parent is None") parent = core.ModelIndex() parent_item = self.tree_item(parent) if not self.hasIndex(row, column, parent): logger.debug("hasIndex is False: (%s, %s) %r", row, column, parent_item) # logger.warn("Parent index model: {!r} != {!r}".format(parent.model(), self)) return core.ModelIndex() child_item = parent_item.child(row) # logger.debug(" {}".format(child_item.obj_path)) if child_item: return self.createIndex(row, column, child_item) else: logger.warn("no child_item") return core.ModelIndex()
def index(self, row, column, parent=core.ModelIndex()): if not self.hasIndex(row, column, parent): return core.ModelIndex() parent_item = parent.internalPointer() if not parent_item: parent_item = self.root return self.createIndex(row, column, parent_item.children[row])
def parent(self, index: core.ModelIndex) -> QtCore.QModelIndex: # type:ignore if not index.isValid(): return core.ModelIndex() child_item = index.internalPointer() parent_item = child_item.parent() # type: ignore if parent_item is None or parent_item == self.root_item: return core.ModelIndex() return self.createIndex(parent_item.row(), 0, parent_item)
def parent(self, index): if not index.isValid(): return core.ModelIndex() item = index.internalPointer() if not item: return core.ModelIndex() if item.parent in [self.root, None]: return core.ModelIndex() return self.createIndex(item.parent.row(), 0, item.parent)
def rowCount(self, parent=core.ModelIndex()): if parent.column() > 0: return 0 if not parent.isValid(): return len(self.items) return len(parent.internalPointer().children)
def canFetchMore(self, parent: core.ModelIndex | None = None): parent = core.ModelIndex() if parent is None else parent if parent.column() > 0: return 0 else: result = not self.tree_item(parent).children_fetched # logger.debug("canFetchMore: {} = {}".format(parent, result)) return result
def rowCount(self, parent: core.ModelIndex | None = None): parent = core.ModelIndex() if parent is None else parent if parent.column() > 0: # This is taken from the PyQt simpletreemodel example. return 0 else: return self.tree_item(parent).child_count()
def test_itemselectionrange(): selection_range = core.ItemSelectionRange() # selection_range_2 = core.ItemSelectionRange() # selection_range_3 = selection_range & selection_range_2 assert core.ModelIndex() in selection_range assert bool(selection_range) is False assert len(selection_range) == 0 for i in selection_range: pass
def fetchMore(self, parent: core.ModelIndex | None = None): """Fetches the children given the model index of a parent node. Adds the children to the parent. """ parent = core.ModelIndex() if parent is None else parent if parent.column() > 0: return parent_item = self.tree_item(parent) if parent_item.children_fetched: return tree_items = self._fetch_object_children(parent_item.obj, parent_item.obj_path) with self.insert_rows(0, len(tree_items) - 1, parent): for tree_item in tree_items: parent_item.append_child(tree_item) parent_item.children_fetched = True
def rowCount(self, parent=core.ModelIndex()): return len(self.distributions) if not parent.isValid() else 0
def hasChildren(self, parent: core.ModelIndex | None = None): parent = core.ModelIndex() if parent is None else parent if parent.column() > 0: return 0 else: return self.tree_item(parent).has_children
def columnCount(self, parent: core.ModelIndex | None = None) -> int: if parent is None: parent = core.ModelIndex() return self._source_model.rowCount(parent)
def test_modelindex(): core.ModelIndex()
def columnCount(self, parent=core.ModelIndex()): return len(self.HEADER) if not parent.isValid() else 0
def test_itemselection(): selection = core.ItemSelection(core.ModelIndex(), core.ModelIndex()) index = core.ModelIndex() assert index not in selection for idx in selection: pass
def columnCount(self, parent=core.ModelIndex()) -> int: return self._source_model.rowCount(parent)
def root_index(self) -> core.ModelIndex: # TODO: needed? """The index that returns the root element (same as an invalid index).""" return core.ModelIndex()