From b10f37581467a3596c41e0d0ebe0154b9d08e33b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 3 Jun 2014 10:16:31 +0200 Subject: [PATCH] Add item_count method to CompletionFilterModel --- qutebrowser/models/completionfilter.py | 12 ++++++++++++ qutebrowser/widgets/_completion.py | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/qutebrowser/models/completionfilter.py b/qutebrowser/models/completionfilter.py index 55038069e..648194c8a 100644 --- a/qutebrowser/models/completionfilter.py +++ b/qutebrowser/models/completionfilter.py @@ -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)) diff --git a/qutebrowser/widgets/_completion.py b/qutebrowser/widgets/_completion.py index 955429ed8..56d677d5f 100644 --- a/qutebrowser/widgets/_completion.py +++ b/qutebrowser/widgets/_completion.py @@ -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)