Move update all logic to from window to view

This commit is contained in:
Roy Nieterau 2022-03-04 11:50:36 +01:00
parent 0cb74b40a3
commit 882a17b04a
2 changed files with 38 additions and 36 deletions

View file

@ -796,3 +796,40 @@ class SceneInventoryView(QtWidgets.QTreeView):
).format(version_str)
dialog.setText(msg)
dialog.exec_()
def update_all(self):
"""Update all items that are currently 'outdated' in the view"""
# Get the source model through the proxy model
model = self.model().sourceModel()
# Get all items from outdated groups
outdated_items = []
for index in iter_model_rows(model,
column=0,
include_root=False):
item = index.data(model.ItemRole)
if not item.get("isGroupNode"):
continue
# Only the group nodes contain the "highest_version" data and as
# such we find only the groups and take its children.
if not model.outdated(item):
continue
# Collect all children which we want to update
children = item.children()
outdated_items.extend(children)
if not outdated_items:
log.info("Nothing to update.")
return
# Trigger update to latest
for item in outdated_items:
try:
api.update(item, -1)
except AssertionError:
self._show_version_error_dialog(None, [item])
log.warning("Update failed", exc_info=True)
self.data_changed.emit()

View file

@ -21,8 +21,6 @@ from .model import (
)
from .view import SceneInventoryView
from ..utils.lib import iter_model_rows
log = logging.getLogger(__name__)
module = sys.modules[__name__]
@ -172,40 +170,7 @@ class SceneInventoryWindow(QtWidgets.QDialog):
)
def _on_update_all(self):
"""Update all items that are currently 'outdated' in the view"""
# Get all items from outdated groups
outdated_items = []
for index in iter_model_rows(self._model,
column=0,
include_root=False):
item = index.data(self._model.ItemRole)
if not item.get("isGroupNode"):
continue
# Only the group nodes contain the "highest_version" data and as
# such we find only the groups and take its children.
if not self._model.outdated(item):
continue
# Collect all children which we want to update
children = item.children()
outdated_items.extend(children)
if not outdated_items:
log.info("Nothing to update.")
return
# Trigger update to latest
# Logic copied from SceneInventoryView._build_item_menu_for_selection
for item in outdated_items:
try:
api.update(item, -1)
except AssertionError:
self._show_version_error_dialog(None, [item])
log.warning("Update failed", exc_info=True)
self._view.data_changed.emit()
self._view.update_all()
def show(root=None, debug=False, parent=None, items=None):