Fix tabbing with models with children

This commit is contained in:
Florian Bruhin 2014-03-23 21:15:28 +01:00
parent ea0ef4fb01
commit d5456fcae1

View File

@ -72,19 +72,19 @@ class CompletionFilterModel(QSortFilterProxyModel):
def first_item(self): def first_item(self):
"""Return the first item in the model.""" """Return the first item in the model."""
# FIXME if the tree looks like this: for i in range(self.rowCount()):
# - cat1 cat = self.index(i, 0)
# + cat2 if cat.model().hasChildren(cat):
# - item return self.index(0, 0, cat)
# then this will yield an invalid index. return QModelIndex()
cat = self.index(0, 0)
return self.index(0, 0, cat)
def last_item(self): def last_item(self):
"""Return the last item in the model.""" """Return the last item in the model."""
# FIXME this has about the same problem as above for i in range(self.rowCount() - 1, -1, -1):
cat = self.index(self.rowCount() - 1, 0) cat = self.index(i, 0)
return self.index(self.rowCount(cat) - 1, 0, cat) if cat.model().hasChildren(cat):
return self.index(self.rowCount(cat) - 1, 0, cat)
return QModelIndex()
def setSourceModel(self, model): def setSourceModel(self, model):
"""Override QSortFilterProxyModel's setSourceModel to clear pattern.""" """Override QSortFilterProxyModel's setSourceModel to clear pattern."""