diff options
-rw-r--r-- | src/gui/painting/qpolygon.cpp | 10 | ||||
-rw-r--r-- | src/gui/painting/qpolygon.h | 6 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp | 12 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index f124691f02..fd775de4a4 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -442,6 +442,16 @@ QRect QPolygon::boundingRect() const return QRect(QPoint(minx,miny), QPoint(maxx,maxy)); } +/*! + \fn QPolygon::toPolygonF() const + \since 6.4 + + Returns this polygon as a polygon with floating point accuracy. + + \sa QPolygonF::toPolygon() +*/ + + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QPolygon &a) { diff --git a/src/gui/painting/qpolygon.h b/src/gui/painting/qpolygon.h index f7153a9f37..eeceff97ed 100644 --- a/src/gui/painting/qpolygon.h +++ b/src/gui/painting/qpolygon.h @@ -51,6 +51,8 @@ class QTransform; class QRect; class QVariant; +class QPolygonF; + // We export each out-of-line method individually to prevent MSVC from // exporting the whole QList class. class QPolygon : public QList<QPoint> @@ -91,6 +93,8 @@ public: [[nodiscard]] Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const; Q_GUI_EXPORT bool intersects(const QPolygon &r) const; + + [[nodiscard]] inline QPolygonF toPolygonF() const; }; Q_DECLARE_SHARED(QPolygon) @@ -159,6 +163,8 @@ public: }; Q_DECLARE_SHARED(QPolygonF) +QPolygonF QPolygon::toPolygonF() const { return QPolygonF(*this); } + #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &); #endif diff --git a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp index 4cde0aa549..0ab9397b51 100644 --- a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp +++ b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp @@ -41,6 +41,7 @@ class tst_QPolygon : public QObject private slots: void constructors(); + void toPolygonF(); void boundingRect_data(); void boundingRect(); void boundingRectF_data(); @@ -80,6 +81,17 @@ void tst_QPolygon::constructors() constructors_helperF(QRectF(1, 2, 3, 4)); } +void tst_QPolygon::toPolygonF() +{ + const QPolygon p = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}}; + auto pf = p.toPolygonF(); + static_assert(std::is_same_v<decltype(pf), QPolygonF>); + QCOMPARE(pf.size(), p.size()); + auto p2 = pf.toPolygon(); + static_assert(std::is_same_v<decltype(p2), QPolygon>); + QCOMPARE(p, p2); +} + void tst_QPolygon::boundingRect_data() { QTest::addColumn<QPolygon>("poly"); |