Add qHash implementations for QRect and QSize

We need them to implement qHash for QQuickPixmapKey.

Change-Id: Ia67de25ec0068b9e1b889bc9c6ee077e24eb71a8
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Shawn Rutledge 2020-07-16 17:20:55 +02:00
parent b3c1093751
commit d1d4ea5ddf
2 changed files with 12 additions and 0 deletions

View File

@ -40,6 +40,7 @@
#ifndef QRECT_H
#define QRECT_H
#include <QtCore/qhashfunctions.h>
#include <QtCore/qmargins.h>
#include <QtCore/qsize.h>
#include <QtCore/qpoint.h>
@ -147,6 +148,7 @@ public:
friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &) noexcept;
friend Q_DECL_CONSTEXPR inline bool operator!=(const QRect &, const QRect &) noexcept;
friend Q_DECL_CONSTEXPR inline size_t qHash(const QRect &, size_t) noexcept;
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
Q_REQUIRED_RESULT CGRect toCGRect() const noexcept;
@ -456,6 +458,11 @@ Q_DECL_CONSTEXPR inline bool operator!=(const QRect &r1, const QRect &r2) noexce
return r1.x1!=r2.x1 || r1.x2!=r2.x2 || r1.y1!=r2.y1 || r1.y2!=r2.y2;
}
Q_DECL_CONSTEXPR inline size_t qHash(const QRect &r, size_t seed = 0) noexcept
{
return qHashMulti(seed, r.x1, r.x2, r.y1, r.y2);
}
Q_DECL_CONSTEXPR inline QRect operator+(const QRect &rectangle, const QMargins &margins) noexcept
{
return QRect(QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),

View File

@ -41,6 +41,7 @@
#define QSIZE_H
#include <QtCore/qnamespace.h>
#include <QtCore/qhashfunctions.h>
#include <QtCore/qmargins.h>
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
@ -90,6 +91,7 @@ public:
friend inline Q_DECL_CONSTEXPR bool operator==(const QSize &, const QSize &) noexcept;
friend inline Q_DECL_CONSTEXPR bool operator!=(const QSize &, const QSize &) noexcept;
friend inline Q_DECL_CONSTEXPR size_t qHash(const QSize &, size_t) noexcept;
friend inline Q_DECL_CONSTEXPR const QSize operator+(const QSize &, const QSize &) noexcept;
friend inline Q_DECL_CONSTEXPR const QSize operator-(const QSize &, const QSize &) noexcept;
friend inline Q_DECL_CONSTEXPR const QSize operator*(const QSize &, qreal) noexcept;
@ -178,6 +180,9 @@ Q_DECL_CONSTEXPR inline bool operator==(const QSize &s1, const QSize &s2) noexce
Q_DECL_CONSTEXPR inline bool operator!=(const QSize &s1, const QSize &s2) noexcept
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
Q_DECL_CONSTEXPR inline size_t qHash(const QSize &s, size_t seed = 0) noexcept
{ return qHashMulti(seed, s.wd, s.ht); }
Q_DECL_CONSTEXPR inline const QSize operator+(const QSize & s1, const QSize & s2) noexcept
{ return QSize(s1.wd+s2.wd, s1.ht+s2.ht); }