Mark items after filtering

This commit is contained in:
Florian Bruhin 2014-06-03 10:37:04 +02:00
parent b10f375814
commit 3f0682e5a9
3 changed files with 15 additions and 10 deletions

View File

@ -68,19 +68,16 @@ class BaseCompletionModel(QStandardItemModel):
marks.append((pos1, pos2))
return marks
def mark_all_items(self, needle):
"""Mark a string in all items (children of root-children).
def mark_item(self, index, needle):
"""Mark a string in the givem item.
Args:
index: A QModelIndex of the item to mark.
needle: The string to mark.
"""
for i in range(self.rowCount()):
cat = self.index(i, 0)
for k in range(self.rowCount(cat)):
idx = self.index(k, 0, cat)
old = self.data(idx)
marks = self._get_marks(needle, old)
self.setData(idx, marks, ROLE_MARKS)
haystack = self.data(index)
marks = self._get_marks(needle, haystack)
self.setData(index, marks, ROLE_MARKS)
def new_category(self, name):
"""Add a new category to the model.

View File

@ -95,6 +95,14 @@ class CompletionFilterModel(QSortFilterProxyModel):
count += self.rowCount(cat)
return count
def mark_all_items(self, text):
"""Mark the given text in all visible items."""
for i in range(self.rowCount()):
cat = self.index(i, 0)
for k in range(self.rowCount(cat)):
index = self.mapToSource(self.index(k, 0, cat))
self.srcmodel.mark_item(index, text)
def setSourceModel(self, model):
"""Override QSortFilterProxyModel's setSourceModel to clear pattern."""
logger.debug("Setting source model: {}".format(model))

View File

@ -329,7 +329,7 @@ class CompletionView(QTreeView):
pattern = parts[cursor_part] if parts else ''
logger.debug("pattern: {}".format(pattern))
self._model.pattern = pattern
self._model.srcmodel.mark_all_items(pattern)
self._model.mark_all_items(pattern)
if self._enabled:
self.show()