diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-03-18 08:16:20 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-03-19 12:02:24 +0100 |
commit | c52ebb3aba3d771b908c03e3b171af64b6f9058a (patch) | |
tree | c43931b9124eabd149bad4a6125fd5b59f6718f2 /src/corelib/tools | |
parent | 5dc570f8b16debfda916b10bb1235aeea9650699 (diff) |
QRect: add toRectF()
For symmetry with QRectF::toRect().
[ChangeLog][QtCore][QRect] Added toRectF().
Fixes: QTBUG-73160
Change-Id: If2bda64b8fe4bc113191dda927e9bb86ebcb4c69
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qrect.cpp | 21 | ||||
-rw-r--r-- | src/corelib/tools/qrect.h | 7 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index 64ccdb20ff..cdde38946f 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -1232,6 +1232,18 @@ bool QRect::intersects(const QRect &r) const noexcept \since 6.0 */ +/*! + \fn QRect::toRectF() const + \since 6.4 + + Returns this rectangle as a rectangle with floating point accuracy. + + \note This function, like the QRectF(QRect) constructor, preserves the + size() of the rectangle, not its bottomRight() corner. + + \sa QRectF::toRect() +*/ + /***************************************************************************** QRect stream functions *****************************************************************************/ @@ -1480,7 +1492,10 @@ QDebug operator<<(QDebug dbg, const QRect &r) Constructs a QRectF rectangle from the given QRect \a rectangle. - \sa toRect() + \note This function, like QRect::toRectF(), preserves the size() of + \a rectangle, not its bottomRight() corner. + + \sa toRect(), QRect::toRectF() */ /*! @@ -2334,7 +2349,7 @@ bool QRectF::intersects(const QRectF &r) const noexcept Returns a QRect based on the values of this rectangle. Note that the coordinates in the returned rectangle are rounded to the nearest integer. - \sa QRectF(), toAlignedRect() + \sa QRectF(), toAlignedRect(), QRect::toRectF() */ /*! diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index 9e64f4d6e8..f034be7007 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -55,6 +55,8 @@ struct CGRect; QT_BEGIN_NAMESPACE +class QRectF; + class Q_CORE_EXPORT QRect { public: @@ -157,6 +159,7 @@ public: #if defined(Q_OS_DARWIN) || defined(Q_QDOC) [[nodiscard]] CGRect toCGRect() const noexcept; #endif + [[nodiscard]] constexpr inline QRectF toRectF() const noexcept; private: int x1; @@ -863,6 +866,8 @@ inline QRectF QRectF::united(const QRectF &r) const noexcept return *this | r; } +constexpr QRectF QRect::toRectF() const noexcept { return *this; } + constexpr inline QRect QRectF::toRect() const noexcept { // This rounding is designed to minimize the maximum possible difference |