From 2c09573d2aca79bf6291820fab904e7bab612e01 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sat, 7 Jan 2023 14:30:10 +0100 Subject: [PATCH] Display graph/set number in tree; fixes T243 --- src/gui_qt/data/datawidget/datawidget.py | 32 ++++++++++++++++++++++-- src/gui_qt/lib/delegates.py | 8 +++++- src/nmreval/data/points.py | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/gui_qt/data/datawidget/datawidget.py b/src/gui_qt/data/datawidget/datawidget.py index 08388cb..0a73161 100644 --- a/src/gui_qt/data/datawidget/datawidget.py +++ b/src/gui_qt/data/datawidget/datawidget.py @@ -21,7 +21,6 @@ class DataTree(QtWidgets.QTreeWidget): def __init__(self, parent=None): super().__init__(parent=parent) - self.setColumnCount(1) self.invisibleRootItem().setFlags(self.invisibleRootItem().flags() ^ QtCore.Qt.ItemIsDropEnabled) self.itemChanged.connect(self.data_change) @@ -44,7 +43,7 @@ class DataTree(QtWidgets.QTreeWidget): header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch) header.setVisible(False) header.moveSection(1, 0) - self.setColumnWidth(1, 16) + # self.setColumnWidth(1, 16) self.setItemDelegateForColumn(1, HeaderDelegate()) def add_graph(self, idd: str, name: str): @@ -59,6 +58,8 @@ class DataTree(QtWidgets.QTreeWidget): self._checked_graphs.add(idd) item.setExpanded(True) + self.update_indexes() + def add_item(self, items: Union[tuple, List[tuple]], gid: str): if isinstance(items, tuple): items = [items] @@ -78,6 +79,8 @@ class DataTree(QtWidgets.QTreeWidget): self.resizeColumnToContents(0) break + self.update_indexes() + @QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem) def data_change(self, item: QtWidgets.QTreeWidgetItem) -> Tuple[set, set]: idd = item.data(0, QtCore.Qt.UserRole) @@ -189,6 +192,8 @@ class DataTree(QtWidgets.QTreeWidget): to_parent.data(0, QtCore.Qt.UserRole), take_from, pos=-1 if append else row) + self.update_indexes() + def move_sets(self, sid: str, gid_in: str, gid_out: str): self.blockSignals(True) to_parent = None @@ -218,8 +223,29 @@ class DataTree(QtWidgets.QTreeWidget): from_parent.removeChild(it) to_parent.addChild(it) + self.update_indexes() + self.blockSignals(False) + def update_indexes(self): + graph_cnt = -1 + set_cnt = 0 + iterator = QtWidgets.QTreeWidgetItemIterator(self) + while iterator.value(): + item = iterator.value() + if item is not None: + if item.parent() is None: + graph_cnt += 1 + set_cnt = 0 + item.setText(1, f'G[{graph_cnt}]') + else: + item.setText(1, f'G[{graph_cnt}].S[{set_cnt}]') + set_cnt += 1 + + iterator += 1 + + self.resizeColumnToContents(1) + def set_name(self, sid, name): iterator = QtWidgets.QTreeWidgetItemIterator(self) while iterator.value(): @@ -306,6 +332,8 @@ class DataTree(QtWidgets.QTreeWidget): iterator += 1 + self.update_indexes() + def contextMenuEvent(self, evt): menu = QtWidgets.QMenu() _ = menu.addAction('Hello') diff --git a/src/gui_qt/lib/delegates.py b/src/gui_qt/lib/delegates.py index bbad0b7..d6f0c9a 100644 --- a/src/gui_qt/lib/delegates.py +++ b/src/gui_qt/lib/delegates.py @@ -231,5 +231,11 @@ class HeaderDelegate(QtWidgets.QStyledItemDelegate): style = QtWidgets.QApplication.style() style.drawControl(QtWidgets.QStyle.CE_HeaderSection, header_option, painter) + + text_rect = style.subElementRect(QtWidgets.QStyle.SE_ItemViewItemText, option, None) + text_rect.adjust(2, 0, 0, 0) + if option.state & QtWidgets.QStyle.State_Selected: - painter.fillRect(option.rect, option.palette.highlight()) \ No newline at end of file + painter.fillRect(option.rect, option.palette.highlight()) + + painter.drawText(text_rect, option.displayAlignment, index.data(QtCore.Qt.DisplayRole)) diff --git a/src/nmreval/data/points.py b/src/nmreval/data/points.py index 05854f4..35d8403 100644 --- a/src/nmreval/data/points.py +++ b/src/nmreval/data/points.py @@ -86,7 +86,7 @@ class Points: y_err = np.atleast_1d(y_err) if y_err.shape != y.shape: raise ValueError(f'y_err ({y_err.shape}) and y ({y.shape}) have different shapes') - print(x, x.shape, x.ndim) + return x, y, y_err, mask @property