Skip to content

Commit

Permalink
Improve groups enable/disable handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
uids6535 committed Sep 7, 2023
1 parent e26d7ab commit b3f93ed
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/asammdf/gui/widgets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,8 @@ def add_new_items(tree, root, items, items_pool):
if info["enabled"]
else QtCore.Qt.Unchecked,
)
if info["disabled"]:
item.set_disabled(info["disabled"])

self.channel_selection.blockSignals(False)
self.channel_selection.refresh()
Expand Down Expand Up @@ -2464,10 +2466,8 @@ def channel_selection_item_double_clicked(self, item, button):
self.channel_selection.setExpandsOnDoubleClick(False)
if item.isDisabled():
item.set_disabled(False)
item.setIcon(item.NameColumn, QtGui.QIcon(":/open.png"))
else:
item.set_disabled(True)
item.setIcon(item.NameColumn, QtGui.QIcon(":/erase.png"))
self.plot.update()
else:
item.setExpanded(not item.isExpanded())
Expand Down
43 changes: 36 additions & 7 deletions src/asammdf/gui/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,28 @@ class Delegate(QtWidgets.QItemDelegate):
def __init__(self, *args):
super().__init__(*args)

def paint(self, pinter, option, index):
def paint(self, painter, option, index):
model = index.model()

item = self.parent().itemFromIndex(index)
brush = model.data(index, QtCore.Qt.ForegroundRole)

# Paint disabled items - hard way
if item and item.type() == item.Channel and item.parent():
for column in range(item.columnCount()):
if item.isDisabled():
item.setForeground(column, QtGui.Qt.darkGray)
else:
item.setForeground(column, item.color)

if brush is not None:
color = brush.color()

complementary = fn.mkColor("#000000")
option.palette.setColor(QtGui.QPalette.Highlight, color)
option.palette.setColor(QtGui.QPalette.HighlightedText, complementary)

super().paint(pinter, option, index)
super().paint(painter, option, index)


class ChannelsTreeFlags(IntFlag):
Expand Down Expand Up @@ -1042,14 +1051,14 @@ def open_menu(self):
# for item in self.selectedItems():
if item.type() == item.Group and item.isDisabled():
item.set_disabled(False)
item.setIcon(item.NameColumn, QtGui.QIcon(":/open.png"))
self.group_activation_changed.emit()

elif action_text == "Deactivate groups":
for item in self.selectedItems():
selectedItems = self.selectedItems()
selectedItems.append(item)
for item in selectedItems:
if item.type() == item.Group and not item.isDisabled():
item.set_disabled(True)
item.setIcon(item.NameColumn, QtGui.QIcon(":/erase.png"))

self.group_activation_changed.emit()

Expand Down Expand Up @@ -1699,6 +1708,9 @@ def __init__(
self.setCheckState(self.NameColumn, QtCore.Qt.Unchecked)
self.name = name.split("\t[")[0]

# Store Previous State (Disabled/Enabled)
self._previous_state = self.isDisabled()

elif type == self.Channel:
self.signal = signal
self.details = None
Expand Down Expand Up @@ -2105,7 +2117,7 @@ def set_conversion(self, conversion):
child = self.child(i)
child.set_conversion(conversion)

def set_disabled(self, disabled):
def set_disabled(self, disabled, preserve_subgroup_state=True):
if self.type() == self.Channel:
self.setDisabled(disabled)
if self.details is not None:
Expand All @@ -2118,12 +2130,29 @@ def set_disabled(self, disabled):
self.signal.enable = enable

elif self.type() == self.Group:
# If the group is subgroup (has a parent)
if self.parent() and not self.parent().isDisabled():
# And the action was triggered on it
if preserve_subgroup_state:
# Save current state
self._previous_state = not self.isDisabled()
# Restore state
elif not disabled:
disabled = self._previous_state

if disabled:
self.setIcon(self.NameColumn, QtGui.QIcon(":/erase.png"))
elif not self.parent() or (
self.parent() and not self.parent().isDisabled()
):
self.setIcon(self.NameColumn, QtGui.QIcon(":/open.png"))

self.setDisabled(disabled)

count = self.childCount()
for i in range(count):
child = self.child(i)
child.set_disabled(disabled)
child.set_disabled(disabled, preserve_subgroup_state=False)

def set_fmt(self, fmt):
if self.kind in "SUV":
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
""" asammdf version module """

__version__ = "7.3.15.dev5"
__version__ = "7.3.15.dev6"

0 comments on commit b3f93ed

Please sign in to comment.