From bd8a4f16ea6d74dfbbe2a0ac76508ed51a3baa9c Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sat, 15 Apr 2023 15:40:49 +0200 Subject: [PATCH] UpperManagement.deleteDate emits list of sets, indexes in datawidget are now only updated once --- src/gui_qt/data/datawidget/datawidget.py | 9 +++++---- src/gui_qt/lib/undos.py | 4 ++-- src/gui_qt/main/mainwindow.py | 11 ++++++----- src/gui_qt/main/management.py | 16 ++++++++++++---- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/gui_qt/data/datawidget/datawidget.py b/src/gui_qt/data/datawidget/datawidget.py index d3a4df3..515506e 100644 --- a/src/gui_qt/data/datawidget/datawidget.py +++ b/src/gui_qt/data/datawidget/datawidget.py @@ -20,6 +20,7 @@ class DataTree(QtWidgets.QTreeWidget): saveFits = QtCore.pyqtSignal(list) extendFits = QtCore.pyqtSignal(list) + # noinspection PyUnresolvedReferences def __init__(self, parent=None): super().__init__(parent=parent) @@ -230,7 +231,7 @@ class DataTree(QtWidgets.QTreeWidget): def sort(self, graph_item: QtWidgets.QTreeWidgetItem, mode: str = 'value'): graph_id = graph_item.data(0, QtCore.Qt.UserRole) - sets = self.management.get_attributes(graph_id, mode) + sets = self.management.get_attributes(graph_id, mode) sets = [el[0] for el in sorted(sets.items(), key=lambda x: x[1])] self.management.move_sets(sets, graph_id, graph_id, pos=-1) @@ -248,7 +249,6 @@ class DataTree(QtWidgets.QTreeWidget): self.blockSignals(False) - def update_indexes(self): graph_cnt = -1 set_cnt = 0 @@ -343,7 +343,7 @@ class DataTree(QtWidgets.QTreeWidget): self.setDragEnabled(idx.column() == 0) super().mousePressEvent(evt) - def remove_item(self, ids: list): + def remove_item(self, ids: list[str]): iterator = QtWidgets.QTreeWidgetItemIterator(self) while iterator.value(): item = iterator.value() @@ -527,6 +527,7 @@ class DataWidget(QtWidgets.QWidget, Ui_DataWidget): self.setupUi(self) self.tree = DataTree(self) self.verticalLayout.addWidget(self.tree) + # noinspection PyUnresolvedReferences self.tree.selectionModel().selectionChanged.connect(lambda x, y: self.show_property(x)) self.tree.keyChanged.connect(lambda x, y: self.keyChanged.emit(x, y)) @@ -554,7 +555,7 @@ class DataWidget(QtWidgets.QWidget, Ui_DataWidget): self.tree.add_item(loi, gid) self.tree.blockSignals(False) - def remove_item(self, key): + def remove_item(self, key: list[str]): self.tree.remove_item(key) def show_property(self, _: QtCore.QModelIndex = None): diff --git a/src/gui_qt/lib/undos.py b/src/gui_qt/lib/undos.py index 86714a6..acc1f37 100644 --- a/src/gui_qt/lib/undos.py +++ b/src/gui_qt/lib/undos.py @@ -236,9 +236,9 @@ class DeleteCommand(QtWidgets.QUndoCommand): # stop graph from rescaling and updating legend self.__graph_container[self.__graph_key].block(True) + self.__signal_remove.emit(list(self.__keys[::-1])) for sid in self.__keys[::-1]: val = self.__value[sid] - self.__signal_remove.emit(sid) if isinstance(val, FitContainer): try: @@ -264,7 +264,7 @@ class DeleteCommand(QtWidgets.QUndoCommand): except KeyError: pass - self.__signal_add.emit([sid], val.graph) + self.__signal_add.emit(list(self.__keys), self.__graph_key) self.__graph_container[self.__graph_key].block(False) diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index 29fa278..1680f41 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -348,7 +348,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): @QtCore.pyqtSlot(str) def remove_graph(self, gid: str): - self.datawidget.remove_item(gid) + self.datawidget.remove_item([gid]) val_figure = self.valuewidget.connected_figure self.valuewidget.remove_graph() @@ -733,10 +733,11 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.datawidget.set_name(sid, self.management[sid].name) - @QtCore.pyqtSlot(str) - def delete_data(self, sid): - if self.valuewidget.shown_set == sid: - self.tabWidget.setCurrentIndex(0) + @QtCore.pyqtSlot(list) + def delete_data(self, sid: list[str]): + for key in sid: + if self.valuewidget.shown_set == key: + self.tabWidget.setCurrentIndex(0) self.datawidget.remove_item(sid) diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index edbb032..594afe4 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -75,7 +75,7 @@ class UpperManagement(QtCore.QObject): restoreGraph = QtCore.pyqtSignal(str) deleteGraph = QtCore.pyqtSignal(str) newData = QtCore.pyqtSignal(list, str) - deleteData = QtCore.pyqtSignal(str) + deleteData = QtCore.pyqtSignal(list) dataChanged = QtCore.pyqtSignal(str) fitFinished = QtCore.pyqtSignal(list) stopFit = QtCore.pyqtSignal() @@ -234,9 +234,17 @@ class UpperManagement(QtCore.QObject): for k in plotkeys: self.data[k].graph = gid - @QtCore.pyqtSlot(str) - def plot_from_graph(self, key: str): - self.graphs[self.data[key].graph].remove(key) + @QtCore.pyqtSlot(list) + def plot_from_graph(self, key: list[str]): + sort_graph = {} + for sid in key: + v = self.data[sid].graph + if v not in sort_graph: + sort_graph[v] = [] + sort_graph[v].append(sid) + + for gid, sets in sort_graph.items(): + self.graphs[gid].remove(sets) @QtCore.pyqtSlot(list, str, str) def move_sets(self, sets: list, dest: str, src: (str|list), pos: int = -1):