diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-04-08 19:45:45 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-04-20 07:41:56 +0000 |
commit | f9063758cb0140f10fb304a635551859039a569e (patch) | |
tree | 918cdd294104e50f3ca0c8b70e0d2036c0a3f6a3 /src/corelib/io | |
parent | 5fdc64f5666d094e34e1373e75ae6e50239d9622 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qurlquery.cpp | 21 | ||||
-rw-r--r-- | src/corelib/io/qurlquery.h | 3 |
2 files changed, 24 insertions, 0 deletions
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 <QtCore/qhashfunctions.h> #include <QtCore/qstringlist.h> QT_BEGIN_NAMESPACE @@ -407,6 +408,7 @@ 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; @@ -414,6 +416,25 @@ bool QUrlQuery::operator ==(const QUrlQuery &other) const } /*! + \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<QUrlQueryPrivate> d; public: typedef QSharedDataPointer<QUrlQueryPrivate> DataPtr; |