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>
This commit is contained in:
Marc Mutz 2015-04-08 19:45:45 +02:00
parent 5fdc64f566
commit f9063758cb
3 changed files with 27 additions and 0 deletions

View File

@ -34,6 +34,7 @@
#include "qurlquery.h"
#include "qurl_p.h"
#include <QtCore/qhashfunctions.h>
#include <QtCore/qstringlist.h>
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.

View File

@ -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;

View File

@ -177,6 +177,7 @@ void tst_QUrlQuery::constructing()
QVERIFY(copy.isEmpty());
QVERIFY(!copy.isDetached());
QVERIFY(copy == empty);
QCOMPARE(qHash(copy), qHash(empty));
QVERIFY(!(copy != empty));
copy = empty;
@ -184,6 +185,7 @@ void tst_QUrlQuery::constructing()
copy = QUrlQuery();
QVERIFY(copy == empty);
QCOMPARE(qHash(copy), qHash(empty));
}
{
QUrlQuery copy(emptyQuery());
@ -298,6 +300,7 @@ void tst_QUrlQuery::addRemove()
QVERIFY(query == original);
QVERIFY(!(query != original));
QCOMPARE(qHash(query), qHash(original));
}
{