summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-03-18 08:16:20 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-03-19 12:02:24 +0100
commit2fb0135efa97708025dab7654a8b2f1350dc30bf (patch)
tree304e6abe32e206a656757a2a46eb7e4121ce57d6 /src/corelib/tools
parent98cbdae527b360e0e6d630848a375c6a025f572d (diff)
QSize/QPoint: add toSizeF/toPointF()
For symmetry with QSizeF::toSize(). [ChangeLog][QtCore][QSize] Added toSizeF(). [ChangeLog][QtCore][QPoint] Added toPointF(). Task-number: QTBUG-73160 Change-Id: I65b088b4f7365ab671ef2f0c75821b707f5ac26d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qpoint.cpp15
-rw-r--r--src/corelib/tools/qpoint.h7
-rw-r--r--src/corelib/tools/qsize.cpp15
-rw-r--r--src/corelib/tools/qsize.h7
4 files changed, 36 insertions, 8 deletions
diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp
index 80599a4caa..6edb054d0a 100644
--- a/src/corelib/tools/qpoint.cpp
+++ b/src/corelib/tools/qpoint.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.
@@ -381,6 +381,15 @@ QT_BEGIN_NAMESPACE
\sa QPoint::operator/=()
*/
+/*!
+ \fn QPoint::toPointF() const
+ \since 6.4
+
+ Returns this point as a point with floating point accuracy.
+
+ \sa QPointF::toPoint()
+*/
+
/*****************************************************************************
QPoint stream functions
*****************************************************************************/
@@ -532,7 +541,7 @@ size_t qHash(QPoint key, size_t seed) noexcept
Constructs a copy of the given \a point.
- \sa toPoint()
+ \sa toPoint(), QPoint::toPointF()
*/
/*!
@@ -744,7 +753,7 @@ size_t qHash(QPoint key, size_t seed) noexcept
Rounds the coordinates of this point to the nearest integer, and
returns a QPoint object with the rounded coordinates.
- \sa QPointF()
+ \sa QPointF(), QPoint::toPointF()
*/
/*!
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h
index f2c562393a..94870a7211 100644
--- a/src/corelib/tools/qpoint.h
+++ b/src/corelib/tools/qpoint.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.
@@ -48,6 +48,8 @@ struct CGPoint;
QT_BEGIN_NAMESPACE
+class QPointF;
+
class QPoint
{
public:
@@ -110,6 +112,7 @@ public:
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
[[nodiscard]] Q_CORE_EXPORT CGPoint toCGPoint() const noexcept;
#endif
+ [[nodiscard]] constexpr inline QPointF toPointF() const noexcept;
private:
friend class QTransform;
@@ -417,6 +420,8 @@ constexpr inline QPointF &QPointF::operator/=(qreal divisor)
return *this;
}
+constexpr QPointF QPoint::toPointF() const noexcept { return *this; }
+
constexpr inline QPoint QPointF::toPoint() const
{
return QPoint(qRound(xp), qRound(yp));
diff --git a/src/corelib/tools/qsize.cpp b/src/corelib/tools/qsize.cpp
index 2779948aae..4f4ae9e75b 100644
--- a/src/corelib/tools/qsize.cpp
+++ b/src/corelib/tools/qsize.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.
@@ -403,6 +403,15 @@ QSize QSize::scaled(const QSize &s, Qt::AspectRatioMode mode) const noexcept
\sa grownBy()
*/
+/*!
+ \fn QSize::toSizeF() const
+ \since 6.4
+
+ Returns this size as a size with floating point accuracy.
+
+ \sa QSizeF::toSize()
+*/
+
/*****************************************************************************
QSize stream functions
*****************************************************************************/
@@ -520,7 +529,7 @@ QDebug operator<<(QDebug dbg, const QSize &s)
Constructs a size with floating point accuracy from the given \a
size.
- \sa toSize()
+ \sa toSize(), QSize::toSizeF()
*/
/*!
@@ -596,7 +605,7 @@ QDebug operator<<(QDebug dbg, const QSize &s)
Note that the coordinates in the returned size will be rounded to
the nearest integer.
- \sa QSizeF()
+ \sa QSizeF(), QSize::toSizeF()
*/
/*!
diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h
index bab193031c..3411fef33d 100644
--- a/src/corelib/tools/qsize.h
+++ b/src/corelib/tools/qsize.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.
@@ -50,6 +50,7 @@ struct CGSize;
QT_BEGIN_NAMESPACE
+class QSizeF;
class Q_CORE_EXPORT QSize
{
@@ -109,6 +110,8 @@ public:
[[nodiscard]] CGSize toCGSize() const noexcept;
#endif
+ [[nodiscard]] inline constexpr QSizeF toSizeF() const noexcept;
+
private:
int wd;
int ht;
@@ -420,6 +423,8 @@ constexpr inline QSize QSizeF::toSize() const noexcept
return QSize(qRound(wd), qRound(ht));
}
+constexpr QSizeF QSize::toSizeF() const noexcept { return *this; }
+
#ifndef QT_NO_DEBUG_STREAM
Q_CORE_EXPORT QDebug operator<<(QDebug, const QSizeF &);
#endif