Improve performance when adding new history item.
Fixes #919. There were two issues here: - CompletionWidget didn't delete the old model when setting a new one. This means filterAcceptsRow was called for models which aren't even used anymore. - setChild was used instead of appendRow for the BaseCompletionModel, which caused Qt to call filterAcceptsRow once for every item of the completion model instead of only once.
This commit is contained in:
parent
02a539f2d7
commit
ef9e1bef1b
@ -198,10 +198,16 @@ class CompletionView(QTreeView):
|
||||
Args:
|
||||
model: The model to use.
|
||||
"""
|
||||
old_model = self.model()
|
||||
sel_model = self.selectionModel()
|
||||
|
||||
self.setModel(model)
|
||||
|
||||
if sel_model is not None:
|
||||
sel_model.deleteLater()
|
||||
if old_model is not None:
|
||||
old_model.deleteLater()
|
||||
|
||||
for i in range(model.rowCount()):
|
||||
self.expand(model.index(i, 0))
|
||||
|
||||
|
@ -88,16 +88,15 @@ class BaseCompletionModel(QStandardItemModel):
|
||||
assert not isinstance(name, int)
|
||||
assert not isinstance(desc, int)
|
||||
assert not isinstance(misc, int)
|
||||
|
||||
nameitem = QStandardItem(name)
|
||||
descitem = QStandardItem(desc)
|
||||
if misc is None:
|
||||
miscitem = QStandardItem()
|
||||
else:
|
||||
miscitem = QStandardItem(misc)
|
||||
idx = cat.rowCount()
|
||||
cat.setChild(idx, 0, nameitem)
|
||||
cat.setChild(idx, 1, descitem)
|
||||
cat.setChild(idx, 2, miscitem)
|
||||
|
||||
cat.appendRow([nameitem, descitem, miscitem])
|
||||
if sort is not None:
|
||||
nameitem.setData(sort, Role.sort)
|
||||
if userdata is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user