change view on too much instances

This commit is contained in:
Jakub Trllo 2025-08-08 13:56:30 +02:00
parent c800e35f3f
commit e07b11b7fa
2 changed files with 16 additions and 0 deletions

View file

@ -548,6 +548,10 @@ class InstanceCardView(AbstractInstanceView):
result.setWidth(width)
return result
def get_current_instance_count(self) -> int:
"""How many instances are currently in the view."""
return len(self._widgets_by_id)
def _toggle_instances(
self,
new_value: Optional[bool],

View file

@ -513,7 +513,19 @@ class OverviewWidget(QtWidgets.QFrame):
self._refresh_instances()
def _on_instances_added(self):
view = self._get_current_view()
is_card_view = False
count = 0
if isinstance(view, InstanceCardView):
is_card_view = True
count = view.get_current_instance_count()
self._refresh_instances()
if is_card_view and count < 10:
new_count = view.get_current_instance_count()
if new_count > count and new_count >= 10:
self._change_view_type()
def _on_instances_removed(self):
self._refresh_instances()