mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-28 09:47:20 +02:00
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...).
This commit is contained in:
parent
df4ad22b6c
commit
b21192282d
1 changed files with 9 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue