def add_file(self, dump_file: DumpFile): file_item = QTreeWidgetItem(self.ui.treeWidget) item_text = f'<diff> {dump_file.file_path}' if dump_file.is_diff else dump_file.file_path file_item.setText(0, item_text) tree_items: Dict[str, QTreeWidgetItem] = {} for dump_type in dump_file.dump_types: if dump_type.name.startswith('<'): continue names = dump_type.namespace.split('.') parent = file_item key = '' for name in names: if not name: continue key += name if key not in tree_items.keys(): tree_item = QTreeWidgetItem(parent) tree_item.setText(0, name) tree_items[key] = tree_item parent = tree_items[key] tree_item = QTreeWidgetItem(parent) tree_item.setText(0, dump_type.name) background_color = color.EXPLORER_DIFF_TEXT_COLOR if dump_file.is_diff else color.EXPLORER_TYPE_TEXT_COLOR tree_item.setTextColor(0, background_color) self.dump_types[tree_item] = dump_type file_item.sortChildren(0, Qt.AscendingOrder) self.ui.treeWidget.itemClicked.connect(self.item_clicked)
def create_root(self, parent, name, value): root = QTreeWidgetItem(parent) root.setText(0, name) root.setText(1, value) root.setTextColor(0, QColor('#ffffff')) root.setTextColor(1, QColor('#ffffff')) root.setBackgroundColor(0, QColor('#0066cc')) root.setBackgroundColor(1, QColor('#0066cc')) return root
def create_child(self, name, value): """Create child item of the tree""" root = QTreeWidgetItem() root.setText(0, name) root.setText(1, value) root.setTextColor(0, QColor('#0066cc')) root.setTextColor(1, QColor('#0066cc')) root.setBackgroundColor(0, QColor('#ccffff')) root.setBackgroundColor(1, QColor('#ccffff')) return root