diff options
author | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-02-17 17:51:49 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2016-02-17 19:57:54 +0000 |
commit | 86c5a337e3b123f2e41c8b15b416f39655519acd (patch) | |
tree | efa0f720a190889b3d31ddbd07cee0495b8a15d4 /src/corelib/tools | |
parent | 47ca3f78139ad51a5018dcdad27fa5caf817f08d (diff) | |
parent | 6620045fcaada61a2897195f32c0ee35beebc37b (diff) |
Merge "Merge dev into 5.7" into refs/staging/5.7
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qhash.cpp | 13 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 35 | ||||
-rw-r--r-- | src/corelib/tools/qrect.cpp | 28 | ||||
-rw-r--r-- | src/corelib/tools/qrect.h | 9 |
4 files changed, 85 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index c1a1b9715f..b49c9d683a 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -1803,6 +1803,19 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW returns \c false. */ +/*! \fn QPair<iterator, iterator> QHash::equal_range(const Key &key) + \since 5.7 + + Returns a pair of iterators delimiting the range of values \c{[first, second)}, that + are stored under \a key. If the range is empty then both iterators will be equal to end(). +*/ + +/*! + \fn QPair<const_iterator, const_iterator> QHash::equal_range(const Key &key) const + \overload + \since 5.7 +*/ + /*! \typedef QHash::ConstIterator Qt-style synonym for QHash::const_iterator. diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 819631932b..5e3016d313 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -458,6 +458,8 @@ public: inline key_iterator keyBegin() const { return key_iterator(begin()); } inline key_iterator keyEnd() const { return key_iterator(end()); } + QPair<iterator, iterator> equal_range(const Key &key); + QPair<const_iterator, const_iterator> equal_range(const Key &key) const Q_DECL_NOTHROW; iterator erase(iterator it) { return erase(const_iterator(it.i)); } iterator erase(const_iterator it); @@ -945,6 +947,39 @@ Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash &other) const } template <class Key, class T> +QPair<typename QHash<Key, T>::iterator, typename QHash<Key, T>::iterator> QHash<Key, T>::equal_range(const Key &akey) +{ + detach(); + auto pair = qAsConst(*this).equal_range(akey); + return qMakePair(iterator(pair.first.i), iterator(pair.second.i)); +} + +template <class Key, class T> +QPair<typename QHash<Key, T>::const_iterator, typename QHash<Key, T>::const_iterator> QHash<Key, T>::equal_range(const Key &akey) const Q_DECL_NOTHROW +{ + uint h; + Node *node = *findNode(akey, &h); + const_iterator firstIt = const_iterator(node); + + if (node != e) { + // equal keys must hash to the same value and so they all + // end up in the same bucket. So we can use node->next, + // which only works within a bucket, instead of (out-of-line) + // QHashData::nextNode() + while (node->next != e && node->next->key == akey) + node = node->next; + + // 'node' may be the last node in the bucket. To produce the end iterator, we'd + // need to enter the next bucket in this case, so we need to use + // QHashData::nextNode() here, which, unlike node->next above, can move between + // buckets. + node = concrete(QHashData::nextNode(reinterpret_cast<QHashData::Node *>(node))); + } + + return qMakePair(firstIt, const_iterator(node)); +} + +template <class Key, class T> class QMultiHash : public QHash<Key, T> { public: diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index 6215c534f8..4b6183646b 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -706,6 +706,20 @@ QRect QRect::normalized() const Q_DECL_NOTHROW current position. */ +/*! + \fn QRect QRect::transposed() const + \since 5.7 + + Returns a copy of the rectangle that has its width and height + exchanged: + + \code + QRect r = {15, 51, 42, 24}; + r = r.transposed(); // r == {15, 51, 24, 42} + \endcode + + \sa QSize::transposed() +*/ /*! \fn void QRect::setRect(int x, int y, int width, int height) @@ -1842,6 +1856,20 @@ QRectF QRectF::normalized() const Q_DECL_NOTHROW current position. */ +/*! + \fn QRectF QRectF::transposed() const + \since 5.7 + + Returns a copy of the rectangle that has its width and height + exchanged: + + \code + QRectF r = {1.5, 5.1, 4.2, 2.4}; + r = r.transposed(); // r == {1.5, 5.1, 2.4, 4.2} + \endcode + + \sa QSizeF::transposed() +*/ /*! \fn void QRectF::setRect(qreal x, qreal y, qreal width, qreal height) diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index e90bb8a21e..31fdc8ce6b 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -102,6 +102,7 @@ public: Q_DECL_RELAXED_CONSTEXPR inline void translate(const QPoint &p) Q_DECL_NOTHROW; Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + Q_DECL_CONSTEXPR inline QRect transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT; Q_DECL_RELAXED_CONSTEXPR inline void moveTo(int x, int t) Q_DECL_NOTHROW; Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPoint &p) Q_DECL_NOTHROW; @@ -284,6 +285,9 @@ Q_DECL_CONSTEXPR inline QRect QRect::translated(int dx, int dy) const Q_DECL_NOT Q_DECL_CONSTEXPR inline QRect QRect::translated(const QPoint &p) const Q_DECL_NOTHROW { return QRect(QPoint(x1 + p.x(), y1 + p.y()), QPoint(x2 + p.x(), y2 + p.y())); } +Q_DECL_CONSTEXPR inline QRect QRect::transposed() const Q_DECL_NOTHROW +{ return QRect(topLeft(), size().transposed()); } + Q_DECL_RELAXED_CONSTEXPR inline void QRect::moveTo(int ax, int ay) Q_DECL_NOTHROW { x2 += ax - x1; @@ -551,6 +555,8 @@ public: Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + Q_DECL_CONSTEXPR inline QRectF transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + Q_DECL_RELAXED_CONSTEXPR inline void moveTo(qreal x, qreal y) Q_DECL_NOTHROW; Q_DECL_RELAXED_CONSTEXPR inline void moveTo(const QPointF &p) Q_DECL_NOTHROW; @@ -751,6 +757,9 @@ Q_DECL_CONSTEXPR inline QRectF QRectF::translated(qreal dx, qreal dy) const Q_DE Q_DECL_CONSTEXPR inline QRectF QRectF::translated(const QPointF &p) const Q_DECL_NOTHROW { return QRectF(xp + p.x(), yp + p.y(), w, h); } +Q_DECL_CONSTEXPR inline QRectF QRectF::transposed() const Q_DECL_NOTHROW +{ return QRectF(topLeft(), size().transposed()); } + Q_DECL_RELAXED_CONSTEXPR inline void QRectF::getRect(qreal *ax, qreal *ay, qreal *aaw, qreal *aah) const { *ax = this->xp; |