mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
TaskModel transfered to Task temaplates model so it only shows task names
This commit is contained in:
parent
08307642cc
commit
8ea75c4a7f
1 changed files with 13 additions and 57 deletions
|
|
@ -182,33 +182,19 @@ class TreeModel(QtCore.QAbstractItemModel):
|
|||
self.endResetModel()
|
||||
|
||||
|
||||
class TasksModel(TreeModel):
|
||||
class TasksTemplateModel(TreeModel):
|
||||
"""A model listing the tasks combined for a list of assets"""
|
||||
|
||||
COLUMNS = ["name", "count"]
|
||||
COLUMNS = ["Tasks"]
|
||||
|
||||
def __init__(self):
|
||||
super(TasksModel, self).__init__()
|
||||
self._num_assets = 0
|
||||
super(TasksTemplateModel, self).__init__()
|
||||
self._icons = {
|
||||
"__default__": awesome.icon("fa.folder-o",
|
||||
color=style.colors.default)
|
||||
}
|
||||
|
||||
self._get_task_icons()
|
||||
|
||||
def _get_task_icons(self):
|
||||
# Get the project configured icons from database
|
||||
project = io.find_one({"type": "project"})
|
||||
tasks = project['config'].get('tasks', [])
|
||||
for task in tasks:
|
||||
icon_name = task.get("icon", None)
|
||||
if icon_name:
|
||||
icon = awesome.icon("fa.{}".format(icon_name),
|
||||
color=style.colors.default)
|
||||
self._icons[task["name"]] = icon
|
||||
|
||||
def set_assets(self, asset_ids):
|
||||
def set_tasks(self, tasks):
|
||||
"""Set assets to track by their database id
|
||||
|
||||
Arguments:
|
||||
|
|
@ -216,42 +202,18 @@ class TasksModel(TreeModel):
|
|||
|
||||
"""
|
||||
|
||||
assets = list()
|
||||
for asset_id in asset_ids:
|
||||
asset = io.find_one({"_id": asset_id, "type": "asset"})
|
||||
assert asset, "Asset not found by id: {0}".format(asset_id)
|
||||
assets.append(asset)
|
||||
|
||||
self._num_assets = len(assets)
|
||||
|
||||
tasks = collections.Counter()
|
||||
for asset in assets:
|
||||
asset_tasks = asset.get("data", {}).get("tasks", [])
|
||||
tasks.update(asset_tasks)
|
||||
|
||||
# If no asset tasks are defined, use the project tasks.
|
||||
if assets and not tasks:
|
||||
project = io.find_one({"type": "project"})
|
||||
tasks.update(
|
||||
[task["name"] for task in project["config"].get("tasks", [])]
|
||||
)
|
||||
|
||||
self.clear()
|
||||
# delete empty strings from tasks
|
||||
del tasks[""]
|
||||
|
||||
# let cleared task view if no tasks are available
|
||||
if len(tasks) == 0:
|
||||
return
|
||||
|
||||
self.beginResetModel()
|
||||
|
||||
default_icon = self._icons["__default__"]
|
||||
for task, count in sorted(tasks.items()):
|
||||
icon = self._icons.get(task, default_icon)
|
||||
|
||||
icon = self._icons["__default__"]
|
||||
for task in tasks:
|
||||
node = Node({
|
||||
"name": task,
|
||||
"count": count,
|
||||
"Tasks": task,
|
||||
"icon": icon
|
||||
})
|
||||
|
||||
|
|
@ -259,16 +221,10 @@ class TasksModel(TreeModel):
|
|||
|
||||
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 == 1: # count column
|
||||
return "count ({0})".format(self._num_assets)
|
||||
|
||||
return super(TasksModel, self).headerData(section, orientation, role)
|
||||
def flags(self, index):
|
||||
return (
|
||||
QtCore.Qt.ItemIsEnabled
|
||||
)
|
||||
|
||||
def data(self, index, role):
|
||||
|
||||
|
|
@ -280,7 +236,7 @@ class TasksModel(TreeModel):
|
|||
if index.column() == 0:
|
||||
return index.internalPointer()['icon']
|
||||
|
||||
return super(TasksModel, self).data(index, role)
|
||||
return super(TasksTemplateModel, self).data(index, role)
|
||||
|
||||
|
||||
class DeselectableTreeView(QtWidgets.QTreeView):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue