QtBase  v6.3.1
qpolygon.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QPOLYGON_H
41 #define QPOLYGON_H
42 
43 #include <QtGui/qtguiglobal.h>
44 #include <QtCore/qlist.h>
45 #include <QtCore/qpoint.h>
46 #include <QtCore/qrect.h>
47 
49 
50 class QTransform;
51 class QRect;
52 class QVariant;
53 
54 // We export each out-of-line method individually to prevent MSVC from
55 // exporting the whole QList class.
56 class QPolygon : public QList<QPoint>
57 {
58 public:
60  QPolygon() = default;
61  Q_IMPLICIT QPolygon(const QList<QPoint> &v) : QList<QPoint>(v) { }
62  Q_IMPLICIT QPolygon(QList<QPoint> &&v) noexcept : QList<QPoint>(std::move(v)) { }
63  Q_IMPLICIT Q_GUI_EXPORT QPolygon(const QRect &r, bool closed=false);
64  Q_GUI_EXPORT QPolygon(int nPoints, const int *points);
65  void swap(QPolygon &other) noexcept { QList<QPoint>::swap(other); } // prevent QList<QPoint><->QPolygon swaps
66 
67  Q_GUI_EXPORT operator QVariant() const;
68 
69  Q_GUI_EXPORT void translate(int dx, int dy);
70  void translate(const QPoint &offset);
71 
72  [[nodiscard]] Q_GUI_EXPORT QPolygon translated(int dx, int dy) const;
73  [[nodiscard]] inline QPolygon translated(const QPoint &offset) const;
74 
75  Q_GUI_EXPORT QRect boundingRect() const;
76 
77  Q_GUI_EXPORT void point(int i, int *x, int *y) const;
78  QPoint point(int i) const;
79  Q_GUI_EXPORT void setPoint(int index, int x, int y);
80  inline void setPoint(int index, const QPoint &p);
81  Q_GUI_EXPORT void setPoints(int nPoints, const int *points);
82  Q_GUI_EXPORT void setPoints(int nPoints, int firstx, int firsty, ...);
83  Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points);
84  Q_GUI_EXPORT void putPoints(int index, int nPoints, int firstx, int firsty, ...);
85  Q_GUI_EXPORT void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
86 
87  Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
88 
89  [[nodiscard]] Q_GUI_EXPORT QPolygon united(const QPolygon &r) const;
90  [[nodiscard]] Q_GUI_EXPORT QPolygon intersected(const QPolygon &r) const;
91  [[nodiscard]] Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const;
92 
93  Q_GUI_EXPORT bool intersects(const QPolygon &r) const;
94 };
96 
97 #ifndef QT_NO_DEBUG_STREAM
98 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
99 #endif
100 
101 /*****************************************************************************
102  QPolygon stream functions
103  *****************************************************************************/
104 #ifndef QT_NO_DATASTREAM
105 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
107 #endif
108 
109 /*****************************************************************************
110  Misc. QPolygon functions
111  *****************************************************************************/
112 
113 inline void QPolygon::setPoint(int index, const QPoint &pt)
114 { setPoint(index, pt.x(), pt.y()); }
115 
116 inline QPoint QPolygon::point(int index) const
117 { return at(index); }
118 
119 inline void QPolygon::translate(const QPoint &offset)
120 { translate(offset.x(), offset.y()); }
121 
123 { return translated(offset.x(), offset.y()); }
124 
125 class QRectF;
126 
127 class QPolygonF : public QList<QPointF>
128 {
129 public:
130  using QList<QPointF>::QList;
131  QPolygonF() = default;
132  Q_IMPLICIT QPolygonF(const QList<QPointF> &v) : QList<QPointF>(v) { }
133  Q_IMPLICIT QPolygonF(QList<QPointF> &&v) noexcept : QList<QPointF>(std::move(v)) { }
134  Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QRectF &r);
135  Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QPolygon &a);
136  inline void swap(QPolygonF &other) { QList<QPointF>::swap(other); } // prevent QList<QPointF><->QPolygonF swaps
137 
138  Q_GUI_EXPORT operator QVariant() const;
139 
140  inline void translate(qreal dx, qreal dy);
141  void Q_GUI_EXPORT translate(const QPointF &offset);
142 
143  inline QPolygonF translated(qreal dx, qreal dy) const;
144  [[nodiscard]] Q_GUI_EXPORT QPolygonF translated(const QPointF &offset) const;
145 
146  QPolygon Q_GUI_EXPORT toPolygon() const;
147 
148  bool isClosed() const { return !isEmpty() && first() == last(); }
149 
150  QRectF Q_GUI_EXPORT boundingRect() const;
151 
152  Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
153 
154  [[nodiscard]] Q_GUI_EXPORT QPolygonF united(const QPolygonF &r) const;
155  [[nodiscard]] Q_GUI_EXPORT QPolygonF intersected(const QPolygonF &r) const;
156  [[nodiscard]] Q_GUI_EXPORT QPolygonF subtracted(const QPolygonF &r) const;
157 
158  Q_GUI_EXPORT bool intersects(const QPolygonF &r) const;
159 };
161 
162 #ifndef QT_NO_DEBUG_STREAM
163 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
164 #endif
165 
166 /*****************************************************************************
167  QPolygonF stream functions
168  *****************************************************************************/
169 #ifndef QT_NO_DATASTREAM
170 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
172 #endif
173 
174 inline void QPolygonF::translate(qreal dx, qreal dy)
175 { translate(QPointF(dx, dy)); }
176 
178 { return translated(QPointF(dx, dy)); }
179 
181 
182 #endif // QPOLYGON_H
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
Definition: qlist.h:108
bool isEmpty() const noexcept
Definition: qlist.h:418
const_reference at(qsizetype i) const noexcept
Definition: qlist.h:457
void swap(QList &other) noexcept
Definition: qlist.h:354
QPointF & last()
Definition: qlist.h:646
QPointF & first()
Definition: qlist.h:643
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
constexpr int x() const noexcept
Definition: qpoint.h:155
constexpr int y() const noexcept
Definition: qpoint.h:160
The QPolygonF class provides a list of points using floating point precision. \inmodule QtGui.
Definition: qpolygon.h:128
QPolygon Q_GUI_EXPORT toPolygon() const
Definition: qpolygon.cpp:645
void swap(QPolygonF &other)
Definition: qpolygon.h:136
Q_GUI_EXPORT QPolygonF intersected(const QPolygonF &r) const
Definition: qpolygon.cpp:948
Q_IMPLICIT QPolygonF(QList< QPointF > &&v) noexcept
Definition: qpolygon.h:133
Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const
Definition: qpolygon.cpp:787
Q_IMPLICIT QPolygonF(const QList< QPointF > &v)
Definition: qpolygon.h:132
Q_GUI_EXPORT QPolygonF subtracted(const QPolygonF &r) const
Definition: qpolygon.cpp:966
Q_GUI_EXPORT QPolygonF united(const QPolygonF &r) const
Definition: qpolygon.cpp:929
Q_GUI_EXPORT bool intersects(const QPolygonF &r) const
Definition: qpolygon.cpp:985
void translate(qreal dx, qreal dy)
Definition: qpolygon.h:174
QPolygonF()=default
QRectF Q_GUI_EXPORT boundingRect() const
Definition: qpolygon.cpp:614
QPolygonF translated(qreal dx, qreal dy) const
Definition: qpolygon.h:177
bool isClosed() const
Definition: qpolygon.h:148
The QPolygon class provides a list of points using integer precision. \inmodule QtGui.
Definition: qpolygon.h:57
Q_GUI_EXPORT bool intersects(const QPolygon &r) const
Definition: qpolygon.cpp:910
Q_GUI_EXPORT QPolygon subtracted(const QPolygon &r) const
Definition: qpolygon.cpp:890
Q_GUI_EXPORT void translate(int dx, int dy)
Definition: qpolygon.cpp:189
void swap(QPolygon &other) noexcept
Definition: qpolygon.h:65
QPolygon()=default
Q_IMPLICIT QPolygon(QList< QPoint > &&v) noexcept
Definition: qpolygon.h:62
Q_GUI_EXPORT QPolygon translated(int dx, int dy) const
Definition: qpolygon.cpp:218
Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const
Definition: qpolygon.cpp:818
Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points)
Definition: qpolygon.cpp:339
Q_GUI_EXPORT QPolygon united(const QPolygon &r) const
Definition: qpolygon.cpp:853
Q_GUI_EXPORT void setPoint(int index, int x, int y)
Definition: qpolygon.cpp:271
Q_GUI_EXPORT QRect boundingRect() const
Definition: qpolygon.cpp:422
Q_IMPLICIT QPolygon(const QList< QPoint > &v)
Definition: qpolygon.h:61
Q_GUI_EXPORT void point(int i, int *x, int *y) const
Definition: qpolygon.cpp:242
Q_GUI_EXPORT QPolygon intersected(const QPolygon &r) const
Definition: qpolygon.cpp:872
Q_GUI_EXPORT void setPoints(int nPoints, const int *points)
Definition: qpolygon.cpp:289
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
FillRule
Definition: qnamespace.h:1320
EGLStreamKHR stream
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLboolean r
[2]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLenum GLuint GLintptr offset
GLint y
GLfixed GLfixed GLint GLint GLfixed points
Definition: qopenglext.h:5206
GLenum array
Definition: qopenglext.h:7028
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
QSharedPointer< T > other(t)
[5]