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 | 5dc570f8b16debfda916b10bb1235aeea9650699 (patch) | |
| tree | 3bfbd47a4b67f108fef975436d80341880488ccc /src/corelib | |
| parent | 2fb0135efa97708025dab7654a8b2f1350dc30bf (diff) | |
QLine/QMargins: add toLineF/toMarginsF()
For symmetry with QLineF::toLine().
[ChangeLog][QtCore][QLine] Added toLineF().
[ChangeLog][QtCore][QMargins] Added toMarginsF().
Task-number: QTBUG-73160
Change-Id: I69051cdd2fe4a3c0a000ab86e363a2918a7aea7c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib')
| -rw-r--r-- | src/corelib/tools/qline.cpp | 15 | ||||
| -rw-r--r-- | src/corelib/tools/qline.h | 7 | ||||
| -rw-r--r-- | src/corelib/tools/qmargins.cpp | 15 | ||||
| -rw-r--r-- | src/corelib/tools/qmargins.h | 8 |
4 files changed, 38 insertions, 7 deletions
diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index bbedfa948e5..72a926689bb 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 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. @@ -263,6 +263,15 @@ QT_BEGIN_NAMESPACE \sa setP1(), setP2(), p1(), p2() */ +/*! + \fn QLine::toLineF() const + \since 6.4 + + Returns this line as a line with floating point accuracy. + + \sa QLineF::toLine() +*/ + #ifndef QT_NO_DEBUG_STREAM @@ -423,7 +432,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) Construct a QLineF object from the given integer-based \a line. - \sa toLine() + \sa toLine(), QLine::toLineF() */ /*! @@ -463,7 +472,7 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) Note that the returned line's start and end points are rounded to the nearest integer. - \sa QLineF() + \sa QLineF(), QLine::toLineF() */ /*! \fn qreal QLineF::x1() const diff --git a/src/corelib/tools/qline.h b/src/corelib/tools/qline.h index 426d69cd6d4..93f3dde3c7c 100644 --- a/src/corelib/tools/qline.h +++ b/src/corelib/tools/qline.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 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. @@ -44,6 +44,7 @@ QT_BEGIN_NAMESPACE +class QLineF; /******************************************************************************* * class QLine @@ -86,6 +87,8 @@ public: constexpr inline bool operator==(const QLine &d) const noexcept; constexpr inline bool operator!=(const QLine &d) const noexcept { return !(*this == d); } + [[nodiscard]] constexpr inline QLineF toLineF() const noexcept; + private: QPoint pt1, pt2; }; @@ -386,6 +389,8 @@ constexpr inline QPointF QLineF::pointAt(qreal t) const return QPointF(pt1.x() + (pt2.x() - pt1.x()) * t, pt1.y() + (pt2.y() - pt1.y()) * t); } +constexpr inline QLineF QLine::toLineF() const noexcept { return *this; } + constexpr inline QLine QLineF::toLine() const { return QLine(pt1.toPoint(), pt2.toPoint()); diff --git a/src/corelib/tools/qmargins.cpp b/src/corelib/tools/qmargins.cpp index 5109cfddce9..2276ffaf32e 100644 --- a/src/corelib/tools/qmargins.cpp +++ b/src/corelib/tools/qmargins.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. @@ -406,6 +406,15 @@ QT_BEGIN_NAMESPACE \since 5.1 */ +/*! + \fn QMargins::toMarginsF() const + \since 6.4 + + Returns these margins as margins with floating point accuracy. + + \sa QMarginsF::toMargins() +*/ + /***************************************************************************** QMargins stream functions *****************************************************************************/ @@ -501,6 +510,8 @@ QDebug operator<<(QDebug dbg, const QMargins &m) \fn QMarginsF::QMarginsF(const QMargins &margins) Constructs margins copied from the given \a margins. + + \sa QMargins::toMarginsF() */ /*! @@ -768,7 +779,7 @@ QDebug operator<<(QDebug dbg, const QMargins &m) Note that the components in the returned margins will be rounded to the nearest integer. - \sa QMarginsF() + \sa QMarginsF(), QMargins::toMarginsF() */ /***************************************************************************** diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h index cf40b89ee0a..c67da13d034 100644 --- a/src/corelib/tools/qmargins.h +++ b/src/corelib/tools/qmargins.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. @@ -44,6 +44,8 @@ QT_BEGIN_NAMESPACE +class QMarginsF; + /***************************************************************************** QMargins class *****************************************************************************/ @@ -75,6 +77,8 @@ public: constexpr QMargins &operator*=(qreal) noexcept; constexpr QMargins &operator/=(qreal); + [[nodiscard]] constexpr inline QMarginsF toMarginsF() const noexcept; + private: int m_left; int m_top; @@ -516,6 +520,8 @@ constexpr inline QMarginsF operator-(const QMarginsF &margins) noexcept return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom()); } +constexpr QMarginsF QMargins::toMarginsF() const noexcept { return *this; } + constexpr inline QMargins QMarginsF::toMargins() const noexcept { return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom)); |
