summaryrefslogtreecommitdiff
path: root/src/positioning
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-03-01 14:07:24 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2016-03-02 09:26:47 +0000
commit3a079a1e6761f3a26223e360d22530f22b5aeade (patch)
tree3f97878218a5645a5f7ee836419ba2936028d7a9 /src/positioning
parenta6ce801018a4254efeab000efa2457317270939b (diff)
downloadqtlocation-3a079a1e6761f3a26223e360d22530f22b5aeade.tar.gz
Add hash function for QGeoCoordinate
[ChangeLog][QtPositioning][General] Added qHash(QGeoCoordinate()). Task-number: QTBUG-51404 Change-Id: I02c6dc0a5399ebf3181b34ffa58a82a2119118a0 Reviewed-by: Paolo Angelelli <paolo.angelelli@theqtcompany.com> Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com>
Diffstat (limited to 'src/positioning')
-rw-r--r--src/positioning/qgeocoordinate.cpp17
-rw-r--r--src/positioning/qgeocoordinate.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/src/positioning/qgeocoordinate.cpp b/src/positioning/qgeocoordinate.cpp
index c71422ca..f28e1865 100644
--- a/src/positioning/qgeocoordinate.cpp
+++ b/src/positioning/qgeocoordinate.cpp
@@ -762,4 +762,21 @@ QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate)
}
#endif
+/*! \fn uint qHash(const QGeoCoordinate &coordinate, uint seed = 0)
+ \relates QHash
+ \since Qt 5.7
+
+ Returns a hash value for \a coordinate, using \a seed to seed the calculation.
+*/
+uint qHash(const QGeoCoordinate &coordinate, uint seed)
+{
+ QtPrivate::QHashCombine hash;
+ // north and south pole are geographically equivalent (no matter the longitude)
+ if (coordinate.latitude() != 90.0 && coordinate.latitude() != -90.0)
+ seed = hash(seed, coordinate.longitude());
+ seed = hash(seed, coordinate.latitude());
+ seed = hash(seed, coordinate.altitude());
+ return seed;
+}
+
QT_END_NAMESPACE
diff --git a/src/positioning/qgeocoordinate.h b/src/positioning/qgeocoordinate.h
index 7b7a4c1f..ddb6274e 100644
--- a/src/positioning/qgeocoordinate.h
+++ b/src/positioning/qgeocoordinate.h
@@ -122,6 +122,8 @@ Q_DECLARE_TYPEINFO(QGeoCoordinate, Q_MOVABLE_TYPE);
Q_POSITIONING_EXPORT QDebug operator<<(QDebug, const QGeoCoordinate &);
#endif
+Q_POSITIONING_EXPORT uint qHash(const QGeoCoordinate &coordinate, uint seed = 0);
+
#ifndef QT_NO_DATASTREAM
Q_POSITIONING_EXPORT QDataStream &operator<<(QDataStream &stream, const QGeoCoordinate &coordinate);
Q_POSITIONING_EXPORT QDataStream &operator>>(QDataStream &stream, QGeoCoordinate &coordinate);