Ensure HistoryCategory works in isolation.
While QSortFilterProxyModel emits layoutChanged when changing the pattern, QSqlQueryModel emits modelReset. As only layoutChanged was connected, a HistoryCategory would only work in a model that also had at least one ListCategory. The simplest solution is to have the parent model emit the signal directly. This also emits a single signal on a pattern change rather that one for each child model. Resolves #3016.
This commit is contained in:
parent
3a012ca1e3
commit
40e4e73e36
@ -60,8 +60,6 @@ class CompletionModel(QAbstractItemModel):
|
||||
def add_category(self, cat):
|
||||
"""Add a completion category to the model."""
|
||||
self._categories.append(cat)
|
||||
cat.layoutAboutToBeChanged.connect(self.layoutAboutToBeChanged)
|
||||
cat.layoutChanged.connect(self.layoutChanged)
|
||||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
"""Return the item data for index.
|
||||
@ -179,8 +177,12 @@ class CompletionModel(QAbstractItemModel):
|
||||
pattern: The filter pattern to set.
|
||||
"""
|
||||
log.completion.debug("Setting completion pattern '{}'".format(pattern))
|
||||
# layoutChanged is broken in pyqt-5.7.1, so we must use metaObject
|
||||
# https://www.riverbankcomputing.com/pipermail/pyqt/2017-January/038483.html
|
||||
self.metaObject().invokeMethod(self, "layoutAboutToBeChanged")
|
||||
for cat in self._categories:
|
||||
cat.set_pattern(pattern)
|
||||
self.metaObject().invokeMethod(self, "layoutChanged")
|
||||
|
||||
def first_item(self):
|
||||
"""Return the index of the first child (non-category) in the model."""
|
||||
|
@ -68,17 +68,17 @@ def test_count(counts):
|
||||
assert model.count() == sum(counts)
|
||||
|
||||
|
||||
@hypothesis.given(strategies.text())
|
||||
def test_set_pattern(pat):
|
||||
@hypothesis.given(pat=strategies.text())
|
||||
def test_set_pattern(pat, qtbot):
|
||||
"""Validate the filtering and sorting results of set_pattern."""
|
||||
model = completionmodel.CompletionModel()
|
||||
cats = [mock.Mock(spec=['set_pattern', 'layoutChanged',
|
||||
'layoutAboutToBeChanged'])
|
||||
for _ in range(3)]
|
||||
cats = [mock.Mock(spec=['set_pattern']) for _ in range(3)]
|
||||
for c in cats:
|
||||
c.set_pattern = mock.Mock(spec=[])
|
||||
model.add_category(c)
|
||||
model.set_pattern(pat)
|
||||
with qtbot.waitSignals([model.layoutAboutToBeChanged, model.layoutChanged],
|
||||
order='strict'):
|
||||
model.set_pattern(pat)
|
||||
for c in cats:
|
||||
c.set_pattern.assert_called_with(pat)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user