Skip to content

Commit

Permalink
Add "Enable Grouping" checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlatwe committed Jul 8, 2019
1 parent 66f678c commit c8a0468
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
4 changes: 4 additions & 0 deletions avalon/tools/cbloader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ def keyPressEvent(self, event):

def show_grouping_dialog(self):
subsets = self.data["model"]["subsets"]
if not subsets.is_groupable():
self.echo("Grouping not enabled.")
return

selected = subsets.selected_subsets()
if not selected:
self.echo("No selected subset.")
Expand Down
25 changes: 16 additions & 9 deletions avalon/tools/cbloader/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ class SubsetsModel(TreeModel):
SortAscendingRole = QtCore.Qt.UserRole + 2
sortDescendingRole = QtCore.Qt.UserRole + 3

def __init__(self, parent=None):
def __init__(self, grouping=True, parent=None):
super(SubsetsModel, self).__init__(parent=parent)
self._asset_id = None
self._sorter = None
self._grouping = grouping
self._icons = {"subset": qta.icon("fa.file-o",
color=style.colors.default)}

def set_asset(self, asset_id):
self._asset_id = asset_id
self.refresh()

def set_grouping(self, state):
self._grouping = state
self.refresh()

def setData(self, index, value, role=QtCore.Qt.EditRole):

# Trigger additional edit when `version` column changed
Expand Down Expand Up @@ -114,14 +119,16 @@ def refresh(self):

# Generate subset group nodes
group_nodes = dict()
for data in active_groups:
name = data.pop("name")
group = Node()
group.update({"subset": name, "isGroup": True, "childRow": 0})
group.update(data)

group_nodes[name] = group
self.add_child(group)
if self._grouping:
for data in active_groups:
name = data.pop("name")
group = Node()
group.update({"subset": name, "isGroup": True, "childRow": 0})
group.update(data)

group_nodes[name] = group
self.add_child(group)

filter = {"type": "subset", "parent": asset_id}

Expand All @@ -140,7 +147,7 @@ def refresh(self):
data["subset"] = data["name"]

group_name = subset["data"].get("subsetGroup")
if group_name:
if self._grouping and group_name:
group = group_nodes[group_name]
parent = group
parent_index = self.createIndex(0, 0, group)
Expand Down
28 changes: 25 additions & 3 deletions avalon/tools/cbloader/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from ... import api
from ... import pipeline

from ..projectmanager.widget import preserve_selection

from .model import (
SubsetsModel,
SubsetFilterProxyModel,
Expand All @@ -23,17 +25,24 @@ class SubsetWidget(QtWidgets.QWidget):
active_changed = QtCore.Signal() # active index changed
version_changed = QtCore.Signal() # version state changed for a subset

def __init__(self, parent=None):
def __init__(self, enable_grouping=True, parent=None):
super(SubsetWidget, self).__init__(parent=parent)

model = SubsetsModel()
model = SubsetsModel(grouping=enable_grouping)
proxy = SubsetFilterProxyModel()
family_proxy = FamiliesFilterProxyModel()
family_proxy.setSourceModel(proxy)

filter = QtWidgets.QLineEdit()
filter.setPlaceholderText("Filter subsets..")

groupable = QtWidgets.QCheckBox("Enable Grouping")
groupable.setChecked(enable_grouping)

top_bar_layout = QtWidgets.QHBoxLayout()
top_bar_layout.addWidget(filter)
top_bar_layout.addWidget(groupable)

view = QtWidgets.QTreeView()
view.setIndentation(20)
view.setStyleSheet("""
Expand All @@ -55,7 +64,7 @@ def __init__(self, parent=None):

layout = QtWidgets.QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(filter)
layout.addLayout(top_bar_layout)
layout.addWidget(view)

view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
Expand All @@ -68,6 +77,9 @@ def __init__(self, parent=None):
"delegates": {
"version": version_delegate,
"time": time_delegate
},
"state": {
"groupable": groupable
}
}

Expand All @@ -94,6 +106,8 @@ def __init__(self, parent=None):

version_delegate.version_changed.connect(self.version_changed)

groupable.stateChanged.connect(self.set_grouping)

self.filter.textChanged.connect(self.proxy.setFilterRegExp)
self.filter.textChanged.connect(self.view.expandAll)

Expand All @@ -102,6 +116,14 @@ def __init__(self, parent=None):
# Expose this from the widget as a method
self.set_family_filters = self.family_proxy.setFamiliesFilter

def is_groupable(self):
return self.data["state"]["groupable"].checkState()

def set_grouping(self, state):
with preserve_selection(tree_view=self.view,
current_index=False):
self.model.set_grouping(state)

def on_context_menu(self, point):

point_index = self.view.indexAt(point)
Expand Down

0 comments on commit c8a0468

Please sign in to comment.