Make srcmodel public in CompletionFilterModel.
This commit is contained in:
parent
b54151f206
commit
dc8f156c21
@ -35,7 +35,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_pattern: The pattern to filter with.
|
_pattern: The pattern to filter with.
|
||||||
_srcmodel: The current source model.
|
srcmodel: The current source model.
|
||||||
Kept as attribute because calling `sourceModel` takes quite
|
Kept as attribute because calling `sourceModel` takes quite
|
||||||
a long time for some reason.
|
a long time for some reason.
|
||||||
"""
|
"""
|
||||||
@ -43,7 +43,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
def __init__(self, source, parent=None):
|
def __init__(self, source, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
super().setSourceModel(source)
|
super().setSourceModel(source)
|
||||||
self._srcmodel = source
|
self.srcmodel = source
|
||||||
self._pattern = ''
|
self._pattern = ''
|
||||||
|
|
||||||
def set_pattern(self, val):
|
def set_pattern(self, val):
|
||||||
@ -61,7 +61,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
self.invalidateFilter()
|
self.invalidateFilter()
|
||||||
sortcol = 0
|
sortcol = 0
|
||||||
try:
|
try:
|
||||||
self._srcmodel.sort(sortcol)
|
self.srcmodel.sort(sortcol)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
self.sort(sortcol)
|
self.sort(sortcol)
|
||||||
self.invalidate()
|
self.invalidate()
|
||||||
@ -111,14 +111,14 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
qtutils.ensure_valid(index)
|
qtutils.ensure_valid(index)
|
||||||
index = self.mapToSource(index)
|
index = self.mapToSource(index)
|
||||||
qtutils.ensure_valid(index)
|
qtutils.ensure_valid(index)
|
||||||
self._srcmodel.mark_item(index, text)
|
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."""
|
||||||
log.completion.debug("Setting source model: {}".format(model))
|
log.completion.debug("Setting source model: {}".format(model))
|
||||||
self.set_pattern('')
|
self.set_pattern('')
|
||||||
super().setSourceModel(model)
|
super().setSourceModel(model)
|
||||||
self._srcmodel = model
|
self.srcmodel = model
|
||||||
|
|
||||||
def filterAcceptsRow(self, row, parent):
|
def filterAcceptsRow(self, row, parent):
|
||||||
"""Custom filter implementation.
|
"""Custom filter implementation.
|
||||||
@ -135,9 +135,9 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
"""
|
"""
|
||||||
if parent == QModelIndex():
|
if parent == QModelIndex():
|
||||||
return True
|
return True
|
||||||
idx = self._srcmodel.index(row, 0, parent)
|
idx = self.srcmodel.index(row, 0, parent)
|
||||||
qtutils.ensure_valid(idx)
|
qtutils.ensure_valid(idx)
|
||||||
data = self._srcmodel.data(idx)
|
data = self.srcmodel.data(idx)
|
||||||
# TODO more sophisticated filtering
|
# TODO more sophisticated filtering
|
||||||
if not self._pattern:
|
if not self._pattern:
|
||||||
return True
|
return True
|
||||||
@ -159,14 +159,14 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
qtutils.ensure_valid(lindex)
|
qtutils.ensure_valid(lindex)
|
||||||
qtutils.ensure_valid(rindex)
|
qtutils.ensure_valid(rindex)
|
||||||
|
|
||||||
left_sort = self._srcmodel.data(lindex, role=completion.Role.sort)
|
left_sort = self.srcmodel.data(lindex, role=completion.Role.sort)
|
||||||
right_sort = self._srcmodel.data(rindex, role=completion.Role.sort)
|
right_sort = self.srcmodel.data(rindex, role=completion.Role.sort)
|
||||||
|
|
||||||
if left_sort is not None and right_sort is not None:
|
if left_sort is not None and right_sort is not None:
|
||||||
return left_sort < right_sort
|
return left_sort < right_sort
|
||||||
|
|
||||||
left = self._srcmodel.data(lindex)
|
left = self.srcmodel.data(lindex)
|
||||||
right = self._srcmodel.data(rindex)
|
right = self.srcmodel.data(rindex)
|
||||||
|
|
||||||
leftstart = left.startswith(self._pattern)
|
leftstart = left.startswith(self._pattern)
|
||||||
rightstart = right.startswith(self._pattern)
|
rightstart = right.startswith(self._pattern)
|
||||||
|
@ -233,7 +233,7 @@ class Completer(QObject):
|
|||||||
|
|
||||||
log.completion.debug(
|
log.completion.debug(
|
||||||
"New completion for {}: {}, with pattern '{}'".format(
|
"New completion for {}: {}, with pattern '{}'".format(
|
||||||
parts, model._srcmodel.__class__.__name__, pattern))
|
parts, model.srcmodel.__class__.__name__, pattern))
|
||||||
|
|
||||||
if self._model().count() == 0:
|
if self._model().count() == 0:
|
||||||
completion.hide()
|
completion.hide()
|
||||||
|
Loading…
Reference in New Issue
Block a user