diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-04-08 19:44:48 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-04-21 07:28:14 +0000 |
commit | 05d16937935ff830c3266c4a8566feed7fe33dbf (patch) | |
tree | f4f638666520f1d9c935b5cb21440d83120b76eb | |
parent | 299350f668b0077bbb11331320eeb843d3feb126 (diff) | |
download | qtbase-05d16937935ff830c3266c4a8566feed7fe33dbf.tar.gz |
Add qHash(QMatrix) and qHash(QTransform)
QMatrix and QTransform can be compared for equality,
so qHash should be overloaded, too.
[ChangeLog][QtCore][QMatrix] Added qHash(QMatrix).
[ChangeLog][QtCore][QTransform] Added qHash(QTransform).
Change-Id: I1ce925ebe258c9d7e35b68e5ac5c3373f1460c58
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r-- | src/gui/painting/qmatrix.cpp | 24 | ||||
-rw-r--r-- | src/gui/painting/qmatrix.h | 2 | ||||
-rw-r--r-- | src/gui/painting/qtransform.cpp | 24 | ||||
-rw-r--r-- | src/gui/painting/qtransform.h | 2 | ||||
-rw-r--r-- | tests/auto/gui/painting/qtransform/tst_qtransform.cpp | 17 |
5 files changed, 68 insertions, 1 deletions
diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp index acedc6a7ba..e4d756c18d 100644 --- a/src/gui/painting/qmatrix.cpp +++ b/src/gui/painting/qmatrix.cpp @@ -31,9 +31,11 @@ ** ****************************************************************************/ +#include "qmatrix.h" + #include "qdatastream.h" #include "qdebug.h" -#include "qmatrix.h" +#include "qhashfunctions.h" #include "qregion.h" #include "qpainterpath.h" #include "qpainterpath_p.h" @@ -972,6 +974,26 @@ bool QMatrix::operator==(const QMatrix &m) const _dy == m._dy; } + +/*! + \since 5.6 + \relates QMatrix + + Returns the hash value for \a key, using + \a seed to seed the calculation. +*/ +uint qHash(const QMatrix &key, uint seed) Q_DECL_NOTHROW +{ + QtPrivate::QHashCombine hash; + seed = hash(key.m11(), seed); + seed = hash(key.m12(), seed); + seed = hash(key.m21(), seed); + seed = hash(key.m22(), seed); + seed = hash(key.dx(), seed); + seed = hash(key.dy(), seed); + return seed; +} + /*! \fn bool QMatrix::operator!=(const QMatrix &matrix) const diff --git a/src/gui/painting/qmatrix.h b/src/gui/painting/qmatrix.h index ddffa8a8b9..c036e4df93 100644 --- a/src/gui/painting/qmatrix.h +++ b/src/gui/painting/qmatrix.h @@ -126,6 +126,8 @@ private: }; Q_DECLARE_TYPEINFO(QMatrix, Q_MOVABLE_TYPE); +Q_GUI_EXPORT Q_DECL_CONST_FUNCTION uint qHash(const QMatrix &key, uint seed = 0) Q_DECL_NOTHROW; + // mathematical semantics inline QPoint operator*(const QPoint &p, const QMatrix &m) { return m.map(p); } diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index 31d7a2300b..4b3f0b30dc 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -34,6 +34,7 @@ #include "qdatastream.h" #include "qdebug.h" +#include "qhashfunctions.h" #include "qmatrix.h" #include "qregion.h" #include "qpainterpath.h" @@ -776,6 +777,29 @@ bool QTransform::operator==(const QTransform &o) const } /*! + \since 5.6 + \relates QTransform + + Returns the hash value for \a key, using + \a seed to seed the calculation. +*/ +uint qHash(const QTransform &key, uint seed) Q_DECL_NOTHROW +{ + QtPrivate::QHashCombine hash; + seed = hash(key.m11(), seed); + seed = hash(key.m12(), seed); + seed = hash(key.m21(), seed); + seed = hash(key.m22(), seed); + seed = hash(key.dx(), seed); + seed = hash(key.dy(), seed); + seed = hash(key.m13(), seed); + seed = hash(key.m23(), seed); + seed = hash(key.m33(), seed); + return seed; +} + + +/*! \fn bool QTransform::operator!=(const QTransform &matrix) const Returns \c true if this matrix is not equal to the given \a matrix, otherwise returns \c false. diff --git a/src/gui/painting/qtransform.h b/src/gui/painting/qtransform.h index cf8d4d1970..65f543144d 100644 --- a/src/gui/painting/qtransform.h +++ b/src/gui/painting/qtransform.h @@ -180,6 +180,8 @@ private: }; Q_DECLARE_TYPEINFO(QTransform, Q_MOVABLE_TYPE); +Q_GUI_EXPORT Q_DECL_CONST_FUNCTION uint qHash(const QTransform &key, uint seed = 0) Q_DECL_NOTHROW; + /******* inlines *****/ inline QTransform::TransformationType QTransform::inline_type() const { diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp index 13b15d09dd..1327cff1bd 100644 --- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp @@ -57,6 +57,7 @@ private slots: void mapRect(); void assignments(); void mapToPolygon(); + void qhash(); void translate(); void scale(); void matrix(); @@ -361,6 +362,22 @@ void tst_QTransform::mapToPolygon() QVERIFY(equal); } +void tst_QTransform::qhash() +{ + QMatrix m1; + m1.shear(3.0, 2.0); + m1.rotate(44); + + QMatrix m2 = m1; + + QTransform t1(m1); + QTransform t2(m2); + + // not really much to test here, so just the bare minimum: + QCOMPARE(qHash(m1), qHash(m2)); + QCOMPARE(qHash(t1), qHash(t2)); +} + void tst_QTransform::translate() { |