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:
Florian Bruhin 2015-09-06 16:59:43 +02:00
parent 02a539f2d7
commit ef9e1bef1b
2 changed files with 9 additions and 4 deletions

View File

@ -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))

View File

@ -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: