From 24bba43b40ccf225d297402e036704654fdf4348 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 28 Dec 2023 16:58:37 +0000 Subject: [PATCH] bugfixes (#192) closes #123 Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/192 --- src/gui_qt/data/datawidget/datawidget.py | 5 +++++ src/gui_qt/graphs/graphwindow.py | 2 +- src/gui_qt/main/management.py | 26 +++++++++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/gui_qt/data/datawidget/datawidget.py b/src/gui_qt/data/datawidget/datawidget.py index 25ad729..34c19d9 100644 --- a/src/gui_qt/data/datawidget/datawidget.py +++ b/src/gui_qt/data/datawidget/datawidget.py @@ -410,6 +410,7 @@ class DataTree(QtWidgets.QTreeWidget): self.ctx_sets(evt, menu) def ctx_graphs(self, evt, menu): + copy_action = menu.addAction('Replicate graph!') del_action = menu.addAction('Exterminate graph!') sort_menu = menu.addMenu('Sort sets') @@ -436,6 +437,10 @@ class DataTree(QtWidgets.QTreeWidget): for gid in graphs: self.management.delete_graph(gid) + elif action == copy_action: + for gid in graphs: + self.management.copy_graph(gid) + elif action.parent() == col_menu: for gid in graphs: self.management.set_cycle(self.management.graphs[gid].sets, action.text()) diff --git a/src/gui_qt/graphs/graphwindow.py b/src/gui_qt/graphs/graphwindow.py index 6179aeb..2d8c67f 100644 --- a/src/gui_qt/graphs/graphwindow.py +++ b/src/gui_qt/graphs/graphwindow.py @@ -781,7 +781,7 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow): graph.graphic.showGrid(x=state['grid'], y=state['grid']) - graph.checkBox.setCheckState(QtCore.Qt.Checked if state['legend'] else QtCore.Qt.Unchecked) + graph.checkBox.setCheckState(QtCore.Qt.CheckState.Checked if state['legend'] else QtCore.Qt.CheckState.Unchecked) graph.real_button.setChecked(state['plots'][0]) graph.imag_button.setChecked(state['plots'][1]) diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 4b8b25c..3185b30 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -279,13 +279,16 @@ class UpperManagement(QtCore.QObject): @QtCore.pyqtSlot() @QtCore.pyqtSlot(list, str) - def copy_sets(self, sets: list = None, src: str = None): - if sets is None: - sets = self.graphs[self.current_graph].active[:] - + def copy_sets(self, sets: list = None, src: str = None, dest: str = None): if src is None: src = self.current_graph + if sets is None: + sets = self.graphs[src].active[:] + + if dest is None: + dest = src + new_ids = [] for s in sets: copy_of_s = self.data[s].copy(full=True) @@ -293,10 +296,23 @@ class UpperManagement(QtCore.QObject): new_ids.append(copy_of_s.id) self.data[copy_of_s.id] = copy_of_s - self.newData.emit(new_ids, src) + self.newData.emit(new_ids, dest) return new_ids + def copy_graph(self, gid): + # Use state of old graph but removes actual references to old graph + src_state = self.graphs[gid].get_state() + src_state.pop('id') + src_state['children'] = [] + src_state['active'] = [] + + new_graph = QGraphWindow.set_state(src_state) + self.graphs[new_graph.id] = new_graph + self.restoreGraph.emit(new_graph.id) + + self.copy_sets(src=gid, dest=new_graph.id) + @QtCore.pyqtSlot(list) @QtCore.pyqtSlot(str) @QtCore.pyqtSlot()