234-value-tooltip #238
@ -49,11 +49,16 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
|
|
||||||
def add_graph(self, idd: str, name: str):
|
def add_graph(self, idd: str, name: str):
|
||||||
item = QtWidgets.QTreeWidgetItem()
|
item = QtWidgets.QTreeWidgetItem()
|
||||||
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsDropEnabled | QtCore.Qt.ItemIsEditable |
|
item.setFlags(
|
||||||
QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable)
|
QtCore.Qt.ItemFlag.ItemIsSelectable |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsDropEnabled |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsEditable |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsEnabled |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsUserCheckable
|
||||||
|
)
|
||||||
item.setText(0, name)
|
item.setText(0, name)
|
||||||
item.setData(0, QtCore.Qt.UserRole, idd)
|
item.setData(0, QtCore.Qt.ItemDataRole.UserRole, idd)
|
||||||
item.setCheckState(0, QtCore.Qt.Checked)
|
item.setCheckState(0, QtCore.Qt.CheckState.Checked)
|
||||||
|
|
||||||
self.addTopLevelItem(item)
|
self.addTopLevelItem(item)
|
||||||
self._checked_graphs.add(idd)
|
self._checked_graphs.add(idd)
|
||||||
@ -67,14 +72,19 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
|
|
||||||
for row in range(self.invisibleRootItem().childCount()):
|
for row in range(self.invisibleRootItem().childCount()):
|
||||||
graph = self.invisibleRootItem().child(row)
|
graph = self.invisibleRootItem().child(row)
|
||||||
if graph.data(0, QtCore.Qt.UserRole) == gid:
|
if graph.data(0, QtCore.Qt.ItemDataRole.UserRole) == gid:
|
||||||
for (idd, name, value) in items:
|
for (idd, name, value) in items:
|
||||||
item = QtWidgets.QTreeWidgetItem([name])
|
item = QtWidgets.QTreeWidgetItem([name])
|
||||||
item.setToolTip(0, f'Value: {value}')
|
item.setToolTip(0, f'Value: {value}')
|
||||||
item.setData(0, QtCore.Qt.UserRole, idd)
|
item.setData(0, QtCore.Qt.ItemDataRole.UserRole, idd)
|
||||||
item.setCheckState(0, QtCore.Qt.Checked)
|
item.setCheckState(0, QtCore.Qt.CheckState.Checked)
|
||||||
item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsEditable |
|
item.setFlags(
|
||||||
QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable)
|
QtCore.Qt.ItemFlag.ItemIsSelectable |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsDragEnabled |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsEditable |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsEnabled |
|
||||||
|
QtCore.Qt.ItemFlag.ItemIsUserCheckable
|
||||||
|
)
|
||||||
graph.addChild(item)
|
graph.addChild(item)
|
||||||
self._checked_sets.add(idd)
|
self._checked_sets.add(idd)
|
||||||
|
|
||||||
@ -85,8 +95,8 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
|
|
||||||
@QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem)
|
@QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem)
|
||||||
def data_change(self, item: QtWidgets.QTreeWidgetItem, emit: bool = True) -> tuple[set, set]:
|
def data_change(self, item: QtWidgets.QTreeWidgetItem, emit: bool = True) -> tuple[set, set]:
|
||||||
idd = item.data(0, QtCore.Qt.UserRole)
|
idd = item.data(0, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
is_selected = item.checkState(0) == QtCore.Qt.Checked
|
is_selected = item.checkState(0) == QtCore.Qt.CheckState.Checked
|
||||||
to_be_hidden = set()
|
to_be_hidden = set()
|
||||||
to_be_shown = set()
|
to_be_shown = set()
|
||||||
|
|
||||||
@ -104,9 +114,9 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
self.blockSignals(True)
|
self.blockSignals(True)
|
||||||
for i in range(item.childCount()):
|
for i in range(item.childCount()):
|
||||||
child = item.child(i)
|
child = item.child(i)
|
||||||
child.setCheckState(0, QtCore.Qt.Checked)
|
child.setCheckState(0, QtCore.Qt.CheckState.Checked)
|
||||||
to_be_shown.add(child.data(0, QtCore.Qt.UserRole))
|
to_be_shown.add(child.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
self._checked_sets.add(child.data(0, QtCore.Qt.UserRole))
|
self._checked_sets.add(child.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
self.blockSignals(False)
|
self.blockSignals(False)
|
||||||
|
|
||||||
# check state change to unchecked
|
# check state change to unchecked
|
||||||
@ -115,10 +125,10 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
self.blockSignals(True)
|
self.blockSignals(True)
|
||||||
for i in range(item.childCount()):
|
for i in range(item.childCount()):
|
||||||
child = item.child(i)
|
child = item.child(i)
|
||||||
child.setCheckState(0, QtCore.Qt.Unchecked)
|
child.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
|
||||||
to_be_hidden.add(child.data(0, QtCore.Qt.UserRole))
|
to_be_hidden.add(child.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
try:
|
try:
|
||||||
self._checked_sets.remove(child.data(0, QtCore.Qt.UserRole))
|
self._checked_sets.remove(child.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
self.blockSignals(False)
|
self.blockSignals(False)
|
||||||
@ -153,7 +163,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
@QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem)
|
@QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem)
|
||||||
def new_selection(self, item: QtWidgets.QTreeWidgetItem):
|
def new_selection(self, item: QtWidgets.QTreeWidgetItem):
|
||||||
if item.parent() is None:
|
if item.parent() is None:
|
||||||
self.management.select_window(item.data(0, QtCore.Qt.UserRole))
|
self.management.select_window(item.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
|
|
||||||
def dropEvent(self, evt: QtGui.QDropEvent):
|
def dropEvent(self, evt: QtGui.QDropEvent):
|
||||||
dropped_index = self.indexAt(evt.pos())
|
dropped_index = self.indexAt(evt.pos())
|
||||||
@ -179,7 +189,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
|
|
||||||
from_parent.removeChild(it)
|
from_parent.removeChild(it)
|
||||||
tobemoved.append(it)
|
tobemoved.append(it)
|
||||||
take_from.append(from_parent.data(0, QtCore.Qt.UserRole))
|
take_from.append(from_parent.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
|
|
||||||
pos = QtCore.QModelIndex(persistent_drop)
|
pos = QtCore.QModelIndex(persistent_drop)
|
||||||
if self.dropIndicatorPosition() == QtWidgets.QAbstractItemView.BelowItem:
|
if self.dropIndicatorPosition() == QtWidgets.QAbstractItemView.BelowItem:
|
||||||
@ -191,8 +201,8 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
else:
|
else:
|
||||||
to_parent.insertChildren(row, tobemoved)
|
to_parent.insertChildren(row, tobemoved)
|
||||||
|
|
||||||
self.management.move_sets([it.data(0, QtCore.Qt.UserRole) for it in tobemoved],
|
self.management.move_sets([it.data(0, QtCore.Qt.ItemDataRole.UserRole) for it in tobemoved],
|
||||||
to_parent.data(0, QtCore.Qt.UserRole), take_from,
|
to_parent.data(0, QtCore.Qt.ItemDataRole.UserRole), take_from,
|
||||||
pos=-1 if append else row)
|
pos=-1 if append else row)
|
||||||
|
|
||||||
self.update_indexes()
|
self.update_indexes()
|
||||||
@ -207,7 +217,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
while iterator.value():
|
while iterator.value():
|
||||||
item = iterator.value()
|
item = iterator.value()
|
||||||
if item is not None:
|
if item is not None:
|
||||||
data = item.data(0, QtCore.Qt.UserRole)
|
data = item.data(0, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
if data == gid_out:
|
if data == gid_out:
|
||||||
from_parent = item
|
from_parent = item
|
||||||
|
|
||||||
@ -231,7 +241,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
self.blockSignals(False)
|
self.blockSignals(False)
|
||||||
|
|
||||||
def sort(self, graph_item: QtWidgets.QTreeWidgetItem, mode: str = 'value'):
|
def sort(self, graph_item: QtWidgets.QTreeWidgetItem, mode: str = 'value'):
|
||||||
graph_id = graph_item.data(0, QtCore.Qt.UserRole)
|
graph_id = graph_item.data(0, QtCore.Qt.ItemDataRole.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])]
|
sets = [el[0] for el in sorted(sets.items(), key=lambda x: x[1])]
|
||||||
|
|
||||||
@ -243,7 +253,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
|
|
||||||
for s in sets:
|
for s in sets:
|
||||||
for c in children:
|
for c in children:
|
||||||
if c.data(0, QtCore.Qt.UserRole) == s:
|
if c.data(0, QtCore.Qt.ItemDataRole.UserRole) == s:
|
||||||
graph_item.addChild(c)
|
graph_item.addChild(c)
|
||||||
|
|
||||||
self.update_indexes()
|
self.update_indexes()
|
||||||
@ -276,7 +286,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
while iterator.value():
|
while iterator.value():
|
||||||
item = iterator.value()
|
item = iterator.value()
|
||||||
if item is not None:
|
if item is not None:
|
||||||
data = item.data(0, QtCore.Qt.UserRole)
|
data = item.data(0, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
if data == sid:
|
if data == sid:
|
||||||
if name != item.text(0):
|
if name != item.text(0):
|
||||||
item.setText(0, name)
|
item.setText(0, name)
|
||||||
@ -285,7 +295,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
iterator += 1
|
iterator += 1
|
||||||
|
|
||||||
def keyPressEvent(self, evt: QtGui.QKeyEvent):
|
def keyPressEvent(self, evt: QtGui.QKeyEvent):
|
||||||
if evt.key() == QtCore.Qt.Key_Delete:
|
if evt.key() == QtCore.Qt.Key.Key_Delete:
|
||||||
rm_sets = []
|
rm_sets = []
|
||||||
rm_graphs = []
|
rm_graphs = []
|
||||||
for idx in self.selectedIndexes():
|
for idx in self.selectedIndexes():
|
||||||
@ -296,20 +306,20 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
if item.parent() is None:
|
if item.parent() is None:
|
||||||
for c_i in range(item.childCount()):
|
for c_i in range(item.childCount()):
|
||||||
# add sets inside graph to removal
|
# add sets inside graph to removal
|
||||||
child_data = item.child(c_i).data(0, QtCore.Qt.UserRole)
|
child_data = item.child(c_i).data(0, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
if child_data not in rm_sets:
|
if child_data not in rm_sets:
|
||||||
rm_sets.append(child_data)
|
rm_sets.append(child_data)
|
||||||
rm_graphs.append(item.data(0, QtCore.Qt.UserRole))
|
rm_graphs.append(item.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
item_data = item.data(0, QtCore.Qt.UserRole)
|
item_data = item.data(0, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
if item_data not in rm_sets:
|
if item_data not in rm_sets:
|
||||||
rm_sets.append(item_data)
|
rm_sets.append(item_data)
|
||||||
|
|
||||||
# self.deleteItem.emit(rm_sets+rm_graphs)
|
# self.deleteItem.emit(rm_sets+rm_graphs)
|
||||||
self.management.delete_sets(rm_sets+rm_graphs)
|
self.management.delete_sets(rm_sets+rm_graphs)
|
||||||
|
|
||||||
elif evt.key() == QtCore.Qt.Key_Space:
|
elif evt.key() == QtCore.Qt.Key.Key_Space:
|
||||||
sets = []
|
sets = []
|
||||||
from_parent = []
|
from_parent = []
|
||||||
|
|
||||||
@ -329,7 +339,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
for it in sets:
|
for it in sets:
|
||||||
if it in from_parent:
|
if it in from_parent:
|
||||||
continue
|
continue
|
||||||
it.setCheckState(0, QtCore.Qt.Unchecked if it.checkState(0) == QtCore.Qt.Checked else QtCore.Qt.Checked)
|
it.setCheckState(0, QtCore.Qt.CheckState.Unchecked if it.checkState(0) == QtCore.Qt.CheckState.Checked else QtCore.Qt.CheckState.Checked)
|
||||||
s1, s2 = self.data_change(it, emit=False)
|
s1, s2 = self.data_change(it, emit=False)
|
||||||
to_be_hidden |= s2
|
to_be_hidden |= s2
|
||||||
to_be_shown |= s1
|
to_be_shown |= s1
|
||||||
@ -353,7 +363,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
# find all items that have to be removed
|
# find all items that have to be removed
|
||||||
while iterator.value():
|
while iterator.value():
|
||||||
item = iterator.value()
|
item = iterator.value()
|
||||||
_id = item.data(0, QtCore.Qt.UserRole)
|
_id = item.data(0, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
if _id in ids:
|
if _id in ids:
|
||||||
try:
|
try:
|
||||||
item_parent = item.parent()
|
item_parent = item.parent()
|
||||||
@ -431,7 +441,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
if i.column() == 0:
|
if i.column() == 0:
|
||||||
continue
|
continue
|
||||||
items.append(self.itemFromIndex(i))
|
items.append(self.itemFromIndex(i))
|
||||||
graphs.append(self.itemFromIndex(i).data(0, QtCore.Qt.UserRole))
|
graphs.append(self.itemFromIndex(i).data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
|
|
||||||
if action == del_action:
|
if action == del_action:
|
||||||
for gid in graphs:
|
for gid in graphs:
|
||||||
@ -473,12 +483,12 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
graph_id = parent.data(0, QtCore.Qt.UserRole)
|
graph_id = parent.data(0, QtCore.Qt.ItemDataRole.UserRole)
|
||||||
if graph_id not in idx:
|
if graph_id not in idx:
|
||||||
idx[graph_id] = []
|
idx[graph_id] = []
|
||||||
# collect sets in their graph
|
# collect sets in their graph
|
||||||
idx[graph_id].append(item.data(0, QtCore.Qt.UserRole))
|
idx[graph_id].append(item.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
data = self.management[item.data(0, QtCore.Qt.UserRole)]
|
data = self.management[item.data(0, QtCore.Qt.ItemDataRole.UserRole)]
|
||||||
if data.mode == 'fit':
|
if data.mode == 'fit':
|
||||||
has_fits = True
|
has_fits = True
|
||||||
|
|
||||||
@ -523,7 +533,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
while iterator.value():
|
while iterator.value():
|
||||||
item = iterator.value()
|
item = iterator.value()
|
||||||
if item is not None:
|
if item is not None:
|
||||||
if item.data(0, QtCore.Qt.UserRole) == gid:
|
if item.data(0, QtCore.Qt.ItemDataRole.UserRole) == gid:
|
||||||
item.setBackground(0, QtGui.QBrush(QtGui.QColor('gray')))
|
item.setBackground(0, QtGui.QBrush(QtGui.QColor('gray')))
|
||||||
else:
|
else:
|
||||||
item.setBackground(0, QtGui.QBrush())
|
item.setBackground(0, QtGui.QBrush())
|
||||||
@ -536,10 +546,10 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
while iterator.value():
|
while iterator.value():
|
||||||
item = iterator.value()
|
item = iterator.value()
|
||||||
if item is not None:
|
if item is not None:
|
||||||
if item.data(0, QtCore.Qt.UserRole) in sets:
|
if item.data(0, QtCore.Qt.ItemDataRole.UserRole) in sets:
|
||||||
item.setCheckState(0, QtCore.Qt.Unchecked)
|
item.setCheckState(0, QtCore.Qt.CheckState.Unchecked)
|
||||||
else:
|
else:
|
||||||
self._checked_sets.add(item.data(0, QtCore.Qt.UserRole))
|
self._checked_sets.add(item.data(0, QtCore.Qt.ItemDataRole.UserRole))
|
||||||
iterator += 1
|
iterator += 1
|
||||||
self.blockSignals(False)
|
self.blockSignals(False)
|
||||||
|
|
||||||
@ -594,7 +604,7 @@ class DataWidget(QtWidgets.QWidget, Ui_DataWidget):
|
|||||||
sid = []
|
sid = []
|
||||||
for i in self.tree.selectedIndexes():
|
for i in self.tree.selectedIndexes():
|
||||||
if i.column() == 0:
|
if i.column() == 0:
|
||||||
sid.append(i.data(role=QtCore.Qt.UserRole))
|
sid.append(i.data(role=QtCore.Qt.ItemDataRole.UserRole))
|
||||||
|
|
||||||
self.startShowProperty.emit(sid)
|
self.startShowProperty.emit(sid)
|
||||||
|
|
||||||
@ -603,7 +613,7 @@ class DataWidget(QtWidgets.QWidget, Ui_DataWidget):
|
|||||||
self.proptable.populate(props)
|
self.proptable.populate(props)
|
||||||
|
|
||||||
def change_property(self, key1, key2, value):
|
def change_property(self, key1, key2, value):
|
||||||
ids = [item.data(0, QtCore.Qt.UserRole) for item in self.tree.selectedItems()]
|
ids = [item.data(0, QtCore.Qt.ItemDataRole.UserRole) for item in self.tree.selectedItems()]
|
||||||
if key2 == 'Value':
|
if key2 == 'Value':
|
||||||
try:
|
try:
|
||||||
value = float(value)
|
value = float(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user