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>
This commit is contained in:
parent
2fb0135efa
commit
5dc570f8b1
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
** Copyright (C) 2022 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** This file is part of the QtCore module of the Qt Toolkit.
|
||||||
@ -263,6 +263,15 @@ QT_BEGIN_NAMESPACE
|
|||||||
\sa setP1(), setP2(), p1(), p2()
|
\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
|
#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.
|
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
|
Note that the returned line's start and end points are rounded to
|
||||||
the nearest integer.
|
the nearest integer.
|
||||||
|
|
||||||
\sa QLineF()
|
\sa QLineF(), QLine::toLineF()
|
||||||
*/
|
*/
|
||||||
/*!
|
/*!
|
||||||
\fn qreal QLineF::x1() const
|
\fn qreal QLineF::x1() const
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
** Copyright (C) 2022 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** This file is part of the QtCore module of the Qt Toolkit.
|
||||||
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QLineF;
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* class QLine
|
* 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;
|
||||||
constexpr inline bool operator!=(const QLine &d) const noexcept { return !(*this == d); }
|
constexpr inline bool operator!=(const QLine &d) const noexcept { return !(*this == d); }
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr inline QLineF toLineF() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPoint pt1, pt2;
|
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);
|
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
|
constexpr inline QLine QLineF::toLine() const
|
||||||
{
|
{
|
||||||
return QLine(pt1.toPoint(), pt2.toPoint());
|
return QLine(pt1.toPoint(), pt2.toPoint());
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2022 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** This file is part of the QtCore module of the Qt Toolkit.
|
||||||
@ -406,6 +406,15 @@ QT_BEGIN_NAMESPACE
|
|||||||
\since 5.1
|
\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
|
QMargins stream functions
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
@ -501,6 +510,8 @@ QDebug operator<<(QDebug dbg, const QMargins &m)
|
|||||||
\fn QMarginsF::QMarginsF(const QMargins &margins)
|
\fn QMarginsF::QMarginsF(const QMargins &margins)
|
||||||
|
|
||||||
Constructs margins copied from the given \a 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
|
Note that the components in the returned margins will be rounded to
|
||||||
the nearest integer.
|
the nearest integer.
|
||||||
|
|
||||||
\sa QMarginsF()
|
\sa QMarginsF(), QMargins::toMarginsF()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2022 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the QtCore module of the Qt Toolkit.
|
** This file is part of the QtCore module of the Qt Toolkit.
|
||||||
@ -44,6 +44,8 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QMarginsF;
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
QMargins class
|
QMargins class
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
@ -75,6 +77,8 @@ public:
|
|||||||
constexpr QMargins &operator*=(qreal) noexcept;
|
constexpr QMargins &operator*=(qreal) noexcept;
|
||||||
constexpr QMargins &operator/=(qreal);
|
constexpr QMargins &operator/=(qreal);
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr inline QMarginsF toMarginsF() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_left;
|
int m_left;
|
||||||
int m_top;
|
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());
|
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
|
constexpr inline QMargins QMarginsF::toMargins() const noexcept
|
||||||
{
|
{
|
||||||
return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
|
return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
** Copyright (C) 2022 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -30,6 +30,8 @@
|
|||||||
#include <qline.h>
|
#include <qline.h>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
class tst_QLine : public QObject
|
class tst_QLine : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -58,6 +60,9 @@ private slots:
|
|||||||
void testAngleTo_data();
|
void testAngleTo_data();
|
||||||
|
|
||||||
void testSet();
|
void testSet();
|
||||||
|
|
||||||
|
void toLineF_data();
|
||||||
|
void toLineF();
|
||||||
};
|
};
|
||||||
|
|
||||||
const qreal epsilon = sizeof(qreal) == sizeof(double) ? 1e-8 : 1e-4;
|
const qreal epsilon = sizeof(qreal) == sizeof(double) ? 1e-8 : 1e-4;
|
||||||
@ -502,5 +507,35 @@ void tst_QLine::testAngleTo_data()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QLine::toLineF_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QLine>("input");
|
||||||
|
QTest::addColumn<QLineF>("result");
|
||||||
|
|
||||||
|
auto row = [](int x1, int y1, int x2, int y2) {
|
||||||
|
QTest::addRow("((%d, %d)->(%d, %d))", x1, y1, x2, y2)
|
||||||
|
<< QLine(x1, y1, x2, y2) << QLineF(x1, y1, x2, y2);
|
||||||
|
};
|
||||||
|
constexpr std::array samples = {-1, 0, 1};
|
||||||
|
for (int x1 : samples) {
|
||||||
|
for (int y1 : samples) {
|
||||||
|
for (int x2 : samples) {
|
||||||
|
for (int y2 : samples) {
|
||||||
|
row(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QLine::toLineF()
|
||||||
|
{
|
||||||
|
QFETCH(const QLine, input);
|
||||||
|
QFETCH(const QLineF, result);
|
||||||
|
|
||||||
|
QCOMPARE(input.toLineF(), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_QLine)
|
QTEST_MAIN(tst_QLine)
|
||||||
#include "tst_qline.moc"
|
#include "tst_qline.moc"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2016 The Qt Company Ltd.
|
** Copyright (C) 2022 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -29,6 +29,8 @@
|
|||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <qmargins.h>
|
#include <qmargins.h>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QMargins)
|
Q_DECLARE_METATYPE(QMargins)
|
||||||
|
|
||||||
class tst_QMargins : public QObject
|
class tst_QMargins : public QObject
|
||||||
@ -54,6 +56,9 @@ private slots:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void structuredBinding();
|
void structuredBinding();
|
||||||
|
|
||||||
|
void toMarginsF_data();
|
||||||
|
void toMarginsF();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Testing get/set functions
|
// Testing get/set functions
|
||||||
@ -339,5 +344,34 @@ void tst_QMargins::structuredBinding()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QMargins::toMarginsF_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QMargins>("input");
|
||||||
|
QTest::addColumn<QMarginsF>("result");
|
||||||
|
|
||||||
|
auto row = [](int x1, int y1, int x2, int y2) {
|
||||||
|
QTest::addRow("(%d, %d, %d, %d)", x1, y1, x2, y2)
|
||||||
|
<< QMargins(x1, y1, x2, y2) << QMarginsF(x1, y1, x2, y2);
|
||||||
|
};
|
||||||
|
constexpr std::array samples = {-1, 0, 1};
|
||||||
|
for (int x1 : samples) {
|
||||||
|
for (int y1 : samples) {
|
||||||
|
for (int x2 : samples) {
|
||||||
|
for (int y2 : samples) {
|
||||||
|
row(x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QMargins::toMarginsF()
|
||||||
|
{
|
||||||
|
QFETCH(const QMargins, input);
|
||||||
|
QFETCH(const QMarginsF, result);
|
||||||
|
|
||||||
|
QCOMPARE(input.toMarginsF(), result);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_QMargins)
|
QTEST_APPLESS_MAIN(tst_QMargins)
|
||||||
#include "tst_qmargins.moc"
|
#include "tst_qmargins.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user