Mark items after filtering
This commit is contained in:
parent
b10f375814
commit
3f0682e5a9
@ -68,19 +68,16 @@ class BaseCompletionModel(QStandardItemModel):
|
|||||||
marks.append((pos1, pos2))
|
marks.append((pos1, pos2))
|
||||||
return marks
|
return marks
|
||||||
|
|
||||||
def mark_all_items(self, needle):
|
def mark_item(self, index, needle):
|
||||||
"""Mark a string in all items (children of root-children).
|
"""Mark a string in the givem item.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
index: A QModelIndex of the item to mark.
|
||||||
needle: The string to mark.
|
needle: The string to mark.
|
||||||
"""
|
"""
|
||||||
for i in range(self.rowCount()):
|
haystack = self.data(index)
|
||||||
cat = self.index(i, 0)
|
marks = self._get_marks(needle, haystack)
|
||||||
for k in range(self.rowCount(cat)):
|
self.setData(index, marks, ROLE_MARKS)
|
||||||
idx = self.index(k, 0, cat)
|
|
||||||
old = self.data(idx)
|
|
||||||
marks = self._get_marks(needle, old)
|
|
||||||
self.setData(idx, marks, ROLE_MARKS)
|
|
||||||
|
|
||||||
def new_category(self, name):
|
def new_category(self, name):
|
||||||
"""Add a new category to the model.
|
"""Add a new category to the model.
|
||||||
|
@ -95,6 +95,14 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
count += self.rowCount(cat)
|
count += self.rowCount(cat)
|
||||||
return count
|
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):
|
def setSourceModel(self, model):
|
||||||
"""Override QSortFilterProxyModel's setSourceModel to clear pattern."""
|
"""Override QSortFilterProxyModel's setSourceModel to clear pattern."""
|
||||||
logger.debug("Setting source model: {}".format(model))
|
logger.debug("Setting source model: {}".format(model))
|
||||||
|
@ -329,7 +329,7 @@ class CompletionView(QTreeView):
|
|||||||
pattern = parts[cursor_part] if parts else ''
|
pattern = parts[cursor_part] if parts else ''
|
||||||
logger.debug("pattern: {}".format(pattern))
|
logger.debug("pattern: {}".format(pattern))
|
||||||
self._model.pattern = pattern
|
self._model.pattern = pattern
|
||||||
self._model.srcmodel.mark_all_items(pattern)
|
self._model.mark_all_items(pattern)
|
||||||
if self._enabled:
|
if self._enabled:
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user