From 1563c38a4b46ad427907b544508e888efbac9772 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 3 Aug 2019 09:27:49 +0300 Subject: QPoint/F: add transposed() For symmetry with QSize and QRect and because there were some users in Qt. Port those users. [ChangeLog][QtCore][QPoint/QPointF] Added transposed(). Change-Id: If4f23dbcf7d67983a6b1885e0d1d538115b49e2b Reviewed-by: Edward Welbourne Reviewed-by: Lars Knoll --- src/corelib/tools/qpoint.cpp | 23 +++++++++++++++++++++++ src/corelib/tools/qpoint.h | 4 ++++ 2 files changed, 27 insertions(+) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index e98eaac4fc..432fb33297 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -138,6 +138,17 @@ QT_BEGIN_NAMESPACE \sa y(), setX() */ +/*! + \fn QPoint::transposed() const + \since 5.14 + + Returns a point with x and y coordinates exchanged: + \code + QPoint{1, 2}.transposed() // {2, 1} + \endcode + + \sa x(), y(), setX(), setY() +*/ /*! \fn int &QPoint::rx() @@ -582,6 +593,18 @@ QDebug operator<<(QDebug dbg, const QPointF &p) \sa y(), setX() */ +/*! + \fn QPointF::transposed() const + \since 5.14 + + Returns a point with x and y coordinates exchanged: + \code + QPointF{1.0, 2.0}.transposed() // {2.0, 1.0} + \endcode + + \sa x(), y(), setX(), setY() +*/ + /*! \fn qreal& QPointF::rx() diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index 34df673b93..fe952f95da 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -64,6 +64,8 @@ public: Q_DECL_CONSTEXPR inline int manhattanLength() const; + Q_DECL_CONSTEXPR QPoint transposed() const noexcept { return {yp, xp}; } + Q_DECL_RELAXED_CONSTEXPR inline int &rx(); Q_DECL_RELAXED_CONSTEXPR inline int &ry(); @@ -232,6 +234,8 @@ public: Q_DECL_RELAXED_CONSTEXPR inline void setX(qreal x); Q_DECL_RELAXED_CONSTEXPR inline void setY(qreal y); + Q_DECL_CONSTEXPR QPointF transposed() const noexcept { return {yp, xp}; } + Q_DECL_RELAXED_CONSTEXPR inline qreal &rx(); Q_DECL_RELAXED_CONSTEXPR inline qreal &ry(); -- cgit v1.2.3