diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-12-02 15:40:14 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-12-03 13:49:31 +0100 |
commit | 0cd2935ed9d772f0eb06d03201baabd60764ec80 (patch) | |
tree | 709538594c39136c301cadfdedcbd55e52cc93ad | |
parent | 83e95956ed58e88b11e2cc3cb61c5beacb7985db (diff) |
Dont' return a const ref to QModelIndex
The conversion operator from QPMI to QModelIndex should return by
value, to hide implementation details and so that we don't have to
rely on a static empty QModelIndex.
Pick-to: 6.0 dev
Change-Id: I92b3f8451422f2b69bf31f28b387a124fd24ec46
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 9 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 7f842e29a6..8da33e0c4e 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -488,17 +488,16 @@ QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other } /*! - \fn QPersistentModelIndex::operator const QModelIndex&() const + \fn QPersistentModelIndex::operator QModelIndex() const - Cast operator that returns a const QModelIndex&. + Cast operator that returns a QModelIndex. */ -QPersistentModelIndex::operator const QModelIndex&() const +QPersistentModelIndex::operator QModelIndex() const { - static const QModelIndex invalid; if (d) return d->index; - return invalid; + return QModelIndex(); } /*! diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 8340ca0e73..26eb910475 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -226,7 +226,7 @@ public: bool operator==(const QModelIndex &other) const; bool operator!=(const QModelIndex &other) const; QPersistentModelIndex &operator=(const QModelIndex &other); - operator const QModelIndex&() const; + operator QModelIndex() const; int row() const; int column() const; void *internalPointer() const; |