Skip to content

Commit

Permalink
Fix remaking Groups when UI mode changes
Browse files Browse the repository at this point in the history
- Links in Groups must be readded to the Group because all link
instances are destroyed when UI mode changes
  • Loading branch information
ptsavol committed Nov 28, 2024
1 parent f824660 commit b11ff60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
22 changes: 22 additions & 0 deletions spinetoolbox/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def item_names(self):
def project_items(self):
return [item for item in self.items if isinstance(item, ProjectItemIcon)]

@property
def links(self):
return [item for item in self.items if not isinstance(item, ProjectItemIcon)]

@property
def n_items(self):
return len(self._items)
Expand Down Expand Up @@ -154,6 +158,23 @@ def remove_item(self, name):
item.my_groups.remove(self)
self.update_group_rect()

def refresh_links(self):
"""Removes all links and jumps from this group and add them back.
This is needed when UI mode is changed because all link and jump instances
are destroyed when UI mode changes.
"""
link_names = [l.name for l in self.links]
print(f"links to refresh:{link_names}")
for link in link_names:
self._items.pop(link)
for connection in self._toolbox.project.connections:
if connection.name in link_names:
self.add_item(connection.name)
for jump in self._toolbox.project.jumps:
if jump.name in link_names:
self.add_item(jump.name)

@Slot(bool)
def call_disband_group(self, _=False):
self._toolbox.toolboxuibase.active_ui_window.ui.graphicsView.push_disband_group_command(self.name)
Expand Down Expand Up @@ -277,6 +298,7 @@ def notify_item_move(self):

def contextMenuEvent(self, event):
"""Opens context-menu in design mode."""
print(f"{self.name}: {self.item_names}")
if self._toolbox.active_ui_mode == "toolboxuilite":
event.ignore() # Send context-menu request to graphics view
return
Expand Down
3 changes: 1 addition & 2 deletions spinetoolbox/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,6 @@ def show_project_or_item_context_menu(self, pos, item):
pos (QPoint): Mouse position
item (ProjectItem, Group, optional): Project item, Group or None
"""
if item is not None:
print(f"item my_groups:{item.get_icon().my_groups}")
menu = QMenu(self)
menu.setToolTipsVisible(True)
menu.aboutToShow.connect(self.refresh_edit_action_states)
Expand Down Expand Up @@ -1670,6 +1668,7 @@ def show_project_or_item_context_menu(self, pos, item):
menu.addSeparator()
menu.addAction(self.ui.actionRename_item)
if len(item.get_icon().my_groups) > 0:
print(f"item my_groups:{item.get_icon().my_groups}")
menu.addSeparator()
for group in item.get_icon().my_groups:
text = f"Leave {group.name}"
Expand Down
9 changes: 1 addition & 8 deletions spinetoolbox/ui_main_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,8 @@ def reload_icons_and_links(self):
self.active_ui_window.ui.graphicsView.do_add_jump(jump)
jump.jump_link.update_icons()
for group in self.project.groups.values():
group.refresh_links()
self.active_ui_window.ui.graphicsView.add_group_on_scene(group)
# TODO:
# Remove all links from Groups. items contains wrong link icon references
# Then find the new links from the scene and add them back to the group and to the links my_groups
# ex_items = [for item in]
# for item in group.items:
# if isinstance(item, JumpOrLink):
# print(item.name)
# item.my_groups.add(group)

def connect_project_signals(self):
"""Connects project signals based on current UI mode."""
Expand Down

0 comments on commit b11ff60

Please sign in to comment.