summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qabstractitemmodel.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-05 21:43:42 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-06 11:27:48 +0200
commit8c889bf1104ed1dad95a01d2b1ae1e6950fe82ed (patch)
tree18701f51f519e39bcc3fe4d487854700af837883 /src/corelib/itemmodels/qabstractitemmodel.cpp
parent0de4f0dcc3cae4f535a5604933e7d44212a159d4 (diff)
QModelIndex/QAIM: improve const correctness
QAIM::createIndex() takes a non-const void*. It's typically called from inside QAIM::index(), which is a const member function. If the data storage wrapped by the model is const correct, it means that we have to drop constness somewhere before calling createIndex(). To support this: change createIndex() to take a const void * instead. This is painless. Accessing the pointer is a bit more troubling, because the accessor (QModelIndex::internalPointer()) returns void *. (Effectively, now it does a const_cast...). To avoid a massive source break, I've left it alone, and instead added another function to retrieve a const void *. Read-only models can now be fully (deep) const correct. [ChangeLog][QtCore][QAbstractItemModel] The createIndex() function now takes a const void *, rather than a void *. [ChangeLog][QtCore][QModelIndex] Added the constInternalPointer() function, to retrieve the internal pointer as a pointer-to-const. Change-Id: I108912b6814fcd5fe0c5cb7db6c721ba51e83de0 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.cpp')
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index fac7058d29..49b5031559 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -352,6 +352,22 @@ void *QPersistentModelIndex::internalPointer() const
}
/*!
+ \fn const void *QPersistentModelIndex::constInternalPointer() const
+ \since 6.0
+ \internal
+
+ Returns a \c{const void} \c{*} pointer used by the model to
+ associate the index with the internal data structure.
+*/
+
+const void *QPersistentModelIndex::constInternalPointer() const
+{
+ if (d)
+ return d->index.constInternalPointer();
+ return nullptr;
+}
+
+/*!
\fn quintptr QPersistentModelIndex::internalId() const
\internal
@@ -1065,6 +1081,15 @@ void QAbstractItemModel::resetInternalData()
*/
/*!
+ \fn const void *QModelIndex::constInternalPointer() const
+
+ Returns a \c{const void} \c{*} pointer used by the model to associate
+ the index with the internal data structure.
+
+ \sa QAbstractItemModel::createIndex()
+*/
+
+/*!
\fn quintptr QModelIndex::internalId() const
Returns a \c{quintptr} used by the model to associate
@@ -2589,7 +2614,7 @@ bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation,
}
/*!
- \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr) const
+ \fn QModelIndex QAbstractItemModel::createIndex(int row, int column, const void *ptr) const
Creates a model index for the given \a row and \a column with the internal
pointer \a ptr.