Make item_count a @property

This commit is contained in:
Florian Bruhin 2014-06-03 10:48:47 +02:00
parent a555aa66a0
commit c7b2ff4db5
2 changed files with 15 additions and 14 deletions

View File

@ -67,6 +67,19 @@ class CompletionFilterModel(QSortFilterProxyModel):
self.sort(sortcol)
self.invalidate()
@property
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 first_item(self):
"""Return the first item in the model."""
for i in range(self.rowCount()):
@ -83,18 +96,6 @@ 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 mark_all_items(self, text):
"""Mark the given text in all visible items."""
for i in range(self.rowCount()):

View File

@ -331,7 +331,7 @@ class CompletionView(QTreeView):
logger.debug("pattern: {}".format(pattern))
self._model.pattern = pattern
if self._model.item_count() == 0:
if self._model.item_count == 0:
self.hide()
return
@ -373,7 +373,7 @@ class CompletionView(QTreeView):
if indexes:
data = self._model.data(indexes[0])
if data is not None:
if self._model.item_count() == 1 and config.get(
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.