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
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;
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
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
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
73Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygon &polygon);
74Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygon &polygon);
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
87inline void QPolygon::translate(const QPoint &offset)
88{ translate(offset.x(), offset.y()); }
89
90inline QPolygon QPolygon::translated(const QPoint &offset) const
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;
102 Q_IMPLICIT Q_GUI_EXPORT QPolygonF(const QRectF &r);
104 inline void swap(QPolygonF &other) { QList<QPointF>::swap(other); } // prevent QList<QPointF><->QPolygonF swaps
105
107
108 inline void translate(qreal dx, qreal dy);
110
111 inline QPolygonF translated(qreal dx, qreal dy) const;
113
115
116 bool isClosed() const { return !isEmpty() && first() == last(); }
117
119
120 Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
121
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
140Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QPolygonF &array);
141Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QPolygonF &array);
142#endif
143
144inline void QPolygonF::translate(qreal dx, qreal dy)
145{ translate(QPointF(dx, dy)); }
146
147inline QPolygonF QPolygonF::translated(qreal dx, qreal dy) const
148{ return translated(QPointF(dx, dy)); }
149
150QT_END_NAMESPACE
151
152#endif // QPOLYGON_H
\inmodule QtCore\reentrant
Definition qdatastream.h:49
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:96
void swap(QPolygonF &other)
Definition qpolygon.h:104
Q_GUI_EXPORT bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const
Definition qpolygon.cpp:731
Q_GUI_EXPORT bool intersects(const QPolygonF &r) const
Definition qpolygon.cpp:929
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.
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:854
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:335
Q_GUI_EXPORT void translate(int dx, int dy)
Translates all points in the polygon by ({dx}, {dy}).
Definition qpolygon.cpp:153
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:365
QPoint point(int i) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:84
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:277
void swap(QPolygon &other) noexcept
Definition qpolygon.h:31
QPolygon()=default
Constructs a polygon with no points.
Q_GUI_EXPORT bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const
Definition qpolygon.cpp:762
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
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:81
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
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:90
void translate(const QPoint &offset)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpolygon.h:87
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 void setPoints(int nPoints, const int *points)
Resizes the polygon to nPoints and populates it with the given points.
Definition qpolygon.cpp:253
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2462
#define SERIALIZE_CMD(c)