Add item_count method to CompletionFilterModel

This commit is contained in:
Florian Bruhin 2014-06-03 10:16:31 +02:00
parent ce8ada5024
commit b10f375814
2 changed files with 14 additions and 2 deletions

View File

@ -83,6 +83,18 @@ class CompletionFilterModel(QSortFilterProxyModel):
return self.index(self.rowCount(cat) - 1, 0, cat)
return QModelIndex()
def item_count(self):
"""Get the count of non-toplevel items currently visible.
Note this only iterates one level deep, as we only need root items
(categories) and children (items) in our model.
"""
count = 0
for i in range(self.rowCount()):
cat = self.index(i, 0)
count += self.rowCount(cat)
return count
def setSourceModel(self, model):
"""Override QSortFilterProxyModel's setSourceModel to clear pattern."""
logger.debug("Setting source model: {}".format(model))

View File

@ -367,8 +367,8 @@ class CompletionView(QTreeView):
if indexes:
data = self._model.data(indexes[0])
if data is not None:
if (self._model.rowCount(indexes[0].parent()) == 1 and
config.get('completion', 'quick-complete')):
if self._model.item_count() == 1 and config.get(
'completion', 'quick-complete'):
# If we only have one item, we want to apply it immediately
# and go on to the next part.
self.change_completed_part.emit(data, True)