added 3rd view

This commit is contained in:
Jakub Trllo 2025-08-08 16:00:25 +02:00
parent de68250995
commit 4fda90d135
3 changed files with 43 additions and 10 deletions

View file

@ -491,6 +491,7 @@ class InstanceListView(AbstractInstanceView):
self._context_item = None
self._context_widget = None
self._missing_parent_item = None
self._parent_grouping = True
self._convertor_group_item = None
self._convertor_group_widget = None
@ -578,7 +579,8 @@ class InstanceListView(AbstractInstanceView):
instances_by_parent_id[instance.parent_instance_id].append(
instance
)
continue
if self._parent_grouping:
continue
group_label = instance.group_label
group_names.add(group_label)
@ -664,6 +666,9 @@ class InstanceListView(AbstractInstanceView):
new_items[parent_id].append(item)
elif item.parent() is not parent_item:
current_parent = item.parent()
if current_parent is not None:
current_parent.takeRow(item.row())
new_items[parent_id].append(item)
self._parent_id_by_id[instance_id] = parent_id
@ -680,6 +685,9 @@ class InstanceListView(AbstractInstanceView):
item.setData(instance.product_name, SORT_VALUE_ROLE)
item.setData(instance.product_name, GROUP_ROLE)
if not self._parent_grouping:
continue
children = instances_by_parent_id.pop(instance_id, [])
for child in children:
_queue.append((child, item, instance_id))
@ -701,7 +709,7 @@ class InstanceListView(AbstractInstanceView):
# Add items under group item
for parent_id, items in new_items.items():
if parent_id is None:
if parent_id is None or not self._parent_grouping:
parent_item = group_item
else:
parent_item = self._items_by_id[parent_id]
@ -1076,6 +1084,11 @@ class InstanceListView(AbstractInstanceView):
if not instance_ids:
break
def parent_grouping_enabled(self) -> bool:
return self._parent_grouping
def set_parent_grouping(self, parent_grouping: bool) -> None:
self._parent_grouping = parent_grouping
def _on_active_changed(self, changed_instance_id, new_value):
self._toggle_active_state(new_value, changed_instance_id)

View file

@ -411,14 +411,27 @@ class OverviewWidget(QtWidgets.QFrame):
return convertor_identifiers
def _change_view_type(self):
old_view = self._get_current_view()
if (
isinstance(old_view, InstanceListView)
and not old_view.parent_grouping_enabled()
):
self._change_view_btn.set_view_type("card")
old_view.set_parent_grouping(True)
old_view.refresh()
old_view.set_refreshed(True)
return
idx = self._product_views_layout.currentIndex()
new_idx = (idx + 1) % self._product_views_layout.count()
old_view = self._get_current_view()
new_view = self._get_view_by_idx(new_idx)
is_list_view = isinstance(new_view, InstanceListView)
if isinstance(new_view, InstanceListView):
new_view.set_parent_grouping(False)
new_view.refresh()
new_view.set_refreshed(True)
if not new_view.refreshed:
elif not new_view.refreshed:
new_view.refresh()
new_view.set_refreshed(True)
else:
@ -432,7 +445,9 @@ class OverviewWidget(QtWidgets.QFrame):
)
self._change_view_btn.set_view_type(
"card" if is_list_view else "list"
"list"
if isinstance(new_view, InstanceCardView)
else "list-parent-grouping"
)
self._product_views_layout.setCurrentIndex(new_idx)

View file

@ -289,7 +289,7 @@ class RemoveInstanceBtn(PublishIconBtn):
class ChangeViewBtn(IconButton):
"""Create toggle view button."""
"""Toggle views button."""
def __init__(self, parent=None):
super().__init__(parent)
self.set_view_type("list")
@ -297,12 +297,17 @@ class ChangeViewBtn(IconButton):
def set_view_type(self, view_type):
if view_type == "list":
# icon_name = "data_table"
icon_name = "view_agenda"
tooltip = "Change to list view"
else:
icon_name = "dehaze"
tooltip = "Change to list view"
elif view_type == "card":
icon_name = "view_agenda"
tooltip = "Change to card view"
else:
icon_name = "segment"
tooltip = "Change to parent grouping view"
# "format_align_right"
# "segment"
icon = get_qt_icon({
"type": "material-symbols",
"name": icon_name,