Skip to content

Commit

Permalink
Fix Copy Display Properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tov101 committed Oct 10, 2023
1 parent 12209cb commit 6f2aaf8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/asammdf/gui/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,19 @@ def keyPressEvent(self, event):
self.plot.plot.update()

elif modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) and key == QtCore.Qt.Key_C:
selected_items = [item for item in self.selectedItems() if item.type() == ChannelsTreeItem.Channel]
if not selected_items:
return
else:
clipboard_text = None
selected_items = [
item
for item in self.selectedItems()
if item.type() in (ChannelsTreeItem.Channel, ChannelsTreeItem.Group)
]
if selected_items:
item = selected_items[0]
QtWidgets.QApplication.instance().clipboard().setText(item.get_display_properties())
if item.type() == ChannelsTreeItem.Group:
item = item.child(0)
if item:
clipboard_text = item.get_display_properties()
QtWidgets.QApplication.instance().clipboard().setText(clipboard_text)

elif modifiers == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier) and key == QtCore.Qt.Key_V:
info = QtWidgets.QApplication.instance().clipboard().text()
Expand Down
10 changes: 10 additions & 0 deletions test/asammdf/gui/widgets/test_PlotWidget_ContextMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ def test_Action_PasteDisplayProperties_Group(self):
self.context_menu(action_text=action_copy, position=position_src)

channel_a_properties = QtWidgets.QApplication.instance().clipboard().text()
channel_a_properties = json.loads(channel_a_properties)
del channel_a_properties["y_range"]

# Paste
position_dst = self.plot.channel_selection.visualItemRect(group_channel_a).center()
Expand All @@ -388,6 +390,8 @@ def test_Action_PasteDisplayProperties_Group(self):
self.context_menu(action_text=action_copy, position=position_src)

group_channel_properties = QtWidgets.QApplication.instance().clipboard().text()
group_channel_properties = json.loads(group_channel_properties)
del group_channel_properties["y_range"]

# Evaluate
self.assertEqual(channel_a_properties, group_channel_properties)
Expand All @@ -410,6 +414,8 @@ def test_Action_PasteDisplayProperties_Group(self):
self.context_menu(action_text=action_copy, position=position_src)

channel_c_properties = QtWidgets.QApplication.instance().clipboard().text()
channel_c_properties = json.loads(channel_c_properties)
del channel_c_properties["y_range"]

# Evaluate
self.assertEqual(channel_c_properties, group_channel_properties)
Expand All @@ -420,6 +426,8 @@ def test_Action_PasteDisplayProperties_Group(self):
position_src = self.plot.channel_selection.visualItemRect(group_channel_b).center()
self.context_menu(action_text=action_copy, position=position_src)
group_channel_b_properties = QtWidgets.QApplication.instance().clipboard().text()
group_channel_b_properties = json.loads(group_channel_b_properties)
del group_channel_b_properties["y_range"]

# Paste
position_dst = self.plot.channel_selection.visualItemRect(group_channel_a).center()
Expand All @@ -430,6 +438,8 @@ def test_Action_PasteDisplayProperties_Group(self):
self.context_menu(action_text=action_copy, position=position_src)

group_channel_a_properties = QtWidgets.QApplication.instance().clipboard().text()
group_channel_a_properties = json.loads(group_channel_a_properties)
del group_channel_a_properties["y_range"]

# Evaluate
self.assertEqual(group_channel_a_properties, group_channel_b_properties)
Expand Down

0 comments on commit 6f2aaf8

Please sign in to comment.