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