Skip to content

Commit

Permalink
Group right hand side by order range (e.g. Collector) instead or orde…
Browse files Browse the repository at this point in the history
…r float numbers. (experimental)
  • Loading branch information
BigRoy committed Aug 18, 2016
1 parent e613c83 commit c478ed3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
68 changes: 59 additions & 9 deletions pyblish_lite/tree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import pyblish

from .vendor import Qt
from Qt import QtWidgets, QtCore
from itertools import groupby
Expand Down Expand Up @@ -88,6 +90,35 @@ def __init__(self):
def set_group_role(self, role):
self.group_role = role

def groupby_key(self, source_index):
"""Returns the data to group by.
Override this in subclasses to group by customized data instead of
by simply the currently set group role.
Args:
source_index (QtCore.QModelIndex): index from source to retrieve
data from to group by.
Returns:
object: Collected data to group by for index.
"""
return source_index.data(self.group_role)

def groupby_label(self, section):
"""Returns the label for a section based on the collected group key.
Override this in subclasses to format the name for a specific key.
Args:
section: key value for this group section
Returns:
str: Label of the section header based on group key
"""
return section

def rebuild(self):
"""Update proxy sections and items
Expand All @@ -105,14 +136,12 @@ def rebuild(self):
source_rows = source.rowCount()
source_indices = [source.index(i, 0) for i in range(source_rows)]

def key_getter(source_index):
"""Return group role data for source index"""
return source.data(source_index, self.group_role)

for section, group in groupby(source_indices, key=key_getter):
for section, group in groupby(source_indices,
key=self.groupby_key):

# section
section_item = ProxySectionItem(section)
label = self.groupby_label(section)
section_item = ProxySectionItem(label)
self.root.addChild(section_item)

# items in section
Expand Down Expand Up @@ -209,6 +238,29 @@ def parent(self, index):
return self.createIndex(row, 0, parent)


class PluginOrderGroupProxy(Proxy):
"""Proxy grouping by order by full range known.
Before Collectors and after Integrators will be grouped as "Other".
"""

def groupby_key(self, source_index):
plugin_order = super(PluginOrderGroupProxy,
self).groupby_key(source_index)
label = "Other"

mapping = {pyblish.plugin.CollectorOrder: "Collector",
pyblish.plugin.ValidatorOrder: "Validator",
pyblish.plugin.ExtractorOrder: "Extractor",
pyblish.plugin.IntegratorOrder: "Integrator"}
for order, _type in mapping.items():
if pyblish.lib.inrange(plugin_order, base=order):
label = _type

return label


class View(QtWidgets.QTreeView):
# An item is requesting to be toggled, with optional forced-state
toggled = QtCore.Signal("QModelIndex", object)
Expand All @@ -223,12 +275,10 @@ def __init__(self, parent=None):
self.viewport().setAttribute(QtCore.Qt.WA_Hover, True)
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
#self.setResizeMode(QtWidgets.QTreeView.Adjust)
self.setVerticalScrollMode(QtWidgets.QTreeView.ScrollPerPixel)
self.setHeaderHidden(True)
self.setRootIsDecorated(False)
self.setIndentation(10)
#self.setItemsExpandable(False)
self.setIndentation(40) # TODO: Set to 0 when styling is better

def event(self, event):
if not event.type() == QtCore.QEvent.KeyPress:
Expand Down
2 changes: 1 addition & 1 deletion pyblish_lite/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def __init__(self, controller, parent=None):
left_proxy.set_group_role(model.Families)
left_view.setModel(left_proxy)

right_proxy = tree.Proxy()
right_proxy = tree.PluginOrderGroupProxy()
right_proxy.setSourceModel(plugin_model)
right_proxy.set_group_role(model.Order)
right_view.setModel(right_proxy)
Expand Down

0 comments on commit c478ed3

Please sign in to comment.