From f9063758cb0140f10fb304a635551859039a569e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 8 Apr 2015 19:45:45 +0200 Subject: Add qHash(QUrlQuery) QUrlQueries can be compared for equality, so qHash should be overloaded, too. [ChangeLog][QtCore][QUrlQuery] Added qHash(QUrlQuery). Change-Id: I626258a938359b49a0cae02012b6cba5ef1fe784 Reviewed-by: Thiago Macieira --- src/corelib/io/qurlquery.cpp | 21 +++++++++++++++++++++ src/corelib/io/qurlquery.h | 3 +++ 2 files changed, 24 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp index 77d1ab3e24..91e6e21e20 100644 --- a/src/corelib/io/qurlquery.cpp +++ b/src/corelib/io/qurlquery.cpp @@ -34,6 +34,7 @@ #include "qurlquery.h" #include "qurl_p.h" +#include #include QT_BEGIN_NAMESPACE @@ -407,12 +408,32 @@ bool QUrlQuery::operator ==(const QUrlQuery &other) const if (d == other.d) return true; if (d && other.d) + // keep in sync with qHash(QUrlQuery): return d->valueDelimiter == other.d->valueDelimiter && d->pairDelimiter == other.d->pairDelimiter && d->itemList == other.d->itemList; return false; } +/*! + \since 5.6 + \relates QUrlQuery + + Returns the hash value for \a key, + using \a seed to seed the calculation. +*/ +uint qHash(const QUrlQuery &key, uint seed) Q_DECL_NOTHROW +{ + if (const QUrlQueryPrivate *d = key.d) { + QtPrivate::QHashCombine hash; + // keep in sync with operator==: + seed = hash(seed, d->valueDelimiter); + seed = hash(seed, d->pairDelimiter); + seed = hash(seed, d->itemList); + } + return seed; +} + /*! Returns \c true if this QUrlQuery object contains no key-value pairs, such as after being default-constructed or after parsing an empty query string. diff --git a/src/corelib/io/qurlquery.h b/src/corelib/io/qurlquery.h index 77a0b4a82d..21962fcb22 100644 --- a/src/corelib/io/qurlquery.h +++ b/src/corelib/io/qurlquery.h @@ -44,6 +44,8 @@ QT_BEGIN_NAMESPACE +Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed = 0) Q_DECL_NOTHROW; + class QUrlQueryPrivate; class Q_CORE_EXPORT QUrlQuery { @@ -95,6 +97,7 @@ public: private: friend class QUrl; + friend Q_CORE_EXPORT uint qHash(const QUrlQuery &key, uint seed) Q_DECL_NOTHROW; QSharedDataPointer d; public: typedef QSharedDataPointer DataPtr; -- cgit v1.2.3