Filter by cols_to_filter in CompletionFilterModel.
This commit is contained in:
parent
3b0125e8cd
commit
aaa523ce7c
@ -130,22 +130,23 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
True if self.pattern is contained in item, or if it's a root item
|
True if self.pattern is contained in item, or if it's a root item
|
||||||
(category). False in all other cases
|
(category). False in all other cases
|
||||||
"""
|
"""
|
||||||
if parent == QModelIndex():
|
if parent == QModelIndex() or not self.pattern:
|
||||||
return True
|
|
||||||
idx = self.srcmodel.index(row, 0, parent)
|
|
||||||
if not idx.isValid():
|
|
||||||
# No entries in parent model
|
|
||||||
return False
|
|
||||||
data = self.srcmodel.data(idx)
|
|
||||||
if not self.pattern:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.srcmodel.custom_filter(self.pattern, row, parent)
|
return self.srcmodel.custom_filter(self.pattern, row, parent)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
|
for col in self.srcmodel.columns_to_filter:
|
||||||
|
idx = self.srcmodel.index(row, col, parent)
|
||||||
|
if not idx.isValid():
|
||||||
|
# No entries in parent model
|
||||||
|
continue
|
||||||
|
data = self.srcmodel.data(idx)
|
||||||
if not data:
|
if not data:
|
||||||
|
continue
|
||||||
|
elif self.pattern.casefold() in data.casefold():
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
return self.pattern.casefold() in data.casefold()
|
|
||||||
|
|
||||||
def intelligentLessThan(self, lindex, rindex):
|
def intelligentLessThan(self, lindex, rindex):
|
||||||
"""Custom sorting implementation.
|
"""Custom sorting implementation.
|
||||||
|
@ -100,15 +100,6 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
|||||||
"""
|
"""
|
||||||
self.new_item(self._bookmark_cat, url, title)
|
self.new_item(self._bookmark_cat, url, title)
|
||||||
|
|
||||||
def custom_filter(self, pattern, row, parent):
|
|
||||||
"""Filter by url and title."""
|
|
||||||
index0 = self.index(row, 0, parent)
|
|
||||||
index1 = self.index(row, 1, parent)
|
|
||||||
url = self.data(index0) or ''
|
|
||||||
title = self.data(index1) or ''
|
|
||||||
return (pattern.casefold() in url.casefold() or pattern.casefold() in
|
|
||||||
title.casefold())
|
|
||||||
|
|
||||||
@config.change_filter('completion', 'timestamp-format')
|
@config.change_filter('completion', 'timestamp-format')
|
||||||
def reformat_timestamps(self):
|
def reformat_timestamps(self):
|
||||||
"""Reformat the timestamps if the config option was changed."""
|
"""Reformat the timestamps if the config option was changed."""
|
||||||
|
Loading…
Reference in New Issue
Block a user