From c52ebb3aba3d771b908c03e3b171af64b6f9058a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 18 Mar 2022 08:16:20 +0100 Subject: QRect: add toRectF() For symmetry with QRectF::toRect(). [ChangeLog][QtCore][QRect] Added toRectF(). Fixes: QTBUG-73160 Change-Id: If2bda64b8fe4bc113191dda927e9bb86ebcb4c69 Reviewed-by: Thiago Macieira --- src/corelib/tools/qrect.cpp | 21 ++++++++++++++++++--- src/corelib/tools/qrect.h | 7 ++++++- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/corelib/tools') 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 -- cgit v1.2.3