summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2026-04-21 17:13:18 +0200
committerMarc Mutz <marc.mutz@qt.io>2026-04-21 19:40:41 +0000
commit1237231616d11bcc9605846064b18030ce464667 (patch)
tree9bf52a344b84938adc3a11ac168c4d60039c2a79
parent04ac244ba4af8213fa71bdf73d80b1f31c749fb0 (diff)
QGeoTileSpec: properly implement qHash()HEADdev
The qHash() overload was missing the seed argument and returned only 32-bits, even on 64-bit platforms, since it was never ported from Qt 5 to Qt 6 style. Fix by rewriting the overload to idiomatic form, to wit: - make it a hidden friend - since it was out-of-line, I opted to add a hash() member function so we don't need to overload - mark as noexcept - add the seed argument and port to size_t - implement using qHashMulti instead of rolling your own combiner - move the implementation beside operator== to enable easy side-by-side comparison for consistency Pick-to: 6.11 6.8 Task-number: QTBUG-145851 Change-Id: I90d1f00ced0d3d24d52d3667de5ad664af14e07c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/location/maps/qgeotilespec.cpp12
-rw-r--r--src/location/maps/qgeotilespec_p.h4
-rw-r--r--src/location/maps/qgeotilespec_p_p.h13
3 files changed, 19 insertions, 10 deletions
diff --git a/src/location/maps/qgeotilespec.cpp b/src/location/maps/qgeotilespec.cpp
index 8249101a..ad68a7d4 100644
--- a/src/location/maps/qgeotilespec.cpp
+++ b/src/location/maps/qgeotilespec.cpp
@@ -99,15 +99,9 @@ bool QGeoTileSpec::isLess(const QGeoTileSpec &rhs) const noexcept
return (*(d.constData()) < *(rhs.d.constData()));
}
-unsigned int qHash(const QGeoTileSpec &spec)
-{
- unsigned int result = (qHash(spec.plugin()) * 13) % 31;
- result += ((spec.mapId() * 17) % 31) << 5;
- result += ((spec.zoom() * 19) % 31) << 10;
- result += ((spec.x() * 23) % 31) << 15;
- result += ((spec.y() * 29) % 31) << 20;
- result += (spec.version() % 3) << 25;
- return result;
+size_t QGeoTileSpec::hash(size_t seed) const noexcept
+{
+ return d->hash(seed);
}
QDebug operator<< (QDebug dbg, const QGeoTileSpec &spec)
diff --git a/src/location/maps/qgeotilespec_p.h b/src/location/maps/qgeotilespec_p.h
index 91b5d76c..27365f1c 100644
--- a/src/location/maps/qgeotilespec_p.h
+++ b/src/location/maps/qgeotilespec_p.h
@@ -72,9 +72,11 @@ private:
bool isEqual(const QGeoTileSpec &rhs) const noexcept;
bool isLess(const QGeoTileSpec &rhs) const noexcept;
+ size_t hash(size_t seed) const noexcept;
+ friend size_t qHash(const QGeoTileSpec &key, size_t seed = 0) noexcept
+ { return key.hash(seed); }
};
-Q_LOCATION_EXPORT unsigned int qHash(const QGeoTileSpec &spec);
Q_LOCATION_EXPORT QDebug operator<<(QDebug, const QGeoTileSpec &);
diff --git a/src/location/maps/qgeotilespec_p_p.h b/src/location/maps/qgeotilespec_p_p.h
index 0f1c2314..cf07b1f7 100644
--- a/src/location/maps/qgeotilespec_p_p.h
+++ b/src/location/maps/qgeotilespec_p_p.h
@@ -15,6 +15,7 @@
// We mean it.
//
+#include <QtCore/qhashfunctions.h>
#include <QString>
#include <QSharedData>
@@ -29,6 +30,18 @@ public:
x_(x), y_(y), version_(version)
{}
+
+ size_t hash(size_t seed) const
+ {
+ return qHashMulti(seed,
+ mapId_,
+ zoom_,
+ x_,
+ y_,
+ version_,
+ plugin_);
+ }
+
inline bool operator==(const QGeoTileSpecPrivate &rhs) const
{
return mapId_ == rhs.mapId_