From 3b79c571fb70b9d84ca3b6e3c3f1de3e71947cb1 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sun, 9 Apr 2023 20:20:37 +0200 Subject: [PATCH] eval expression reuses ListWidgetItems of datasets; closes #31 --- src/gui_qt/main/mainwindow.py | 1 - src/gui_qt/math/evaluation.py | 35 +++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index 10420ca..77bc0c2 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -944,7 +944,6 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): def extend_fit(self, sets: list): w = FitExtension(self) res = w.exec() - print(res) if res: p = w.values x = linspace(p[0], p[1], num=p[2]) diff --git a/src/gui_qt/math/evaluation.py b/src/gui_qt/math/evaluation.py index 617e5f9..c74bf14 100644 --- a/src/gui_qt/math/evaluation.py +++ b/src/gui_qt/math/evaluation.py @@ -31,13 +31,36 @@ class QEvalDialog(QtWidgets.QDialog, Ui_CalcDialog): self.namespace_widget.set_namespace(self.namespace) def add_data(self, data): - self.listWidget.clear() + # self.listWidget.clear() + tmp = [] + while self.listWidget.count(): + tmp.append(self.listWidget.takeItem(0)) + for set_id, name in data: - item = QtWidgets.QListWidgetItem(name) - item.setData(QtCore.Qt.UserRole, set_id) - item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable) - item.setCheckState(QtCore.Qt.Checked) - self.listWidget.addItem(item) + + # search if set was used before + new_one = True + for i in range(len(tmp)): + w = tmp[i] + if w.data(QtCore.Qt.UserRole) == set_id: + + self.listWidget.addItem(w) + tmp.pop(i) + new_one = False + break + + # new set, create item + if new_one: + item = QtWidgets.QListWidgetItem(name) + item.setData(QtCore.Qt.UserRole, set_id) + item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable) + item.setCheckState(QtCore.Qt.Checked) + self.listWidget.addItem(item) + + while len(tmp): + # delete remaining ListWidgetItems + w = tmp.pop() + w.deleteLater() def set_graphs(self, graphs: list): self.graph_comboBox.clear()