Merge branch 'lahwaacz-completion_trivial'

This commit is contained in:
Florian Bruhin 2016-07-29 12:08:28 +02:00
commit f9c09a1f43
4 changed files with 15 additions and 42 deletions

View File

@ -147,8 +147,8 @@ Contributors, sorted by the number of commits in descending order:
* Bruno Oliveira
* Alexander Cogneau
* Felix Van der Jeugt
* Martin Tournoij
* Jakub Klinkovský
* Martin Tournoij
* Raphael Pierzina
* Joel Torstensson
* Jan Verbeek

View File

@ -200,7 +200,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
columns_to_filter = index.model().srcmodel.columns_to_filter
if index.column() in columns_to_filter and pattern:
repl = r'<span class="highlight">\g<0></span>'
text = re.sub(re.escape(pattern).replace(r'\ ', r'.*'),
text = re.sub(re.escape(pattern).replace(r'\ ', r'|'),
repl, self._opt.text, flags=re.IGNORECASE)
self._doc.setHtml(text)
else:

View File

@ -128,20 +128,3 @@ class BaseCompletionModel(QStandardItemModel):
else:
# category
return Qt.NoItemFlags
def sort(self, column, order=Qt.AscendingOrder):
"""Sort the data in column according to order.
Override QAbstractItemModel::sort.
"""
raise NotImplementedError
def custom_filter(self, pattern, row, parent):
"""Custom filter.
Args:
pattern: The current filter pattern.
row: The row to accept or reject in the filter.
parent: The parent item QModelIndex.
"""
raise NotImplementedError

View File

@ -63,9 +63,6 @@ class CompletionFilterModel(QSortFilterProxyModel):
Invalidates the filter and re-sorts the model.
If the current completion model overrides sort(), it is used.
If not, the default implementation in QCompletionFilterModel is called.
Args:
val: The value to set.
"""
@ -74,13 +71,9 @@ class CompletionFilterModel(QSortFilterProxyModel):
val = re.escape(val)
val = val.replace(r'\ ', r'.*')
self.pattern_re = re.compile(val, re.IGNORECASE)
self.invalidateFilter()
sortcol = 0
try:
self.srcmodel.sort(sortcol)
except NotImplementedError:
self.sort(sortcol)
self.invalidate()
sortcol = 0
self.sort(sortcol)
def count(self):
"""Get the count of non-toplevel items currently visible.
@ -140,20 +133,17 @@ class CompletionFilterModel(QSortFilterProxyModel):
if parent == QModelIndex() or not self.pattern:
return True
try:
return self.srcmodel.custom_filter(self.pattern, row, parent)
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:
continue
elif self.pattern_re.search(data):
return True
return False
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:
continue
elif self.pattern_re.search(data):
return True
return False
def intelligentLessThan(self, lindex, rindex):
"""Custom sorting implementation.