mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Tools: Fix recursive filtering (#4597)
* check for 'filterRegExp' first * use recursive filtering option if is available
This commit is contained in:
parent
a7f0d57638
commit
86184a8ee0
6 changed files with 33 additions and 23 deletions
|
|
@ -295,10 +295,10 @@ class SubsetWidget(QtWidgets.QWidget):
|
|||
self.model.set_grouping(state)
|
||||
|
||||
def _subset_changed(self, text):
|
||||
if hasattr(self.proxy, "setFilterRegularExpression"):
|
||||
self.proxy.setFilterRegularExpression(text)
|
||||
else:
|
||||
if hasattr(self.proxy, "setFilterRegExp"):
|
||||
self.proxy.setFilterRegExp(text)
|
||||
else:
|
||||
self.proxy.setFilterRegularExpression(text)
|
||||
self.view.expandAll()
|
||||
|
||||
def set_loading_state(self, loading, empty):
|
||||
|
|
|
|||
|
|
@ -482,10 +482,10 @@ class FilterProxyModel(QtCore.QSortFilterProxyModel):
|
|||
return True
|
||||
|
||||
# Filter by regex
|
||||
if hasattr(self, "filterRegularExpression"):
|
||||
regex = self.filterRegularExpression()
|
||||
else:
|
||||
if hasattr(self, "filterRegExp"):
|
||||
regex = self.filterRegExp()
|
||||
else:
|
||||
regex = self.filterRegularExpression()
|
||||
pattern = regex.pattern()
|
||||
if pattern:
|
||||
pattern = re.escape(pattern)
|
||||
|
|
|
|||
|
|
@ -160,10 +160,10 @@ class SceneInventoryWindow(QtWidgets.QDialog):
|
|||
self._model.set_hierarchy_view(enabled)
|
||||
|
||||
def _on_text_filter_change(self, text_filter):
|
||||
if hasattr(self._proxy, "setFilterRegularExpression"):
|
||||
self._proxy.setFilterRegularExpression(text_filter)
|
||||
else:
|
||||
if hasattr(self._proxy, "setFilterRegExp"):
|
||||
self._proxy.setFilterRegExp(text_filter)
|
||||
else:
|
||||
self._proxy.setFilterRegularExpression(text_filter)
|
||||
|
||||
def _on_outdated_state_change(self):
|
||||
self._proxy.set_filter_outdated(
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ class RecursiveSortFilterProxyModel(QtCore.QSortFilterProxyModel):
|
|||
if not parent.isValid():
|
||||
return False
|
||||
|
||||
if hasattr(self, "filterRegularExpression"):
|
||||
regex = self.filterRegularExpression()
|
||||
else:
|
||||
if hasattr(self, "filterRegExp"):
|
||||
regex = self.filterRegExp()
|
||||
else:
|
||||
regex = self.filterRegularExpression()
|
||||
|
||||
pattern = regex.pattern()
|
||||
if pattern and regex.isValid():
|
||||
|
|
@ -111,10 +111,10 @@ class SearchEntitiesDialog(QtWidgets.QDialog):
|
|||
|
||||
def _on_filter_timer(self):
|
||||
text = self._filter_edit.text()
|
||||
if hasattr(self._proxy, "setFilterRegularExpression"):
|
||||
self._proxy.setFilterRegularExpression(text)
|
||||
else:
|
||||
if hasattr(self._proxy, "setFilterRegExp"):
|
||||
self._proxy.setFilterRegExp(text)
|
||||
else:
|
||||
self._proxy.setFilterRegularExpression(text)
|
||||
|
||||
# WARNING This expanding and resizing is relatively slow.
|
||||
self._view.expandAll()
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ from qtpy import QtCore
|
|||
class RecursiveSortFilterProxyModel(QtCore.QSortFilterProxyModel):
|
||||
"""Filters to the regex if any of the children matches allow parent"""
|
||||
def filterAcceptsRow(self, row, parent):
|
||||
if hasattr(self, "filterRegularExpression"):
|
||||
regex = self.filterRegularExpression()
|
||||
else:
|
||||
if hasattr(self, "filterRegExp"):
|
||||
regex = self.filterRegExp()
|
||||
else:
|
||||
regex = self.filterRegularExpression()
|
||||
pattern = regex.pattern()
|
||||
if pattern:
|
||||
model = self.sourceModel()
|
||||
|
|
|
|||
|
|
@ -202,11 +202,20 @@ class RecursiveSortFilterProxyModel(QtCore.QSortFilterProxyModel):
|
|||
Use case: Filtering by string - parent won't be filtered if does not match
|
||||
the filter string but first checks if any children does.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RecursiveSortFilterProxyModel, self).__init__(*args, **kwargs)
|
||||
recursive_enabled = False
|
||||
if hasattr(self, "setRecursiveFilteringEnabled"):
|
||||
self.setRecursiveFilteringEnabled(True)
|
||||
recursive_enabled = True
|
||||
self._recursive_enabled = recursive_enabled
|
||||
|
||||
def filterAcceptsRow(self, row, parent_index):
|
||||
if hasattr(self, "filterRegularExpression"):
|
||||
regex = self.filterRegularExpression()
|
||||
else:
|
||||
if hasattr(self, "filterRegExp"):
|
||||
regex = self.filterRegExp()
|
||||
else:
|
||||
regex = self.filterRegularExpression()
|
||||
|
||||
pattern = regex.pattern()
|
||||
if pattern:
|
||||
|
|
@ -219,8 +228,9 @@ class RecursiveSortFilterProxyModel(QtCore.QSortFilterProxyModel):
|
|||
|
||||
# Check current index itself
|
||||
value = model.data(source_index, self.filterRole())
|
||||
if re.search(pattern, value, re.IGNORECASE):
|
||||
return True
|
||||
matched = bool(re.search(pattern, value, re.IGNORECASE))
|
||||
if matched or self._recursive_enabled:
|
||||
return matched
|
||||
|
||||
rows = model.rowCount(source_index)
|
||||
for idx in range(rows):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue