def data(self, idx: QModelIndex, role: int = Qt.DisplayRole): depth = Id.depth(idx) if depth == Id.Depth.Invalid: return if role == Role.Data: # return the top level plugin if depth == Id.Depth.D0: return self.sourcePlugin(idx.row()) if depth == Id.Depth.D1: return self.sourcePlugin(Id.row(idx.internalId())) if depth == Id.Depth.D2: return self.sourcePlugin(Id.row(Id.parentId(idx.internalId()))) if role == Role.MergeAssociations: if depth == Id.Depth.D0: return self.mergeAssociations(idx.row()) if depth == Id.Depth.D1: return self.mergeAssociations(Id.row(idx.internalId())) if depth == Id.Depth.D2: return self.mergeAssociations( Id.row(Id.parentId(idx.internalId()))) if role == Role.Cell: return self._display_data(idx) if not idx.parent().isValid(): return if role == Qt.DisplayRole: return self._display_data(idx) return self._style_data(idx, role)
def parent(self, child: QModelIndex): if not child.isValid(): return QModelIndex() parentId = child.internalId() if not Id.isValid(parentId): return QModelIndex() return self.createIndex(Id.row(parentId), Id.column(parentId), Id.parentId(parentId))
def rowCount(self, parent: QModelIndex = QModelIndex()): if not self.sourceModel(): return 0 depth = Id.depth(parent) if depth == Id.Depth.Invalid: return self.sourceModel().rowCount() if parent.column() != 0: return 0 if depth == Id.Depth.D0: return len(Row) if depth == Id.Depth.D1: plugin = self.sourcePlugin(Id.row(parent.internalId())) if not plugin.isMerge and not plugin.isMerged: return 0 plugins, merges = self.mergeAssociations( Id.row(parent.internalId())) if parent.row() == Row.MergedPlugins: return len(plugins) if parent.row() == Row.MergedBy: return len(merges) if plugin.mergeFile and parent.row() == Row.ZEditOptions: return len(MERGE_OPTIONS) return 0