fix usage of filteregexp

This commit is contained in:
Jakub Trllo 2022-12-21 15:55:05 +01:00
parent b5b8119f49
commit 940cb35e0d
4 changed files with 27 additions and 11 deletions

View file

@ -482,8 +482,13 @@ class FilterProxyModel(QtCore.QSortFilterProxyModel):
return True
# Filter by regex
if not self.filterRegExp().isEmpty():
pattern = re.escape(self.filterRegExp().pattern())
if hasattr(self, "filterRegularExpression"):
regex = self.filterRegularExpression()
else:
regex = self.filterRegExp()
pattern = regex.pattern()
if pattern:
pattern = re.escape(pattern)
if not self._matches(row, parent, pattern):
return False

View file

@ -27,8 +27,13 @@ class RecursiveSortFilterProxyModel(QtCore.QSortFilterProxyModel):
if not parent.isValid():
return False
regex = self.filterRegExp()
if not regex.isEmpty() and regex.isValid():
if hasattr(self, "filterRegularExpression"):
regex = self.filterRegularExpression()
else:
regex = self.filterRegExp()
pattern = regex.pattern()
if pattern and regex.isValid():
pattern = regex.pattern()
compiled_regex = re.compile(pattern, re.IGNORECASE)
source_model = self.sourceModel()

View file

@ -5,14 +5,15 @@ 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):
regex = self.filterRegExp()
if not regex.isEmpty():
pattern = regex.pattern()
if hasattr(self, "filterRegularExpression"):
regex = self.filterRegularExpression()
else:
regex = self.filterRegExp()
pattern = regex.pattern()
if pattern:
model = self.sourceModel()
source_index = model.index(row, self.filterKeyColumn(), parent)
if source_index.isValid():
# Check current index itself
key = model.data(source_index, self.filterRole())
if re.search(pattern, key, re.IGNORECASE):

View file

@ -203,8 +203,13 @@ class RecursiveSortFilterProxyModel(QtCore.QSortFilterProxyModel):
the filter string but first checks if any children does.
"""
def filterAcceptsRow(self, row, parent_index):
regex = self.filterRegExp()
if not regex.isEmpty():
if hasattr(self, "filterRegularExpression"):
regex = self.filterRegularExpression()
else:
regex = self.filterRegExp()
pattern = regex.pattern()
if pattern:
model = self.sourceModel()
source_index = model.index(
row, self.filterKeyColumn(), parent_index