mirror of https://github.com/qt/qtbase.git
Add qHash(QLocale)
QLocales can be compared for equality, so qHash should be overloaded, too. [ChangeLog][QtCore][QLocale] Added qHash(QLocale). Change-Id: Ia0fdf1207b842b9bb20b8f9ab0165016915debf4 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
82e442a26b
commit
1be6bad232
|
@ -42,6 +42,7 @@
|
|||
|
||||
#include "qdatastream.h"
|
||||
#include "qdebug.h"
|
||||
#include "qhashfunctions.h"
|
||||
#include "qstring.h"
|
||||
#include "qlocale.h"
|
||||
#include "qlocale_p.h"
|
||||
|
@ -865,6 +866,21 @@ bool QLocale::operator!=(const QLocale &other) const
|
|||
return d->m_data != other.d->m_data || d->m_numberOptions != other.d->m_numberOptions;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.6
|
||||
\relates QLocale
|
||||
|
||||
Returns the hash value for \a key, using
|
||||
\a seed to seed the calculation.
|
||||
*/
|
||||
uint qHash(const QLocale &key, uint seed) Q_DECL_NOTHROW
|
||||
{
|
||||
QtPrivate::QHashCombine hash;
|
||||
seed = hash(seed, key.d->m_data);
|
||||
seed = hash(seed, key.d->m_numberOptions);
|
||||
return seed;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 4.2
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ QT_BEGIN_NAMESPACE
|
|||
class QDataStream;
|
||||
class QDate;
|
||||
class QDateTime;
|
||||
class QLocale;
|
||||
class QTime;
|
||||
class QVariant;
|
||||
class QTextStream;
|
||||
|
@ -52,6 +53,8 @@ class QTextStreamPrivate;
|
|||
|
||||
class QLocalePrivate;
|
||||
|
||||
Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed = 0) Q_DECL_NOTHROW;
|
||||
|
||||
class Q_CORE_EXPORT QLocale
|
||||
{
|
||||
Q_GADGET
|
||||
|
@ -979,6 +982,8 @@ public:
|
|||
private:
|
||||
QLocale(QLocalePrivate &dd);
|
||||
friend class QLocalePrivate;
|
||||
friend Q_CORE_EXPORT uint qHash(const QLocale &key, uint seed) Q_DECL_NOTHROW;
|
||||
|
||||
QSharedDataPointer<QLocalePrivate> d;
|
||||
};
|
||||
Q_DECLARE_TYPEINFO(QLocale, Q_MOVABLE_TYPE);
|
||||
|
|
|
@ -371,6 +371,8 @@ void tst_QLocale::ctor()
|
|||
QString("requested: \"" + QString(req_lc) + "\", got: " \
|
||||
+ QLocale::languageToString(l.language()) \
|
||||
+ "/" + QLocale::countryToString(l.country())).toLatin1().constData()); \
|
||||
QCOMPARE(l, QLocale(QLocale::exp_lang, QLocale::exp_country)); \
|
||||
QCOMPARE(qHash(l), qHash(QLocale(QLocale::exp_lang, QLocale::exp_country))); \
|
||||
}
|
||||
|
||||
QLocale::setDefault(QLocale(QLocale::C));
|
||||
|
|
Loading…
Reference in New Issue