diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-07-27 12:03:17 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-08-16 11:07:03 +0000 |
commit | 8dc45d5b7cd9637f28b2d872a834266b991bf434 (patch) | |
tree | de8736a89ac904eba38d88e36bc01b97d219fec6 /src/corelib/itemmodels/qabstractitemmodel.cpp | |
parent | 17198e03ab36e5f579a1477b09cc3e601975eb5f (diff) |
Deprecate Q(Persistent)ModelIndex::child
Due to how invalid model indices are handled in Qt, child() is unsuitable
for general purpose usage. In particular you can never get a top level
item in the model because the root model index by definition hasn't got
a pointer to the model it belongs.
That makes child() useless for anything but tree models (and even there
you'd need to special case your code anyhow).
[ChangeLog][QtCore][QModelIndex] QModelIndex::child has
been deprecated due to its lack of generality.
Use model->index(row, column, index) instead.
[ChangeLog][QtCore][QPersistentModelIndex] QPersistentModelIndex::child has
been deprecated due to its lack of generality.
Use model->index(row, column, index) instead.
Change-Id: Ice73c17133aaf71355fa2af1eacfe64da01bd456
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.cpp')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 54ea45782d..7fdf107383 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -364,7 +364,7 @@ quintptr QPersistentModelIndex::internalId() const Returns the parent QModelIndex for this persistent index, or an invalid QModelIndex if it has no parent. - \sa child(), sibling(), model() + \sa sibling(), model() */ QModelIndex QPersistentModelIndex::parent() const { @@ -377,7 +377,7 @@ QModelIndex QPersistentModelIndex::parent() const Returns the sibling at \a row and \a column or an invalid QModelIndex if there is no sibling at this position. - \sa parent(), child() + \sa parent() */ QModelIndex QPersistentModelIndex::sibling(int row, int column) const @@ -387,7 +387,12 @@ QModelIndex QPersistentModelIndex::sibling(int row, int column) const return QModelIndex(); } +#if QT_DEPRECATED_SINCE(5, 8) /*! + \obsolete + + Use QAbstractItemModel::index() instead. + Returns the child of the model index that is stored in the given \a row and \a column. @@ -397,9 +402,10 @@ QModelIndex QPersistentModelIndex::sibling(int row, int column) const QModelIndex QPersistentModelIndex::child(int row, int column) const { if (d) - return d->index.child(row, column); + return d->index.model()->index(row, column, d->index); return QModelIndex(); } +#endif /*! Returns the data for the given \a role for the item referred to by the @@ -1099,12 +1105,16 @@ void QAbstractItemModel::resetInternalData() Returns the sibling at \a row and \a column. If there is no sibling at this position, an invalid QModelIndex is returned. - \sa parent(), child() + \sa parent() */ /*! \fn QModelIndex QModelIndex::child(int row, int column) const + \obsolete + + Use QAbstractItemModel::index() instead. + Returns the child of the model index that is stored in the given \a row and \a column. @@ -1153,7 +1163,7 @@ void QAbstractItemModel::resetInternalData() Returns the parent of the model index, or QModelIndex() if it has no parent. - \sa child(), sibling(), model() + \sa sibling(), model() */ /*! |