Skip to content

Commit

Permalink
indexToItem changes and subcategory view modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
swillisart committed Jan 18, 2023
1 parent 3fea1dc commit 302d3fe
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 40 deletions.
8 changes: 4 additions & 4 deletions library/widgets/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from relic.local import (INGEST_PATH, Category, ClassGroup, Extension,
FileType, TempAsset, getAssetSourceLocation)
from relic.qt.delegates import Statuses
from relic.qt.util import polymorphicItem
from relic.qt.util import polymorphicItem, indexToItem
from relic.scheme import Class, AssetType
from sequence_path import Path

Expand Down Expand Up @@ -262,8 +262,8 @@ def onLinkItem(self, simple_asset):

# upate the group item with new count.
total = self.increment + len(selection)
index = self.existingNamesList.listView.selectedIndexes()[0]
qitem = self.existingNamesList.indexToItem(index)
index = self.existingNamesList.list_view.selectedIndexes()[0]
qitem = indexToItem(self.existingNamesList.itemModel, index)
simple_asset.name = f'{base} {total}'
qitem.setData(simple_asset.name, Qt.DisplayRole)

Expand Down Expand Up @@ -402,7 +402,7 @@ def selectedSubcategory(self):

def updateSubcategoryCounts(self, index):
tab = self.category_widgets[self.current_category_id]
item = tab.category.tree.indexToItem(index)
item = indexToItem(tab.category.tree.model, index)
tab.category.tree.updateSubcategoryCounts(item)

@Slot()
Expand Down
6 changes: 4 additions & 2 deletions library/widgets/simple_asset_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ def setConstructor(self, constructor):
def onFilterResults(self, results):
if not self.constructor:
return
constructor = self.constructor
item_model = self.itemModel
for x in results:
relate = self.constructor(*x)
relate = constructor(*x)
item = QStandardItem(relate.name)
item.setData(relate, role=Qt.UserRole)
self.itemModel.appendRow(item)
item_model.appendRow(item)

def filterRegExpChanged(self):
text = self.searchBox.text()
Expand Down
37 changes: 16 additions & 21 deletions library/widgets/subcategoriesViews.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from library.objectmodels import relationships, subcategory, CategoryColor
from library.widgets.util import ListViewFocus
from relic.qt.expandable_group import ExpandableGroup
from relic.qt.util import polymorphicItem
from relic.qt.util import polymorphicItem, indexToItem
# -- Third-party --
from PySide6.QtCore import (QEvent, QFile, QItemSelectionModel, QObject,
QPoint, QRegularExpression, QSize,
QSortFilterProxyModel, Signal, Slot)
from PySide6.QtGui import (QAction, QColor, QCursor, QIcon, QDropEvent, QDrag,
QRegularExpressionValidator, QStandardItemModel, Qt)
from PySide6.QtWidgets import (QAbstractItemView, QListView, QMenu,
from PySide6.QtWidgets import (QAbstractItemView, QMenu,
QMessageBox, QStyledItemDelegate, QTreeView,
QWidget, QInputDialog, QLineEdit, QApplication, QStyle)

Expand Down Expand Up @@ -95,7 +95,7 @@ def __init__(self, category=None):
self.proxyModel = recursiveTreeFilter()
self.proxyModel.setSourceModel(self.model)
self.setModel(self.proxyModel)
self.subcategoryListView = ListViewFocus(self)
self.subcategoryListView = ListViewFocus()
self.subcategoryListView.setWindowFlags(Qt.Popup | Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
self.subcategoryListView.newItem.connect(self.newSubcategory)
self.subcategoryListView.renameItem.connect(self.renameSubcategory)
Expand Down Expand Up @@ -145,9 +145,8 @@ def listViewRenameMode(self):
self._showSubcategoryLister()

def _showSubcategoryLister(self):
self.subcategoryListView.addItems(self.model, replace=True)
self.subcategoryListView.proxyModel.endResetModel()
self.subcategoryListView.show()
self.subcategoryListView.addItems(self.model, replace=True)

def loadTreeFromData(self, data):
"""Loads the tree from data.
Expand All @@ -164,13 +163,14 @@ def loadTreeFromData(self, data):

# If the subcategory does not have a link-to-parent relationship
# consider it a root subcategory at the top of the tree.
if not tree_item.upstream or tree_item.upstream <= 0:
tree_upstream = tree_item.upstream
if not tree_upstream or tree_upstream <= 0:
model_root_item.appendRow(tree_item)
else:
parent = data.get(tree_item.upstream)
parent = data.get(tree_upstream)
parent.appendRow(tree_item)

if not tree_item.upstream:
if not tree_upstream:
count += tree_item.count if tree_item.count else 0
self.proxyModel.sort(0, Qt.DescendingOrder)
return count
Expand Down Expand Up @@ -239,11 +239,6 @@ def showContextMenu(self, point: QPoint):

context_menu.exec(QCursor.pos())

def indexToItem(self, index):
remapped_index = self.proxyModel.mapToSource(index)
item = self.model.itemFromIndex(remapped_index)
return item

@Slot()
def newSubcategory(self, name):
"""Inserts a named subcategory into the category tree.
Expand All @@ -255,7 +250,7 @@ def newSubcategory(self, name):
count=0,
)
if selection:
item = self.indexToItem(selection[-1])
item = indexToItem(self.model, selection[-1])
new_item.links = (self.category.id, item.id)
self.new_item_parent = item
new_item.createNew()
Expand All @@ -276,7 +271,7 @@ def renameSubcategory(self, name):
selection = self.selectedIndexes()
if not selection: return

item = self.indexToItem(selection[0])
item = indexToItem(self.model, selection[0])
item.setData(name, Qt.DisplayRole)
item.name = name
subcategory(id=item.id,name=item.name).update(fields=['name'])
Expand All @@ -293,7 +288,7 @@ def resyncCount(self):
return

for index in selection:
item = self.indexToItem(index)
item = indexToItem(self.model, index)
difference = new_count - item.count
self.category.count += difference
asset = index.data(Qt.UserRole)
Expand All @@ -319,7 +314,7 @@ def deleteSubcategory(self):

ids = []
for i, item in enumerate(selection):
item = self.indexToItem(item)
item = indexToItem(self.model, item)
# Use the recursive nature of getCounts to fetch tree descendent ids.
for tree_item in CategoryManager.iterateTreeItems(item):
if tree_item.count > 0:
Expand All @@ -337,7 +332,7 @@ def getSelectionIds(self):
indexes = self.selectedIndexes()
ids = []
for i in indexes:
item = self.indexToItem(i)
item = indexToItem(self.model, i)
do_recurse = int(RELIC_PREFS.recurse_subcategories)
if do_recurse:
# get all descendant subcategory ids
Expand Down Expand Up @@ -370,7 +365,7 @@ def dragEnterEvent(self, event):
if len(selection) != 1:
return

item = self.indexToItem(selection[0])
item = indexToItem(self.model, selection[0])
if not item:
return
self.drag_item = item
Expand All @@ -389,7 +384,7 @@ def getDropDestinationItem(self, event):
index = self.indexAt(drop_position)

if index.isValid():
destination = self.indexToItem(index)
destination = indexToItem(self.model, index)
else:
destination = None

Expand Down Expand Up @@ -488,7 +483,7 @@ def reparentToRoot(self):
# Reparents an item moving to root.
root = self.model.invisibleRootItem()
for index in self.selectedIndexes():
subcategory_item = self.indexToItem(index)
subcategory_item = indexToItem(self.model, index)
selected_parent = subcategory_item.parent()
if not selected_parent:
continue
Expand Down
25 changes: 13 additions & 12 deletions library/widgets/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import partial

from relic.qt.util import polymorphicItem
from relic.qt.util import polymorphicItem, indexToItem
from relic.qt.widgets import FilterBox, FilterBoxLine

from PySide6.QtCore import (QEvent, QFile, QItemSelectionModel, QMargins,
Expand Down Expand Up @@ -113,30 +113,31 @@ def __init__(self, *args, **kwargs):
layout.addWidget(self.list_view)
self.setLayout(layout)

def indexToItem(self, index):
remapped_index = self.proxyModel.mapToSource(index)
item = self.itemModel.itemFromIndex(remapped_index)
return item

def addItems(self, data_model, replace=False):
if replace:
self.itemModel.clear()
item_model = self.itemModel
recurse = self.recursivelyAppendItemToModel
if isinstance(data_model, QStandardItemModel):
for i in range(data_model.rowCount()):
item = data_model.item(i, 0)
if item:
self.recursivelyAppendItemToModel(item)
recurse(item_model, recurse, item)

print(self.proxyModel.rowCount())
print(self.itemModel.rowCount())

def recursivelyAppendItemToModel(self, item):
@staticmethod
def recursivelyAppendItemToModel(item_model, recurse, item):
obj = item.data(Qt.UserRole)
simple = SimpleAsset(obj.name, obj.id)
clone = polymorphicItem(fields=simple)
item_model.appendRow(clone)
if item.hasChildren():
self.itemModel.appendRow(item.clone())
for i in range(item.rowCount()):
child_index = item.child(i, 0)
if child_index:
self.recursivelyAppendItemToModel(child_index)
else:
self.itemModel.appendRow(item.clone())
recurse(item_model, recurse, child_index)

@Slot()
def onSelection(self, selection):
Expand Down
2 changes: 1 addition & 1 deletion plugins/relicMaya/plug-ins/relicMayaPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from relic.local import (INGEST_PATH, Category, FileType, Nuketools, TempAsset,
getAssetSourceLocation)
from relic.scheme import AssetType, TagType, UserType
from relic.plugin import views, networking
from relic.plugin import views, networking, classes
from relic.qt.util import loadStylesheet

# -- Module --
Expand Down

0 comments on commit 302d3fe

Please sign in to comment.