Source code for cgl.ui.widgets.containers.proxy
try:
from PySide6 import QtCore
except:
from PySide6 import QtCore
[docs]
class LJTableSearchProxy(QtCore.QSortFilterProxyModel):
def __init__(self):
QtCore.QSortFilterProxyModel.__init__(self)
self.search_wgt = None
self.search_text = None
self.setSortCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.setDynamicSortFilter(True)
[docs]
def invalidateFilter(self):
text = self.search_wgt.text()
# logging.debug("search: filtering on %s" % text)
if text:
self.search_text = text.lower()
# Create the array used to check for multiple words
self.text_array = [i for i in self.search_text.split(' ') if i != '']
else:
self.search_text = None
QtCore.QSortFilterProxyModel.invalidateFilter(self)
[docs]
def filterAcceptsRow(self, src_row, src_parent):
if not self.search_text: # there is no search we can accept
return True
# Check for each word in the input text
for word in self.text_array:
if not self._filter_help(word, src_row, src_parent):
return False
return True
def _filter_help(self, word, src_row, src_parent):
"""
Original contents of filterAcceptsRow()
"""
column_count = self.sourceModel().columnCount(src_row)
for x in range(0, column_count + 1):
src_index = self.sourceModel().index(src_row, x, src_parent)
data = self.sourceModel().data(src_index, QtCore.Qt.DisplayRole)
if isinstance(data, str):
if word in data.lower():
return True
return False