summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-04-16 15:49:14 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-04-24 17:40:09 +0200
commit5d32552cf40d8ec15ed313f71559444c8765efd2 (patch)
tree023d5ec3cbb4d135dd6c2a2002c460e2e7437c51
parentfd894fd68edf3d67975cda8eb9dda43646887b0d (diff)
Move QMargins operator| into qmargins.h, add equivalent for QMarginsF
Addresses FIXME comment in qwidget.cpp, where the operator is being used. Add documentation, make constexpr and add noexcept as for the other operators. As a drive-by, remove invalid const from return type in the documentation of the other operators. They all return a non-const QMargins object. Change-Id: I5a9ca82978d38acd02e03ec00ca202fe1b8cf6c1 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/corelib/tools/qmargins.cpp47
-rw-r--r--src/corelib/tools/qmargins.h12
-rw-r--r--src/widgets/kernel/qwidget.cpp8
3 files changed, 48 insertions, 19 deletions
diff --git a/src/corelib/tools/qmargins.cpp b/src/corelib/tools/qmargins.cpp
index 74be7bb2ba..2d7816e217 100644
--- a/src/corelib/tools/qmargins.cpp
+++ b/src/corelib/tools/qmargins.cpp
@@ -157,7 +157,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator+(const QMargins &m1, const QMargins &m2)
+ \fn QMargins operator+(const QMargins &m1, const QMargins &m2)
\relates QMargins
Returns a QMargins object that is the sum of the given margins, \a m1
@@ -169,7 +169,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator-(const QMargins &m1, const QMargins &m2)
+ \fn QMargins operator-(const QMargins &m1, const QMargins &m2)
\relates QMargins
Returns a QMargins object that is formed by subtracting \a m2 from
@@ -181,7 +181,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator+(const QMargins &lhs, int rhs)
+ \fn QMargins operator+(const QMargins &lhs, int rhs)
\relates QMargins
Returns a QMargins object that is formed by adding \a rhs to
@@ -193,7 +193,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator+(int lhs, const QMargins &rhs)
+ \fn QMargins operator+(int lhs, const QMargins &rhs)
\relates QMargins
Returns a QMargins object that is formed by adding \a lhs to
@@ -205,7 +205,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator-(const QMargins &lhs, int rhs)
+ \fn QMargins operator-(const QMargins &lhs, int rhs)
\relates QMargins
Returns a QMargins object that is formed by subtracting \a rhs from
@@ -217,7 +217,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator*(const QMargins &margins, int factor)
+ \fn QMargins operator*(const QMargins &margins, int factor)
\relates QMargins
Returns a QMargins object that is formed by multiplying each component
@@ -229,7 +229,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator*(int factor, const QMargins &margins)
+ \fn QMargins operator*(int factor, const QMargins &margins)
\relates QMargins
\overload
@@ -242,7 +242,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator*(const QMargins &margins, qreal factor)
+ \fn QMargins operator*(const QMargins &margins, qreal factor)
\relates QMargins
\overload
@@ -255,7 +255,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator*(qreal factor, const QMargins &margins)
+ \fn QMargins operator*(qreal factor, const QMargins &margins)
\relates QMargins
\overload
@@ -268,7 +268,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator/(const QMargins &margins, int divisor)
+ \fn QMargins operator/(const QMargins &margins, int divisor)
\relates QMargins
Returns a QMargins object that is formed by dividing the components of
@@ -280,7 +280,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn const QMargins operator/(const QMargins &, qreal)
+ \fn QMargins operator/(const QMargins &, qreal)
\relates QMargins
\overload
@@ -311,6 +311,18 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn QMargins operator|(const QMargins &m1, const QMargins &m2)
+ \relates QMargins
+
+ Returns a QMargins object that is formed from the maximum of each
+ component of \a m2 and a m1.
+
+ \sa QMargins::operator+=(), QMargins::operator-=()
+
+ \since 6.0
+*/
+
+/*!
\fn QMargins &QMargins::operator+=(const QMargins &margins)
Add each component of \a margins to the respective component of this object
@@ -651,6 +663,19 @@ QDebug operator<<(QDebug dbg, const QMargins &m)
*/
/*!
+ \fn QMargins operator|(const QMargins &m1, const QMargins &m2)
+ \relates QMarginsF
+ \overload
+
+ Returns a QMarginsF object that is formed from the maximum of each
+ component of \a m2 and a m1.
+
+ \sa QMarginsF::operator+=(), QMarginsF::operator-=()
+
+ \since 6.0
+*/
+
+/*!
\fn QMarginsF operator+(const QMarginsF &margins)
\relates QMarginsF
diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h
index 447037daaa..bc1fa3cb61 100644
--- a/src/corelib/tools/qmargins.h
+++ b/src/corelib/tools/qmargins.h
@@ -216,6 +216,12 @@ Q_DECL_CONSTEXPR inline QMargins operator/(const QMargins &margins, qreal diviso
qRound(margins.right() / divisor), qRound(margins.bottom() / divisor));
}
+Q_DECL_CONSTEXPR inline QMargins operator|(const QMargins &m1, const QMargins &m2) noexcept
+{
+ return QMargins(qMax(m1.left(), m2.left()), qMax(m1.top(), m2.top()),
+ qMax(m1.right(), m2.right()), qMax(m1.bottom(), m2.bottom()));
+}
+
Q_DECL_RELAXED_CONSTEXPR inline QMargins &QMargins::operator+=(const QMargins &margins) noexcept
{
return *this = *this + margins;
@@ -430,6 +436,12 @@ Q_DECL_CONSTEXPR inline QMarginsF operator/(const QMarginsF &lhs, qreal divisor)
lhs.right() / divisor, lhs.bottom() / divisor);
}
+Q_DECL_CONSTEXPR inline QMarginsF operator|(const QMarginsF &m1, const QMarginsF &m2) noexcept
+{
+ return QMarginsF(qMax(m1.left(), m2.left()), qMax(m1.top(), m2.top()),
+ qMax(m1.right(), m2.right()), qMax(m1.bottom(), m2.bottom()));
+}
+
Q_DECL_RELAXED_CONSTEXPR inline QMarginsF &QMarginsF::operator+=(const QMarginsF &margins) noexcept
{
return *this = *this + margins;
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 06080a0f42..d7cb7e2f10 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -7414,14 +7414,6 @@ void QWidgetPrivate::updateContentsRect()
QCoreApplication::sendEvent(q, &e);
}
-
-// FIXME: Move to qmargins.h for next minor Qt release
-QMargins operator|(const QMargins &m1, const QMargins &m2)
-{
- return QMargins(qMax(m1.left(), m2.left()), qMax(m1.top(), m2.top()),
- qMax(m1.right(), m2.right()), qMax(m1.bottom(), m2.bottom()));
-}
-
/*!
\since 4.6