From 8dc45d5b7cd9637f28b2d872a834266b991bf434 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 27 Jul 2016 12:03:17 +0100 Subject: Deprecate Q(Persistent)ModelIndex::child MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: David Faure --- src/corelib/itemmodels/qabstractitemmodel.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/corelib/itemmodels/qabstractitemmodel.h') diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 0820626452..907ba09676 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -63,7 +63,9 @@ public: inline void *internalPointer() const Q_DECL_NOTHROW { return reinterpret_cast(i); } inline QModelIndex parent() const; inline QModelIndex sibling(int row, int column) const; - inline QModelIndex child(int row, int column) const; +#if QT_DEPRECATED_SINCE(5, 8) + QT_DEPRECATED_X("Use QAbstractItemModel::index") inline QModelIndex child(int row, int column) const; +#endif inline QVariant data(int role = Qt::DisplayRole) const; inline Qt::ItemFlags flags() const; Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const Q_DECL_NOTHROW { return m; } @@ -128,7 +130,9 @@ public: quintptr internalId() const; QModelIndex parent() const; QModelIndex sibling(int row, int column) const; - QModelIndex child(int row, int column) const; +#if QT_DEPRECATED_SINCE(5, 8) + QT_DEPRECATED_X("Use QAbstractItemModel::index") QModelIndex child(int row, int column) const; +#endif QVariant data(int role = Qt::DisplayRole) const; Qt::ItemFlags flags() const; const QAbstractItemModel *model() const; @@ -419,8 +423,10 @@ inline QModelIndex QModelIndex::parent() const inline QModelIndex QModelIndex::sibling(int arow, int acolumn) const { return m ? (r == arow && c == acolumn) ? *this : m->sibling(arow, acolumn, *this) : QModelIndex(); } +#if QT_DEPRECATED_SINCE(5, 8) inline QModelIndex QModelIndex::child(int arow, int acolumn) const { return m ? m->index(arow, acolumn, *this) : QModelIndex(); } +#endif inline QVariant QModelIndex::data(int arole) const { return m ? m->data(*this, arole) : QVariant(); } -- cgit v1.2.3