diff --git a/openpype/tools/utils/models.py b/openpype/tools/utils/models.py index d09d16d898..c5e1ce1b12 100644 --- a/openpype/tools/utils/models.py +++ b/openpype/tools/utils/models.py @@ -195,132 +195,6 @@ class Item(dict): self._children.append(child) -class TasksModel(TreeModel): - """A model listing the tasks combined for a list of assets""" - - Columns = ["name", "count"] - - def __init__(self, dbcon, parent=None): - super(TasksModel, self).__init__(parent=parent) - self.dbcon = dbcon - self._num_assets = 0 - self._icons = { - "__default__": qtawesome.icon( - "fa.male", - color=style.colors.default - ), - "__no_task__": qtawesome.icon( - "fa.exclamation-circle", - color=style.colors.mid - ) - } - - self._refresh_task_icons() - - def _refresh_task_icons(self): - # Get the project configured icons from database - project = self.dbcon.find_one({"type": "project"}, {"config.tasks"}) - tasks = project["config"].get("tasks", {}) - for task_name, task in tasks.items(): - icon_name = task.get("icon", None) - if icon_name: - icon = qtawesome.icon( - "fa.{}".format(icon_name), - color=style.colors.default - ) - self._icons[task_name] = icon - - def set_assets(self, asset_ids=None, asset_docs=None): - """Set assets to track by their database id - - Arguments: - asset_ids (list): List of asset ids. - asset_docs (list): List of asset entities from MongoDB. - - """ - - if asset_docs is None and asset_ids is not None: - # prepare filter query - _filter = {"type": "asset", "_id": {"$in": asset_ids}} - _projection = {"data.tasks"} - - # find assets in db by query - asset_docs = list(self.dbcon.find(_filter, _projection)) - db_assets_ids = [asset["_id"] for asset in asset_docs] - - # check if all assets were found - not_found = [ - str(a_id) for a_id in asset_ids if a_id not in db_assets_ids - ] - - assert not not_found, "Assets not found by id: {0}".format( - ", ".join(not_found) - ) - - if asset_docs is None: - asset_docs = list() - - self._num_assets = len(asset_docs) - - tasks = collections.Counter() - for asset_doc in asset_docs: - asset_tasks = asset_doc.get("data", {}).get("tasks", {}) - tasks.update(asset_tasks.keys()) - - self.clear() - self.beginResetModel() - - default_icon = self._icons["__default__"] - - if not tasks: - no_task_icon = self._icons["__no_task__"] - item = Item({ - "name": "No task", - "count": 0, - "icon": no_task_icon, - "enabled": False, - }) - - self.add_child(item) - - else: - for task, count in sorted(tasks.items()): - icon = self._icons.get(task, default_icon) - - item = Item({ - "name": task, - "count": count, - "icon": icon - }) - - self.add_child(item) - - self.endResetModel() - - def headerData(self, section, orientation, role): - # Override header for count column to show amount of assets - # it is listing the tasks for - if role == QtCore.Qt.DisplayRole: - if orientation == QtCore.Qt.Horizontal: - if section == 0: - return "Tasks" - elif section == 1: # count column - return "count ({0})".format(self._num_assets) - - return super(TasksModel, self).headerData(section, orientation, role) - - def data(self, index, role): - if not index.isValid(): - return - - # Add icon to the first column - if role == QtCore.Qt.DecorationRole: - if index.column() == 0: - return index.internalPointer()["icon"] - - return super(TasksModel, self).data(index, role) - - class AssetModel(TreeModel): """A model listing assets in the silo in the active project.