forked from M-Labs/artiq
1
0
Fork 0

gui/models: handle Qt calling DictSyncTreeSepModel.index with garbage inputs. Closes #388

This commit is contained in:
Sebastien Bourdeauducq 2016-04-11 20:10:53 +08:00
parent 7d590afd73
commit 3134106a11
1 changed files with 15 additions and 4 deletions

View File

@ -270,13 +270,24 @@ class DictSyncTreeSepModel(QtCore.QAbstractItemModel):
return None return None
def index(self, row, column, parent): def index(self, row, column, parent):
if column >= len(self.headers):
return QtCore.QModelIndex()
if parent.isValid(): if parent.isValid():
parent_item = parent.internalPointer() parent_item = parent.internalPointer()
return self.createIndex(row, column, try:
parent_item.children_by_row[row]) child = parent_item.children_by_row[row]
except IndexError:
# This can happen when the last row is selected
# and then deleted; Qt will attempt to select
# the non-existent next one.
return QtCore.QModelIndex()
return self.createIndex(row, column, child)
else: else:
return self.createIndex(row, column, try:
self.children_by_row[row]) child = self.children_by_row[row]
except IndexError:
return QtCore.QModelIndex()
return self.createIndex(row, column, child)
def _index_item(self, item): def _index_item(self, item):
if item is self: if item is self: