diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-02-24 16:32:53 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-22 20:45:12 +0200 |
commit | 15953e95030ee42c78a84c48c7a3f3c2c448601f (patch) | |
tree | 628bc796efb6c825f09efa331e292d834603ae8d /src/corelib/itemmodels/qabstractitemmodel.h | |
parent | be15856f61a949b8a01a1659c15af675c4c2f4e9 (diff) |
QModelIndex: clean up integer size confusion in the API
QAIM::createIndex() took either int or quint32, but QMI::internalId()
returned qint64.
In the new interface, createIndex() takes, and internalId() provides,
integers of type quintptr.
This matches the storage size of the void* in the model index and
avoids truncation.
Remove the
createIndex(int, int, quint32) and
\obsolete createIndex(int,int,int)
overloads.
This makes a literal 0 in the third parameter ambiguous now.
The solutions have been noted in changes-5.0.0.
Change-Id: I0a0ecd8430eaf695129a4d09d14d4e30745485c4
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.h')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 78176c3eb9..fdc4d6aa90 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -64,7 +64,7 @@ public: inline int row() const { return r; } inline int column() const { return c; } inline void *internalPointer() const { return p; } - inline qint64 internalId() const { return reinterpret_cast<qint64>(p); } + inline quintptr internalId() const { return quintptr(p); } inline QModelIndex parent() const; inline QModelIndex sibling(int row, int column) const; inline QModelIndex child(int row, int column) const; @@ -88,7 +88,10 @@ public: } return false; } private: - inline QModelIndex(int row, int column, void *ptr, const QAbstractItemModel *model); + inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) + : r(arow), c(acolumn), p(ptr), m(amodel) {} + inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) + : r(arow), c(acolumn), p(reinterpret_cast<void*>(id)), m(amodel) {} int r, c; void *p; const QAbstractItemModel *m; @@ -121,7 +124,7 @@ public: int row() const; int column() const; void *internalPointer() const; - qint64 internalId() const; + quintptr internalId() const; QModelIndex parent() const; QModelIndex sibling(int row, int column) const; QModelIndex child(int row, int column) const; @@ -329,8 +332,7 @@ protected: QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent = 0); inline QModelIndex createIndex(int row, int column, void *data = 0) const; - inline QModelIndex createIndex(int row, int column, int id) const; - inline QModelIndex createIndex(int row, int column, quint32 id) const; + inline QModelIndex createIndex(int row, int column, quintptr id) const; void encodeData(const QModelIndexList &indexes, QDataStream &stream) const; bool decodeData(int row, int column, const QModelIndex &parent, QDataStream &stream); @@ -400,25 +402,8 @@ inline bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int { return moveRows(sourceParent, sourceColumn, 1, destinationParent, destinationChild); } inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, void *adata) const { return QModelIndex(arow, acolumn, adata, this); } -inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, int aid) const -#if defined(Q_CC_MSVC) -#pragma warning( push ) -#pragma warning( disable : 4312 ) // avoid conversion warning on 64-bit -#endif -{ return QModelIndex(arow, acolumn, reinterpret_cast<void*>(aid), this); } -#if defined(Q_CC_MSVC) -#pragma warning( pop ) -#endif -inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, quint32 aid) const -#if defined(Q_CC_MSVC) -#pragma warning( push ) -#pragma warning( disable : 4312 ) // avoid conversion warning on 64-bit -#endif -{ return QModelIndex(arow, acolumn, reinterpret_cast<void*>(aid), this); } -#if defined(Q_CC_MSVC) -#pragma warning( pop ) -#endif - +inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, quintptr aid) const +{ return QModelIndex(arow, acolumn, aid, this); } class Q_CORE_EXPORT QAbstractTableModel : public QAbstractItemModel { @@ -463,10 +448,6 @@ private: // inline implementations -inline QModelIndex::QModelIndex(int arow, int acolumn, void *adata, - const QAbstractItemModel *amodel) - : r(arow), c(acolumn), p(adata), m(amodel) {} - inline QModelIndex QModelIndex::parent() const { return m ? m->parent(*this) : QModelIndex(); } |