QPolygon: add toPolygonF()
This was forgotten when implementing QTBUG-73160, but suggested in passing in QTBUG-64. [ChangeLog][QtGui][QPolygon] Added toPolygonF(). Task-number: QTBUG-73160 Task-number: QTBUG-64 Change-Id: I9b33cf47a0d432aa842ab0f8337001c66e4ca41c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
83779c858b
commit
a1903eb941
@ -442,6 +442,16 @@ QRect QPolygon::boundingRect() const
|
|||||||
return QRect(QPoint(minx,miny), QPoint(maxx,maxy));
|
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
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
QDebug operator<<(QDebug dbg, const QPolygon &a)
|
QDebug operator<<(QDebug dbg, const QPolygon &a)
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,8 @@ class QTransform;
|
|||||||
class QRect;
|
class QRect;
|
||||||
class QVariant;
|
class QVariant;
|
||||||
|
|
||||||
|
class QPolygonF;
|
||||||
|
|
||||||
// We export each out-of-line method individually to prevent MSVC from
|
// We export each out-of-line method individually to prevent MSVC from
|
||||||
// exporting the whole QList class.
|
// exporting the whole QList class.
|
||||||
class QPolygon : public QList<QPoint>
|
class QPolygon : public QList<QPoint>
|
||||||
@ -91,6 +93,8 @@ public:
|
|||||||
[[nodiscard]] Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const;
|
[[nodiscard]] Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const;
|
||||||
|
|
||||||
Q_GUI_EXPORT bool intersects(const QPolygon &r) const;
|
Q_GUI_EXPORT bool intersects(const QPolygon &r) const;
|
||||||
|
|
||||||
|
[[nodiscard]] inline QPolygonF toPolygonF() const;
|
||||||
};
|
};
|
||||||
Q_DECLARE_SHARED(QPolygon)
|
Q_DECLARE_SHARED(QPolygon)
|
||||||
|
|
||||||
@ -159,6 +163,8 @@ public:
|
|||||||
};
|
};
|
||||||
Q_DECLARE_SHARED(QPolygonF)
|
Q_DECLARE_SHARED(QPolygonF)
|
||||||
|
|
||||||
|
QPolygonF QPolygon::toPolygonF() const { return QPolygonF(*this); }
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
|
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,6 +41,7 @@ class tst_QPolygon : public QObject
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void constructors();
|
void constructors();
|
||||||
|
void toPolygonF();
|
||||||
void boundingRect_data();
|
void boundingRect_data();
|
||||||
void boundingRect();
|
void boundingRect();
|
||||||
void boundingRectF_data();
|
void boundingRectF_data();
|
||||||
@ -80,6 +81,17 @@ void tst_QPolygon::constructors()
|
|||||||
constructors_helperF(QRectF(1, 2, 3, 4));
|
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()
|
void tst_QPolygon::boundingRect_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QPolygon>("poly");
|
QTest::addColumn<QPolygon>("poly");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user