From 9e9e73aa6b012fbc9e29a45982387e545191729d Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 1 Jul 2014 08:30:56 -0400 Subject: [PATCH] qtlib: Fix broken SelectableList It was still using `.reset()`, which disappeared in Qt5. Fixes #254. --- qtlib/selectable_list.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/qtlib/selectable_list.py b/qtlib/selectable_list.py index 931fc197..529fb7cf 100644 --- a/qtlib/selectable_list.py +++ b/qtlib/selectable_list.py @@ -1,9 +1,9 @@ # Created By: Virgil Dupras # Created On: 2011-09-06 # Copyright 2014 Hardcoded Software (http://www.hardcoded.net) -# -# This software is licensed under the "BSD" License as described in the "LICENSE" file, -# which should be included with this package. The terms are also available at +# +# This software is licensed under the "BSD" License as described in the "LICENSE" file, +# which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/bsd_license from PyQt5.QtCore import Qt, QAbstractListModel, QItemSelection, QItemSelectionModel @@ -16,7 +16,7 @@ class SelectableList(QAbstractListModel): self.model = model self.view.setModel(self) self.model.view = self - + #--- Override def data(self, index, role): if not index.isValid(): @@ -25,26 +25,27 @@ class SelectableList(QAbstractListModel): if role in {Qt.DisplayRole, Qt.EditRole}: return self.model[index.row()] return None - + def rowCount(self, index): if index.isValid(): return 0 return len(self.model) - + #--- Virtual def _updateSelection(self): raise NotImplementedError() - + def _restoreSelection(self): raise NotImplementedError() - + #--- model --> view def refresh(self): self._updating = True - self.reset() + self.beginResetModel() + self.endResetModel() self._updating = False self._restoreSelection() - + def update_selection(self): self._restoreSelection() @@ -52,18 +53,18 @@ class ComboboxModel(SelectableList): def __init__(self, model, view, **kwargs): super().__init__(model, view, **kwargs) self.view.currentIndexChanged[int].connect(self.selectionChanged) - + #--- Override def _updateSelection(self): index = self.view.currentIndex() if index != self.model.selected_index: self.model.select(index) - + def _restoreSelection(self): index = self.model.selected_index if index is not None: self.view.setCurrentIndex(index) - + #--- Events def selectionChanged(self, index): if not self._updating: @@ -74,13 +75,13 @@ class ListviewModel(SelectableList): super().__init__(model, view, **kwargs) self.view.selectionModel().selectionChanged[(QItemSelection, QItemSelection)].connect( self.selectionChanged) - + #--- Override def _updateSelection(self): newIndexes = [modelIndex.row() for modelIndex in self.view.selectionModel().selectedRows()] if newIndexes != self.model.selected_indexes: self.model.select(newIndexes) - + def _restoreSelection(self): newSelection = QItemSelection() for index in self.model.selected_indexes: @@ -94,4 +95,4 @@ class ListviewModel(SelectableList): def selectionChanged(self, index): if not self._updating: self._updateSelection() - +