QMatrix, QTransform: restore nothrow move special members

The user-defined copy assignment and (on QMatrix) copy
constructors inhibit the move special member functions.

We cannot do something about it in Qt 5, because these
classes are exported (which they shouldn't be), and
because making them trivially copyable might change
how they are passed to functions by value, so we need
to supply all the missing member functions manually.

Change-Id: I59e480d7ba02cac7e3d654cb3345f541e0701f4c
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
Marc Mutz 2016-02-10 15:43:15 +01:00
parent d55b685d23
commit 4bc923b628
4 changed files with 34 additions and 10 deletions

View File

@ -244,11 +244,11 @@ QMatrix::QMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy)
{
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
Constructs a matrix that is a copy of the given \a matrix.
*/
QMatrix::QMatrix(const QMatrix &matrix)
QMatrix::QMatrix(const QMatrix &matrix) Q_DECL_NOTHROW
: _m11(matrix._m11)
, _m12(matrix._m12)
, _m21(matrix._m21)
@ -257,6 +257,7 @@ QMatrix::QMatrix(const QMatrix &matrix)
, _dy(matrix._dy)
{
}
#endif
/*!
Sets the matrix elements to the specified values, \a m11, \a m12,
@ -1063,10 +1064,11 @@ QMatrix QMatrix::operator *(const QMatrix &m) const
return QMatrix(tm11, tm12, tm21, tm22, tdx, tdy, true);
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
Assigns the given \a matrix's values to this matrix.
*/
QMatrix &QMatrix::operator=(const QMatrix &matrix)
QMatrix &QMatrix::operator=(const QMatrix &matrix) Q_DECL_NOTHROW
{
_m11 = matrix._m11;
_m12 = matrix._m12;
@ -1076,6 +1078,7 @@ QMatrix &QMatrix::operator=(const QMatrix &matrix)
_dy = matrix._dy;
return *this;
}
#endif
/*!
\since 4.2

View File

@ -60,7 +60,16 @@ public:
QMatrix();
QMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
qreal dx, qreal dy);
QMatrix(const QMatrix &matrix);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// ### Qt 6: remove; the compiler-generated ones are fine!
QMatrix &operator=(QMatrix &&other) Q_DECL_NOTHROW // = default
{ memcpy(this, &other, sizeof(QMatrix)); return *this; }
QMatrix &operator=(const QMatrix &) Q_DECL_NOTHROW; // = default
QMatrix(QMatrix &&other) Q_DECL_NOTHROW // = default
{ memcpy(this, &other, sizeof(QMatrix)); }
QMatrix(const QMatrix &other) Q_DECL_NOTHROW; // = default
#endif
void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22,
qreal dx, qreal dy);
@ -106,8 +115,6 @@ public:
QMatrix &operator*=(const QMatrix &);
QMatrix operator*(const QMatrix &o) const;
QMatrix &operator=(const QMatrix &);
operator QVariant() const;
private:

View File

@ -1011,10 +1011,11 @@ QTransform QTransform::operator*(const QTransform &m) const
element of this matrix.
*/
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
Assigns the given \a matrix's values to this matrix.
*/
QTransform & QTransform::operator=(const QTransform &matrix)
QTransform & QTransform::operator=(const QTransform &matrix) Q_DECL_NOTHROW
{
affine._m11 = matrix.affine._m11;
affine._m12 = matrix.affine._m12;
@ -1030,6 +1031,7 @@ QTransform & QTransform::operator=(const QTransform &matrix)
return *this;
}
#endif
/*!
Resets the matrix to an identity matrix, i.e. all elements are set

View File

@ -74,6 +74,19 @@ public:
qreal h22, qreal dx, qreal dy);
explicit QTransform(const QMatrix &mtx);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// ### Qt 6: remove; the compiler-generated ones are fine!
QTransform &operator=(QTransform &&other) Q_DECL_NOTHROW // = default
{ memcpy(this, &other, sizeof(QTransform)); return *this; }
QTransform &operator=(const QTransform &) Q_DECL_NOTHROW; // = default
QTransform(QTransform &&other) Q_DECL_NOTHROW // = default
: affine(Qt::Uninitialized)
{ memcpy(this, &other, sizeof(QTransform)); }
QTransform(const QTransform &other) Q_DECL_NOTHROW // = default
: affine(Qt::Uninitialized)
{ memcpy(this, &other, sizeof(QTransform)); }
#endif
bool isAffine() const;
bool isIdentity() const;
bool isInvertible() const;
@ -124,8 +137,6 @@ public:
QTransform &operator*=(const QTransform &);
QTransform operator*(const QTransform &o) const;
QTransform &operator=(const QTransform &);
operator QVariant() const;
void reset();
@ -180,9 +191,10 @@ private:
mutable uint m_type : 5;
mutable uint m_dirty : 5;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
class Private;
Private *d;
#endif
};
Q_DECLARE_TYPEINFO(QTransform, Q_MOVABLE_TYPE);