Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QPOLYGON_H
6#define QPOLYGON_H
7
8#include <QtGui/qtguiglobal.h>
9#include <QtCore/qlist.h>
10#include <QtCore/qpoint.h>
11#include <QtCore/qrect.h>
12
14
15class QTransform;
16class QRect;
17class QVariant;
18
19class QPolygonF;
20
21// We export each out-of-line method individually to prevent MSVC from
22// exporting the whole QList class.
23class QPolygon : public QList<QPoint>
24{
25public:
26 using QList<QPoint>::QList;
27 QPolygon() = default;
30 Q_IMPLICIT Q_GUI_EXPORT QPolygon(const QRect &r, bool closed=false);
31 Q_GUI_EXPORT QPolygon(int nPoints, const int *points);
32 void swap(QPolygon &other) noexcept { QList<QPoint>::swap(other); } // prevent QList<QPoint><->QPolygon swaps
33
35
36 Q_GUI_EXPORT void translate(int dx, int dy);
37 void translate(const QPoint &offset);
38
39 [[nodiscard]] Q_GUI_EXPORT QPolygon translated(int dx, int dy) const;
40 [[nodiscard]] inline QPolygon translated(const QPoint &offset) const;
41
42 Q_GUI_EXPORT QRect boundingRect() const;
43
44 Q_GUI_EXPORT void point(int i, int *x, int *y) const;
45 QPoint point(int i) const;
46 Q_GUI_EXPORT void setPoint(int index, int x, int y);
47 inline void setPoint(int index, const QPoint &p);
48 Q_GUI_EXPORT void setPoints(int nPoints, const int *points);
49 Q_GUI_EXPORT void setPoints(int nPoints, int firstx, int firsty, ...);
50 Q_GUI_EXPORT void putPoints(int index, int nPoints, const int *points);
51 Q_GUI_EXPORT void putPoints(int index, int nPoints, int firstx, int firsty, ...);
52 Q_GUI_EXPORT void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
53
54 Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
55
59
60 Q_GUI_EXPORT bool intersects(const QPolygon &r) const;
61
62 [[nodiscard]] inline QPolygonF toPolygonF() const;
63};
64Q_DECLARE_SHARED(QPolygon)
65
66#ifndef QT_NO_DEBUG_STREAM
67Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &);
68#endif
69
70/*****************************************************************************
71 QPolygon stream functions
72 *****************************************************************************/
73#ifndef QT_NO_DATASTREAM
74Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
75Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
76#endif
77
78/*****************************************************************************
79 Misc. QPolygon functions
80 *****************************************************************************/
81
82inline void QPolygon::setPoint(int index, const QPoint &pt)
83{ setPoint(index, pt.x(), pt.y()); }
84
85inline QPoint QPolygon::point(int index) const
86{ return at(index); }
87
88inline void QPolygon::translate(const QPoint &offset)
89{ translate(offset.x(), offset.y()); }
90
91inline QPolygon QPolygon::translated(const QPoint &offset) const
92{ return translated(offset.x(), offset.y()); }
93
94class QRectF;
95
96class QPolygonF : public QList<QPointF>
97{
98public:
99 using QList<QPointF>::QList;
100 QPolygonF() = default;
103 Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QRectF &r);
105 inline void swap(QPolygonF &other) { QList<QPointF>::swap(other); } // prevent QList<QPointF><->QPolygonF swaps
106
108
109 inline void translate(qreal dx, qreal dy);
111
112 inline QPolygonF translated(qreal dx, qreal dy) const;
114
116
117 bool isClosed() const { return !isEmpty() && first() == last(); }
118
120
121 Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
122
126
127 Q_GUI_EXPORT bool intersects(const QPolygonF &r) const;
128};
129Q_DECLARE_SHARED(QPolygonF)
130
131QPolygonF QPolygon::toPolygonF() const { return QPolygonF(*this); }
132
133#ifndef QT_NO_DEBUG_STREAM
134Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &);
135#endif
136
137/*****************************************************************************
138 QPolygonF stream functions
139 *****************************************************************************/
140#ifndef QT_NO_DATASTREAM
141Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
142Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
143#endif
144
145inline void QPolygonF::translate(qreal dx, qreal dy)
146{ translate(QPointF(dx, dy)); }
147
148inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
149{ return translated(QPointF(dx, dy)); }
150
151QT_END_NAMESPACE
152
153#endif // QPOLYGON_H
\inmodule QtCore\reentrant
Definition qdatastream.h:50
void updateOpacity(qreal opacity)
void drawImage(const QRectF &r, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor) override
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
void updateMatrix(const QTransform &matrix)
void updatePen(const QPen &pen)
void drawPolygon(const QPointF *points, int numPoints, PolygonDrawMode mode) override
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
void updateClipRegion(const QRegion &region, Qt::ClipOperation op)
void drawPath(const QPainterPath &path) override
The default implementation ignores the path and does nothing.
void drawTextItem(const QPointF &p, const QTextItem &ti) override
This function draws the text item textItem at position p.
QPicturePaintEngine(QPaintEnginePrivate &dptr)
void updateBrushOrigin(const QPointF &origin)
void updateFont(const QFont &font)
void updateCompositionMode(QPainter::CompositionMode cmode)
void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s) override
Reimplement this function to draw the pixmap in the given rect, starting at the given p.
void updateClipEnabled(bool enabled)
void updateState(const QPaintEngineState &state) override
Reimplement this function to update the state of a paint engine.
bool end() override
Reimplement this function to finish painting on the current paint device.
void updateBrush(const QBrush &brush)
void drawEllipse(const QRectF &rect) override
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.
void updateClipPath(const QPainterPath &path, Qt::ClipOperation op)
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.
void updateRenderHints(QPainter::RenderHints hints)
void updateBackground(Qt::BGMode bgmode, const QBrush &bgBrush)
Type type() const override
Reimplement this function to return the paint engine \l{Type}.
bool begin(QPaintDevice *pdev) override
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
The QPicture class is a paint device that records and replays QPainter commands.
Definition qpicture.h:19
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:97
void swap(QPolygonF &other)
Definition qpolygon.h:105
Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const
Definition qpolygon.cpp:732
Q_GUI_EXPORT bool intersects(const QPolygonF &r) const
Definition qpolygon.cpp:930
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:145
QPolygonF()=default
Constructs a polygon with no points.
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:148
bool isClosed() const
Returns true if the polygon is closed; otherwise returns false.
Definition qpolygon.h:117
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:24
QPolygonF toPolygonF() const
Definition qpolygon.h:131
Q_GUI_EXPORT bool intersects(const QPolygon &r) const
Definition qpolygon.cpp:855
Q_GUI_EXPORT void putPoints(int index, int nPoints, int firstx, int firsty,...)
Copies nPoints points from the variable argument list into this polygon from the given index.
Definition qpolygon.cpp:336
Q_GUI_EXPORT void translate(int dx, int dy)
Translates all points in the polygon by ({dx}, {dy}).
Definition qpolygon.cpp:154
Q_GUI_EXPORT void putPoints(int index, int nPoints, const QPolygon &from, int fromIndex=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.cpp:366
QPoint point(int i) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:85
Q_GUI_EXPORT void setPoints(int nPoints, int firstx, int firsty,...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.cpp:278
void swap(QPolygon &other) noexcept
Definition qpolygon.h:32
QPolygon()=default
Constructs a polygon with no points.
Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const
Definition qpolygon.cpp:763
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:304
void setPoint(int index, const QPoint &p)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:82
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:236
QPolygon translated(const QPoint &offset) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:91
void translate(const QPoint &offset)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:88
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:207
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:254
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
#define SERIALIZE_CMD(c)