From 35915e90f61e02b9fba75bab620c29f2b7f4bc18 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 26 Dec 2014 21:43:40 +0100 Subject: QModelIndex: plaster API with Q_DECL_NOTHROW This is mostly straight-forward, but some things are worth noting: 1. Yes, this is necessary. The noexcept operator looks for noexcept tagging, not at the contents of the function to determine whether to return true. The more conditionally-noexcept functions are used, the more important it becomes that low-level classes are correctly marked noexcept. In that, it is like constexpr. 2. The functions that actually call into the model (data(), flags(), sibling(), ...) can throw (bad_alloc, if nothing else). Consequently, they're not marked nothrow. They're the only ones. Change-Id: Id0413212b0f1c049a339480ee449a53c3ca9fea0 Reviewed-by: Thiago Macieira --- src/corelib/itemmodels/qabstractitemmodel.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/corelib/itemmodels/qabstractitemmodel.h') diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 5761084055..a49cf160cc 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -49,24 +49,24 @@ class Q_CORE_EXPORT QModelIndex { friend class QAbstractItemModel; public: - Q_DECL_CONSTEXPR inline QModelIndex() : r(-1), c(-1), i(0), m(0) {} + Q_DECL_CONSTEXPR inline QModelIndex() Q_DECL_NOTHROW : r(-1), c(-1), i(0), m(0) {} // compiler-generated copy/move ctors/assignment operators are fine! - Q_DECL_CONSTEXPR inline int row() const { return r; } - Q_DECL_CONSTEXPR inline int column() const { return c; } - Q_DECL_CONSTEXPR inline quintptr internalId() const { return i; } - inline void *internalPointer() const { return reinterpret_cast(i); } + Q_DECL_CONSTEXPR inline int row() const Q_DECL_NOTHROW { return r; } + Q_DECL_CONSTEXPR inline int column() const Q_DECL_NOTHROW { return c; } + Q_DECL_CONSTEXPR inline quintptr internalId() const Q_DECL_NOTHROW { return i; } + 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; inline QVariant data(int role = Qt::DisplayRole) const; inline Qt::ItemFlags flags() const; - Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const { return m; } - Q_DECL_CONSTEXPR inline bool isValid() const { return (r >= 0) && (c >= 0) && (m != 0); } - Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const + Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const Q_DECL_NOTHROW { return m; } + Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW { return (r >= 0) && (c >= 0) && (m != 0); } + Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const Q_DECL_NOTHROW { return (other.r == r) && (other.i == i) && (other.c == c) && (other.m == m); } - Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const + Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const Q_DECL_NOTHROW { return !(*this == other); } - Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const + Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const Q_DECL_NOTHROW { return r < other.r || (r == other.r && (c < other.c @@ -74,9 +74,9 @@ public: || (i == other.i && m < other.m ))))); } private: - inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) + inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) Q_DECL_NOTHROW : r(arow), c(acolumn), i(reinterpret_cast(ptr)), m(amodel) {} - Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) + Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) Q_DECL_NOTHROW : r(arow), c(acolumn), i(id), m(amodel) {} int r, c; quintptr i; @@ -475,7 +475,7 @@ inline QVariant QModelIndex::data(int arole) const inline Qt::ItemFlags QModelIndex::flags() const { return m ? m->flags(*this) : Qt::ItemFlags(0); } -inline uint qHash(const QModelIndex &index) +inline uint qHash(const QModelIndex &index) Q_DECL_NOTHROW { return uint((index.row() << 4) + index.column() + index.internalId()); } QT_END_NAMESPACE -- cgit v1.2.3