From b21192282d2dd70d1727773448c075f325b8bf8a Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Fri, 6 Dec 2024 10:12:11 +0100 Subject: [PATCH] QObjectListModel: implement 'index' method Implementing this method allows to use QObjectListModel in combination with other Qt classes that can act on a model (eg: QSelectionItemModel, QSortFilterProxyModel...). --- meshroom/common/qt.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/meshroom/common/qt.py b/meshroom/common/qt.py index 80a09504..6e067dbe 100644 --- a/meshroom/common/qt.py +++ b/meshroom/common/qt.py @@ -283,6 +283,15 @@ class QObjectListModel(QtCore.QAbstractListModel): self._objectByKey[key] = item + @QtCore.Slot(int, result=QtCore.QModelIndex) + def index(self, row: int, column: int = 0, parent=QtCore.QModelIndex()): + """ Returns the model index for the given row, column and parent index. """ + if parent.isValid() or column != 0: + return QtCore.QModelIndex() + if row < 0 or row >= self.size(): + return QtCore.QModelIndex() + return self.createIndex(row, column, self._objects[row]) + def _dereferenceItem(self, item): # Ask for object deletion if parented to the model if shiboken6.isValid(item) and item.parent() == self: