Make item_count a @property
This commit is contained in:
parent
a555aa66a0
commit
c7b2ff4db5
@ -67,6 +67,19 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
self.sort(sortcol)
|
self.sort(sortcol)
|
||||||
self.invalidate()
|
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):
|
def first_item(self):
|
||||||
"""Return the first item in the model."""
|
"""Return the first item in the model."""
|
||||||
for i in range(self.rowCount()):
|
for i in range(self.rowCount()):
|
||||||
@ -83,18 +96,6 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
return self.index(self.rowCount(cat) - 1, 0, cat)
|
return self.index(self.rowCount(cat) - 1, 0, cat)
|
||||||
return QModelIndex()
|
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):
|
def mark_all_items(self, text):
|
||||||
"""Mark the given text in all visible items."""
|
"""Mark the given text in all visible items."""
|
||||||
for i in range(self.rowCount()):
|
for i in range(self.rowCount()):
|
||||||
|
@ -331,7 +331,7 @@ class CompletionView(QTreeView):
|
|||||||
logger.debug("pattern: {}".format(pattern))
|
logger.debug("pattern: {}".format(pattern))
|
||||||
self._model.pattern = pattern
|
self._model.pattern = pattern
|
||||||
|
|
||||||
if self._model.item_count() == 0:
|
if self._model.item_count == 0:
|
||||||
self.hide()
|
self.hide()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ class CompletionView(QTreeView):
|
|||||||
if indexes:
|
if indexes:
|
||||||
data = self._model.data(indexes[0])
|
data = self._model.data(indexes[0])
|
||||||
if data is not None:
|
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'):
|
'completion', 'quick-complete'):
|
||||||
# If we only have one item, we want to apply it immediately
|
# If we only have one item, we want to apply it immediately
|
||||||
# and go on to the next part.
|
# and go on to the next part.
|
||||||
|
Loading…
Reference in New Issue
Block a user