Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpolygon.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPOLYGON_H
5#define QPOLYGON_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qlist.h>
9#include <QtCore/qpoint.h>
10#include <QtCore/qrect.h>
11
13
14class QTransform;
15class QRect;
16class QVariant;
17
18class QPolygonF;
19
20// We export each out-of-line method individually to prevent MSVC from
21// exporting the whole QList class.
22class QPolygon : public QList<QPoint>
23{
24public:
25 using QList<QPoint>::QList;
26 QPolygon() = default;
27 Q_IMPLICIT QPolygon(const QList<QPoint> &v) : QList<QPoint>(v) { }
28 Q_IMPLICIT QPolygon(QList<QPoint> &&v) noexcept : QList<QPoint>(std::move(v)) { }
29 Q_IMPLICIT Q_GUI_EXPORT QPolygon(const QRect &r, bool closed=false);
30 Q_GUI_EXPORT QPolygon(int nPoints, const int *points);
31 void swap(QPolygon &other) noexcept { QList<QPoint>::swap(other); } // prevent QList<QPoint><->QPolygon swaps
32
33 Q_GUI_EXPORT operator QVariant() const;
34
35 Q_GUI_EXPORT void translate(int dx, int dy);
36 void translate(const QPoint &offset);
37
38 [[nodiscard]] Q_GUI_EXPORT QPolygon translated(int dx, int dy) const;
39 [[nodiscard]] inline QPolygon translated(const QPoint &offset) const;
40
41 Q_GUI_EXPORT QRect boundingRect() const;
42
43 Q_GUI_EXPORT void point(int i, int *x, int *y) const;
44 QPoint point(int i) const;
45 Q_GUI_EXPORT void setPoint(int index, int x, int y);
46 inline void setPoint(int index, const QPoint &p);
47 Q_GUI_EXPORT void setPoints(int nPoints, const int *points);
48 Q_GUI_EXPORT void setPoints(int nPoints, int firstx, int firsty, ...);
49 Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points);
50 Q_GUI_EXPORT void putPoints(int index, int nPoints, int firstx, int firsty, ...);
51 Q_GUI_EXPORT void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
52
53 Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
54
55 [[nodiscard]] Q_GUI_EXPORT QPolygon united(const QPolygon &r) const;
56 [[nodiscard]] Q_GUI_EXPORT QPolygon intersected(const QPolygon &r) const;
57 [[nodiscard]] Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const;
58
59 Q_GUI_EXPORT bool intersects(const QPolygon &r) const;
60
61 [[nodiscard]] inline QPolygonF toPolygonF() const;
62};
63Q_DECLARE_SHARED(QPolygon)
64
65#ifndef QT_NO_DEBUG_STREAM
66Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
67#endif
68
69/*****************************************************************************
70 QPolygon stream functions
71 *****************************************************************************/
72#ifndef QT_NO_DATASTREAM
75#endif
76
77/*****************************************************************************
78 Misc. QPolygon functions
79 *****************************************************************************/
80
81inline void QPolygon::setPoint(int index, const QPoint &pt)
82{ setPoint(index, pt.x(), pt.y()); }
83
84inline QPoint QPolygon::point(int index) const
85{ return at(index); }
86
88{ translate(offset.x(), offset.y()); }
89
91{ return translated(offset.x(), offset.y()); }
92
93class QRectF;
94
95class QPolygonF : public QList<QPointF>
96{
97public:
98 using QList<QPointF>::QList;
99 QPolygonF() = default;
100 Q_IMPLICIT QPolygonF(const QList<QPointF> &v) : QList<QPointF>(v) { }
101 Q_IMPLICIT QPolygonF(QList<QPointF> &&v) noexcept : QList<QPointF>(std::move(v)) { }
102 Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QRectF &r);
103 Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QPolygon &a);
104 inline void swap(QPolygonF &other) { QList<QPointF>::swap(other); } // prevent QList<QPointF><->QPolygonF swaps
105
106 Q_GUI_EXPORT operator QVariant() const;
107
108 inline void translate(qreal dx, qreal dy);
109 void Q_GUI_EXPORT translate(const QPointF &offset);
110
111 inline QPolygonF translated(qreal dx, qreal dy) const;
112 [[nodiscard]] Q_GUI_EXPORT QPolygonF translated(const QPointF &offset) const;
113
114 QPolygon Q_GUI_EXPORT toPolygon() const;
115
116 bool isClosed() const { return !isEmpty() && first() == last(); }
117
118 QRectF Q_GUI_EXPORT boundingRect() const;
119
120 Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
121
122 [[nodiscard]] Q_GUI_EXPORT QPolygonF united(const QPolygonF &r) const;
123 [[nodiscard]] Q_GUI_EXPORT QPolygonF intersected(const QPolygonF &r) const;
124 [[nodiscard]] Q_GUI_EXPORT QPolygonF subtracted(const QPolygonF &r) const;
125
126 Q_GUI_EXPORT bool intersects(const QPolygonF &r) const;
127};
128Q_DECLARE_SHARED(QPolygonF)
129
130QPolygonF QPolygon::toPolygonF() const { return QPolygonF(*this); }
131
132#ifndef QT_NO_DEBUG_STREAM
133Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
134#endif
135
136/*****************************************************************************
137 QPolygonF stream functions
138 *****************************************************************************/
139#ifndef QT_NO_DATASTREAM
142#endif
143
145{ translate(QPointF(dx, dy)); }
146
148{ return translated(QPointF(dx, dy)); }
149
151
152#endif // QPOLYGON_H
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
Definition qlist.h:75
bool isEmpty() const noexcept
Definition qlist.h:401
QPointF & first()
Definition qlist.h:645
QPointF & last()
Definition qlist.h:648
void swap(QList &other) noexcept
Definition qlist.h:337
QList()=default
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:130
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:135
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
QPolygon Q_GUI_EXPORT toPolygon() const
Creates and returns a QPolygon by converting each QPointF to a QPoint.
Definition qpolygon.cpp:614
void swap(QPolygonF &other)
Definition qpolygon.h:104
Q_GUI_EXPORT QPolygonF intersected(const QPolygonF &r) const
Definition qpolygon.cpp:896
Q_IMPLICIT QPolygonF(QList< QPointF > &&v) noexcept
Definition qpolygon.h:101
Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const
Definition qpolygon.cpp:735
Q_IMPLICIT QPolygonF(const QList< QPointF > &v)
Constructs a polygon containing the specified points.
Definition qpolygon.h:100
Q_GUI_EXPORT QPolygonF subtracted(const QPolygonF &r) const
Definition qpolygon.cpp:914
Q_GUI_EXPORT QPolygonF united(const QPolygonF &r) const
Definition qpolygon.cpp:877
Q_GUI_EXPORT bool intersects(const QPolygonF &r) const
Definition qpolygon.cpp:933
void translate(qreal dx, qreal dy)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:144
QPolygonF()=default
Constructs a polygon with no points.
QRectF Q_GUI_EXPORT boundingRect() const
Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty.
Definition qpolygon.cpp:583
QPolygonF translated(qreal dx, qreal dy) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:147
bool isClosed() const
Returns true if the polygon is closed; otherwise returns false.
Definition qpolygon.h:116
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:23
QPolygonF toPolygonF() const
Definition qpolygon.h:130
Q_GUI_EXPORT bool intersects(const QPolygon &r) const
Definition qpolygon.cpp:858
Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const
Definition qpolygon.cpp:838
Q_GUI_EXPORT void translate(int dx, int dy)
Translates all points in the polygon by ({dx}, {dy}).
Definition qpolygon.cpp:153
void swap(QPolygon &other) noexcept
Definition qpolygon.h:31
QPolygon()=default
Constructs a polygon with no points.
Q_IMPLICIT QPolygon(QList< QPoint > &&v) noexcept
Definition qpolygon.h:28
Q_GUI_EXPORT QPolygon translated(int dx, int dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition qpolygon.cpp:182
Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const
Definition qpolygon.cpp:766
Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.cpp:303
Q_GUI_EXPORT QPolygon united(const QPolygon &r) const
Definition qpolygon.cpp:801
Q_GUI_EXPORT void setPoint(int index, int x, int y)
Sets the point at the given index to the point specified by ({x}, {y}).
Definition qpolygon.cpp:235
Q_GUI_EXPORT QRect boundingRect() const
Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, 0) if the polygon is empty.
Definition qpolygon.cpp:386
Q_IMPLICIT QPolygon(const QList< QPoint > &v)
Constructs a polygon containing the specified points.
Definition qpolygon.h:27
Q_GUI_EXPORT void point(int i, int *x, int *y) const
Extracts the coordinates of the point at the given index to {x} and *{y} (if they are valid pointers)...
Definition qpolygon.cpp:206
Q_GUI_EXPORT QPolygon intersected(const QPolygon &r) const
Definition qpolygon.cpp:820
Q_GUI_EXPORT void setPoints(int nPoints, const int *points)
Resizes the polygon to nPoints and populates it with the given points.
Definition qpolygon.cpp:253
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
#define Q_IMPLICIT
EGLStreamKHR stream
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLenum GLuint GLintptr offset
GLint y
GLfixed GLfixed GLint GLint GLfixed points
GLenum array
GLfloat GLfloat p
[1]
Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &)
Definition qpolygon.cpp:420
Q_GUI_EXPORT QDataStream & operator>>(QDataStream &stream, QPolygon &polygon)
Definition qpolygon.cpp:677
double qreal
Definition qtypes.h:187
QSharedPointer< T > other(t)
[5]
QAction * at