1
0
forked from IPKM/nmreval
closes #123

Co-authored-by: Dominik Demuth <dominik.demuth@physik.tu-darmstadt.de>
Reviewed-on: IPKM/nmreval#192
This commit is contained in:
Dominik Demuth 2023-12-28 16:58:37 +00:00
parent 694d47267d
commit 24bba43b40
3 changed files with 27 additions and 6 deletions

View File

@ -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())

View File

@ -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])

View File

@ -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()