QMargins - Add missing operators
Add missing standard operators. [ChangeLog][QtCore][QMargins] Added missing addition and subtraction operators. Change-Id: I6aeed39531a736c12d378a817a9431279da79bc4 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
db352e1e97
commit
9c6447e081
@ -181,6 +181,42 @@ QT_BEGIN_NAMESPACE
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn const QMargins operator+(const QMargins &lhs, int rhs)
|
||||
\relates QMargins
|
||||
|
||||
Returns a QMargins object that is formed by adding \a rhs to
|
||||
\a lhs.
|
||||
|
||||
\sa QMargins::operator+=(), QMargins::operator-=()
|
||||
|
||||
\since 5.3
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn const QMargins operator+(int lhs, const QMargins &rhs)
|
||||
\relates QMargins
|
||||
|
||||
Returns a QMargins object that is formed by adding \a lhs to
|
||||
\a rhs.
|
||||
|
||||
\sa QMargins::operator+=(), QMargins::operator-=()
|
||||
|
||||
\since 5.3
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn const QMargins operator-(const QMargins &lhs, int rhs)
|
||||
\relates QMargins
|
||||
|
||||
Returns a QMargins object that is formed by subtracting \a rhs from
|
||||
\a lhs.
|
||||
|
||||
\sa QMargins::operator+=(), QMargins::operator-=()
|
||||
|
||||
\since 5.3
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn const QMargins operator*(const QMargins &margins, int factor)
|
||||
\relates QMargins
|
||||
@ -257,6 +293,15 @@ QT_BEGIN_NAMESPACE
|
||||
\since 5.1
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMargins operator+(const QMargins &margins)
|
||||
\relates QMargins
|
||||
|
||||
Returns a QMargin object that is formed from all components of \a margins.
|
||||
|
||||
\since 5.3
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMargins operator-(const QMargins &margins)
|
||||
\relates QMargins
|
||||
|
@ -161,6 +161,24 @@ Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &m1, const QMargins &m
|
||||
m1.right() - m2.right(), m1.bottom() - m2.bottom());
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &lhs, int rhs)
|
||||
{
|
||||
return QMargins(lhs.left() + rhs, lhs.top() + rhs,
|
||||
lhs.right() + rhs, lhs.bottom() + rhs);
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QMargins operator+(int lhs, const QMargins &rhs)
|
||||
{
|
||||
return QMargins(rhs.left() + lhs, rhs.top() + lhs,
|
||||
rhs.right() + lhs, rhs.bottom() + lhs);
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &lhs, int rhs)
|
||||
{
|
||||
return QMargins(lhs.left() - rhs, lhs.top() - rhs,
|
||||
lhs.right() - rhs, lhs.bottom() - rhs);
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QMargins operator*(const QMargins &margins, int factor)
|
||||
{
|
||||
return QMargins(margins.left() * factor, margins.top() * factor,
|
||||
@ -245,6 +263,11 @@ inline QMargins &QMargins::operator/=(qreal divisor)
|
||||
return *this = *this / divisor;
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QMargins operator+(const QMargins &margins)
|
||||
{
|
||||
return margins;
|
||||
}
|
||||
|
||||
Q_DECL_CONSTEXPR inline QMargins operator-(const QMargins &margins)
|
||||
{
|
||||
return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
|
||||
|
@ -123,6 +123,13 @@ void tst_QMargins::operators()
|
||||
QCOMPARE(a, halved);
|
||||
|
||||
QCOMPARE(m1 + (-m1), QMargins());
|
||||
|
||||
QMargins m3 = QMargins(10, 11, 12, 13);
|
||||
QCOMPARE(m3 + 1, QMargins(11, 12, 13, 14));
|
||||
QCOMPARE(1 + m3, QMargins(11, 12, 13, 14));
|
||||
QCOMPARE(m3 - 1, QMargins(9, 10, 11, 12));
|
||||
QCOMPARE(+m3, QMargins(10, 11, 12, 13));
|
||||
QCOMPARE(-m3, QMargins(-10, -11, -12, -13));
|
||||
}
|
||||
|
||||
// Testing QDataStream operators
|
||||
|
Loading…
Reference in New Issue
Block a user