diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-07-26 15:19:56 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-07-27 16:39:45 +0200 |
commit | cc6d520ee633d15b18724e3b7e6ecff25570dd0d (patch) | |
tree | d28209d102ae33c905badf17f7e355a93ef57a88 /src | |
parent | 8cdcf2533e5eba41f22c897bac670bd5ec9a636e (diff) | |
download | qtlocation-cc6d520ee633d15b18724e3b7e6ecff25570dd0d.tar.gz |
Add qHash overloads to QGeoShape hierarchy
This patch adds qHash overloads to QGeoShape hierarchy, allowing to use
the classes as keys in QHash.
Note that the actual qHash overload is required only for the base type.
All the derived classes are correctly hashed using the virtual method
in private d_ptr.
Task-number: QTBUG-95163
Pick-to: 6.2
Change-Id: I186f9d396e698187ebf0363d96c19e324db10905
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/positioning/qgeocircle.cpp | 5 | ||||
-rw-r--r-- | src/positioning/qgeocircle_p.h | 2 | ||||
-rw-r--r-- | src/positioning/qgeopath.cpp | 6 | ||||
-rw-r--r-- | src/positioning/qgeopath_p.h | 1 | ||||
-rw-r--r-- | src/positioning/qgeopolygon.cpp | 7 | ||||
-rw-r--r-- | src/positioning/qgeopolygon_p.h | 1 | ||||
-rw-r--r-- | src/positioning/qgeorectangle.cpp | 5 | ||||
-rw-r--r-- | src/positioning/qgeorectangle_p.h | 2 | ||||
-rw-r--r-- | src/positioning/qgeoshape.cpp | 15 | ||||
-rw-r--r-- | src/positioning/qgeoshape.h | 3 | ||||
-rw-r--r-- | src/positioning/qgeoshape_p.h | 2 |
11 files changed, 49 insertions, 0 deletions
diff --git a/src/positioning/qgeocircle.cpp b/src/positioning/qgeocircle.cpp index f1ad77d7..195736e5 100644 --- a/src/positioning/qgeocircle.cpp +++ b/src/positioning/qgeocircle.cpp @@ -483,4 +483,9 @@ bool QGeoCirclePrivate::operator==(const QGeoShapePrivate &other) const return m_radius == otherCircle.m_radius && m_center == otherCircle.m_center; } +size_t QGeoCirclePrivate::hash(size_t seed) const +{ + return qHashMulti(seed, m_center, m_radius); +} + QT_END_NAMESPACE diff --git a/src/positioning/qgeocircle_p.h b/src/positioning/qgeocircle_p.h index 5e957f6f..65f1d9d1 100644 --- a/src/positioning/qgeocircle_p.h +++ b/src/positioning/qgeocircle_p.h @@ -84,6 +84,8 @@ public: bool operator==(const QGeoShapePrivate &other) const override; + size_t hash(size_t seed) const override; + QGeoCoordinate m_center; qreal m_radius; QGeoRectangle m_bbox; diff --git a/src/positioning/qgeopath.cpp b/src/positioning/qgeopath.cpp index 36c537c7..9f327bd8 100644 --- a/src/positioning/qgeopath.cpp +++ b/src/positioning/qgeopath.cpp @@ -609,6 +609,12 @@ QGeoRectangle QGeoPathPrivate::boundingGeoRectangle() const return m_bbox; } +size_t QGeoPathPrivate::hash(size_t seed) const +{ + const size_t res = qHashRange(m_path.cbegin(), m_path.cend(), seed); + return qHashMulti(seed, res, m_width); +} + void QGeoPathPrivate::setPath(const QList<QGeoCoordinate> &path) { for (const QGeoCoordinate &c: path) diff --git a/src/positioning/qgeopath_p.h b/src/positioning/qgeopath_p.h index 3b7a1777..64abb621 100644 --- a/src/positioning/qgeopath_p.h +++ b/src/positioning/qgeopath_p.h @@ -184,6 +184,7 @@ public: virtual bool operator==(const QGeoShapePrivate &other) const override; virtual bool contains(const QGeoCoordinate &coordinate) const override; virtual QGeoRectangle boundingGeoRectangle() const override; + size_t hash(size_t seed) const override; // QGeoPathPrivate API virtual const QList<QGeoCoordinate> &path() const; diff --git a/src/positioning/qgeopolygon.cpp b/src/positioning/qgeopolygon.cpp index 71ee2578..073b5b30 100644 --- a/src/positioning/qgeopolygon.cpp +++ b/src/positioning/qgeopolygon.cpp @@ -558,6 +558,13 @@ bool QGeoPolygonPrivate::operator==(const QGeoShapePrivate &other) const return m_path == otherPath.m_path && m_holesList == otherPath.m_holesList; } +size_t QGeoPolygonPrivate::hash(size_t seed) const +{ + const size_t pointsHash = qHashRange(m_path.cbegin(), m_path.cend(), seed); + const size_t holesHash = qHashRange(m_holesList.cbegin(), m_holesList.cend(), seed); + return qHashMulti(seed, pointsHash, holesHash); +} + void QGeoPolygonPrivate::addHole(const QList<QGeoCoordinate> &holePath) { for (const QGeoCoordinate &holeVertex: holePath) diff --git a/src/positioning/qgeopolygon_p.h b/src/positioning/qgeopolygon_p.h index 199a97f7..718f2ddd 100644 --- a/src/positioning/qgeopolygon_p.h +++ b/src/positioning/qgeopolygon_p.h @@ -70,6 +70,7 @@ public: virtual bool contains(const QGeoCoordinate &coordinate) const override; virtual void translate(double degreesLatitude, double degreesLongitude) override; virtual bool operator==(const QGeoShapePrivate &other) const override; + size_t hash(size_t seed) const override; // QGeoPath API virtual void markDirty() override; diff --git a/src/positioning/qgeorectangle.cpp b/src/positioning/qgeorectangle.cpp index c276b40e..24ec22a3 100644 --- a/src/positioning/qgeorectangle.cpp +++ b/src/positioning/qgeorectangle.cpp @@ -1036,5 +1036,10 @@ bool QGeoRectanglePrivate::operator==(const QGeoShapePrivate &other) const return topLeft == otherBox.topLeft && bottomRight == otherBox.bottomRight; } +size_t QGeoRectanglePrivate::hash(size_t seed) const +{ + return qHashMulti(seed, topLeft, bottomRight); +} + QT_END_NAMESPACE diff --git a/src/positioning/qgeorectangle_p.h b/src/positioning/qgeorectangle_p.h index 632fdaa4..79a267f5 100644 --- a/src/positioning/qgeorectangle_p.h +++ b/src/positioning/qgeorectangle_p.h @@ -78,6 +78,8 @@ public: bool operator==(const QGeoShapePrivate &other) const override; + size_t hash(size_t seed) const override; + QGeoCoordinate topLeft; QGeoCoordinate bottomRight; }; diff --git a/src/positioning/qgeoshape.cpp b/src/positioning/qgeoshape.cpp index 58df873b..7ab32b60 100644 --- a/src/positioning/qgeoshape.cpp +++ b/src/positioning/qgeoshape.cpp @@ -429,6 +429,21 @@ QDataStream &QGeoShape::dataStreamIn(QDataStream &stream, QGeoShape &shape) } #endif +/*! + \relates QGeoShape + + Returns the hash value for the \a shape, using \a seed for the + calculation. +*/ +size_t qHash(const QGeoShape &shape, size_t seed) noexcept +{ + if (shape.d_ptr) + return shape.d_ptr->hash(seed); + else + return qHashMulti(seed, shape.type()); +} + QT_END_NAMESPACE #include "moc_qgeoshape.cpp" + diff --git a/src/positioning/qgeoshape.h b/src/positioning/qgeoshape.h index ffabf4dc..f2a9166c 100644 --- a/src/positioning/qgeoshape.h +++ b/src/positioning/qgeoshape.h @@ -119,8 +119,11 @@ private: static QDataStream &dataStreamOut(QDataStream &stream, const QGeoShape &shape); static QDataStream &dataStreamIn(QDataStream &stream, QGeoShape &shape); #endif + friend Q_POSITIONING_EXPORT size_t qHash(const QGeoShape &key, size_t seed) noexcept; }; +Q_POSITIONING_EXPORT size_t qHash(const QGeoShape &shape, size_t seed = 0) noexcept; + Q_DECLARE_TYPEINFO(QGeoShape, Q_RELOCATABLE_TYPE); QT_END_NAMESPACE diff --git a/src/positioning/qgeoshape_p.h b/src/positioning/qgeoshape_p.h index fcc8f8b6..94551c89 100644 --- a/src/positioning/qgeoshape_p.h +++ b/src/positioning/qgeoshape_p.h @@ -75,6 +75,8 @@ public: virtual bool operator==(const QGeoShapePrivate &other) const; + virtual size_t hash(size_t seed) const = 0; + QGeoShape::ShapeType type; }; |