From 3134106a110c5ed097b6855848180eac16bcff98 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 11 Apr 2016 20:10:53 +0800 Subject: [PATCH] gui/models: handle Qt calling DictSyncTreeSepModel.index with garbage inputs. Closes #388 --- artiq/gui/models.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/artiq/gui/models.py b/artiq/gui/models.py index 4d4c08b67..3bc47470a 100644 --- a/artiq/gui/models.py +++ b/artiq/gui/models.py @@ -270,13 +270,24 @@ class DictSyncTreeSepModel(QtCore.QAbstractItemModel): return None def index(self, row, column, parent): + if column >= len(self.headers): + return QtCore.QModelIndex() if parent.isValid(): parent_item = parent.internalPointer() - return self.createIndex(row, column, - parent_item.children_by_row[row]) + try: + 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: - return self.createIndex(row, column, - self.children_by_row[row]) + try: + child = self.children_by_row[row] + except IndexError: + return QtCore.QModelIndex() + return self.createIndex(row, column, child) def _index_item(self, item): if item is self: