1
0
forked from IPKM/nmreval

UpperManagement.deleteDate emits list of sets, indexes in datawidget are now only updated once

This commit is contained in:
Dominik Demuth 2023-04-15 15:40:49 +02:00
parent e41c42d573
commit bd8a4f16ea
4 changed files with 25 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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