diff options
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 14 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 38 | ||||
-rw-r--r-- | src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp | 2 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.h | 8 |
4 files changed, 33 insertions, 29 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index abd86f2b49..18f0f6f55f 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -2355,6 +2355,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, bool wrap = flags & Qt::MatchWrap; bool allHits = (hits == -1); QString text; // only convert to a string if it is needed + const int column = start.column(); QModelIndex p = parent(start); int from = start.row(); int to = rowCount(p); @@ -2362,7 +2363,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, // iterates twice if wrapping for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) { for (int r = from; (r < to) && (allHits || result.count() < hits); ++r) { - QModelIndex idx = index(r, start.column(), p); + QModelIndex idx = index(r, column, p); if (!idx.isValid()) continue; QVariant v = data(idx, role); @@ -2401,10 +2402,13 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, result.append(idx); } } - if (recurse && hasChildren(idx)) { // search the hierarchy - result += match(index(0, idx.column(), idx), role, - (text.isEmpty() ? value : text), - (allHits ? -1 : hits - result.count()), flags); + if (recurse) { + const auto parent = column != 0 ? idx.sibling(idx.row(), 0) : idx; + if (hasChildren(parent)) { // search the hierarchy + result += match(index(0, column, parent), role, + (text.isEmpty() ? value : text), + (allHits ? -1 : hits - result.count()), flags); + } } } // prepare for the next iteration diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index c34876d1d6..496f583c22 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -57,12 +57,12 @@ class Q_CORE_EXPORT QModelIndex { friend class QAbstractItemModel; public: - Q_DECL_CONSTEXPR inline QModelIndex() Q_DECL_NOTHROW : r(-1), c(-1), i(0), m(nullptr) {} + Q_DECL_CONSTEXPR inline QModelIndex() noexcept : r(-1), c(-1), i(0), m(nullptr) {} // compiler-generated copy/move ctors/assignment operators are fine! - 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<void*>(i); } + Q_DECL_CONSTEXPR inline int row() const noexcept { return r; } + Q_DECL_CONSTEXPR inline int column() const noexcept { return c; } + Q_DECL_CONSTEXPR inline quintptr internalId() const noexcept { return i; } + inline void *internalPointer() const noexcept { return reinterpret_cast<void*>(i); } inline QModelIndex parent() const; inline QModelIndex sibling(int row, int column) const; inline QModelIndex siblingAtColumn(int column) const; @@ -72,13 +72,13 @@ public: #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; } - Q_DECL_CONSTEXPR inline bool isValid() const Q_DECL_NOTHROW { return (r >= 0) && (c >= 0) && (m != nullptr); } - Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline const QAbstractItemModel *model() const noexcept { return m; } + Q_DECL_CONSTEXPR inline bool isValid() const noexcept { return (r >= 0) && (c >= 0) && (m != nullptr); } + Q_DECL_CONSTEXPR inline bool operator==(const QModelIndex &other) const noexcept { 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_NOTHROW + Q_DECL_CONSTEXPR inline bool operator!=(const QModelIndex &other) const noexcept { return !(*this == other); } - Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline bool operator<(const QModelIndex &other) const noexcept { return r < other.r || (r == other.r && (c < other.c @@ -86,9 +86,9 @@ public: || (i == other.i && std::less<const QAbstractItemModel *>()(m, other.m)))))); } private: - inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) Q_DECL_NOTHROW + inline QModelIndex(int arow, int acolumn, void *ptr, const QAbstractItemModel *amodel) noexcept : r(arow), c(acolumn), i(reinterpret_cast<quintptr>(ptr)), m(amodel) {} - Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) Q_DECL_NOTHROW + Q_DECL_CONSTEXPR inline QModelIndex(int arow, int acolumn, quintptr id, const QAbstractItemModel *amodel) noexcept : r(arow), c(acolumn), i(id), m(amodel) {} int r, c; quintptr i; @@ -103,7 +103,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QModelIndex &); class QPersistentModelIndexData; // qHash is a friend, but we can't use default arguments for friends (ยง8.3.6.4) -uint qHash(const QPersistentModelIndex &index, uint seed = 0) Q_DECL_NOTHROW; +uint qHash(const QPersistentModelIndex &index, uint seed = 0) noexcept; class Q_CORE_EXPORT QPersistentModelIndex { @@ -118,12 +118,12 @@ public: { return !operator==(other); } QPersistentModelIndex &operator=(const QPersistentModelIndex &other); #ifdef Q_COMPILER_RVALUE_REFS - inline QPersistentModelIndex(QPersistentModelIndex &&other) Q_DECL_NOTHROW + inline QPersistentModelIndex(QPersistentModelIndex &&other) noexcept : d(other.d) { other.d = nullptr; } - inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other) Q_DECL_NOTHROW + inline QPersistentModelIndex &operator=(QPersistentModelIndex &&other) noexcept { qSwap(d, other.d); return *this; } #endif - inline void swap(QPersistentModelIndex &other) Q_DECL_NOTHROW { qSwap(d, other.d); } + inline void swap(QPersistentModelIndex &other) noexcept { qSwap(d, other.d); } bool operator==(const QModelIndex &other) const; bool operator!=(const QModelIndex &other) const; QPersistentModelIndex &operator=(const QModelIndex &other); @@ -143,14 +143,14 @@ public: bool isValid() const; private: QPersistentModelIndexData *d; - friend uint qHash(const QPersistentModelIndex &, uint seed) Q_DECL_NOTHROW; + friend uint qHash(const QPersistentModelIndex &, uint seed) noexcept; #ifndef QT_NO_DEBUG_STREAM friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QPersistentModelIndex &); #endif }; Q_DECLARE_SHARED(QPersistentModelIndex) -inline uint qHash(const QPersistentModelIndex &index, uint seed) Q_DECL_NOTHROW +inline uint qHash(const QPersistentModelIndex &index, uint seed) noexcept { return qHash(index.d, seed); } @@ -464,7 +464,7 @@ inline QVariant QModelIndex::data(int arole) const inline Qt::ItemFlags QModelIndex::flags() const { return m ? m->flags(*this) : Qt::ItemFlags(); } -inline uint qHash(const QModelIndex &index) Q_DECL_NOTHROW +inline uint qHash(const QModelIndex &index) noexcept { return uint((uint(index.row()) << 4) + index.column() + index.internalId()); } QT_END_NAMESPACE diff --git a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp index a20024f468..0319d215a1 100644 --- a/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp +++ b/src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp @@ -55,7 +55,7 @@ public: struct SourceModelForRowResult { - SourceModelForRowResult() : sourceModel(Q_NULLPTR), sourceRow(-1) {} + SourceModelForRowResult() : sourceModel(nullptr), sourceRow(-1) {} QAbstractItemModel *sourceModel; int sourceRow; }; diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 1c924053a5..e5cd24817b 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -61,9 +61,9 @@ public: inline QItemSelectionRange(const QItemSelectionRange &other) : tl(other.tl), br(other.br) {} # ifdef Q_COMPILER_RVALUE_REFS - QItemSelectionRange(QItemSelectionRange &&other) Q_DECL_NOTHROW + QItemSelectionRange(QItemSelectionRange &&other) noexcept : tl(std::move(other.tl)), br(std::move(other.br)) {} - QItemSelectionRange &operator=(QItemSelectionRange &&other) Q_DECL_NOTHROW + QItemSelectionRange &operator=(QItemSelectionRange &&other) noexcept { tl = std::move(other.tl); br = std::move(other.br); return *this; } # endif QItemSelectionRange &operator=(const QItemSelectionRange &other) @@ -72,7 +72,7 @@ public: QItemSelectionRange(const QModelIndex &topL, const QModelIndex &bottomR) : tl(topL), br(bottomR) {} explicit QItemSelectionRange(const QModelIndex &index) : tl(index), br(tl) {} - void swap(QItemSelectionRange &other) Q_DECL_NOTHROW + void swap(QItemSelectionRange &other) noexcept { qSwap(tl, other.tl); qSwap(br, other.br); @@ -249,7 +249,7 @@ Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QList<QItemSelectionRange>; class Q_CORE_EXPORT QItemSelection : public QList<QItemSelectionRange> { public: - QItemSelection() Q_DECL_NOTHROW : QList<QItemSelectionRange>() {} + QItemSelection() noexcept : QList<QItemSelectionRange>() {} QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight); // reusing QList::swap() here is OK! |