Qt 4.8
qpolygon.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPOLYGON_H
43 #define QPOLYGON_H
44 
45 #include <QtCore/qvector.h>
46 #include <QtCore/qpoint.h>
47 #include <QtCore/qrect.h>
48 
50 
52 
53 QT_MODULE(Gui)
54 
55 class QMatrix;
56 class QTransform;
57 class QRect;
58 class QVariant;
59 
60 class Q_GUI_EXPORT QPolygon : public QVector<QPoint>
61 {
62 public:
63  inline QPolygon() {}
64  inline ~QPolygon() {}
65  inline QPolygon(int size);
66  inline QPolygon(const QPolygon &a) : QVector<QPoint>(a) {}
67  inline QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {}
68  QPolygon(const QRect &r, bool closed=false);
69  QPolygon(int nPoints, const int *points);
70  inline void swap(QPolygon &other) { QVector<QPoint>::swap(other); } // prevent QVector<QPoint><->QPolygon swaps
71 
72  operator QVariant() const;
73 
74  void translate(int dx, int dy);
75  void translate(const QPoint &offset);
76 
77  QPolygon translated(int dx, int dy) const;
78  inline QPolygon translated(const QPoint &offset) const;
79 
80  QRect boundingRect() const;
81 
82  void point(int i, int *x, int *y) const;
83  QPoint point(int i) const;
84  void setPoint(int index, int x, int y);
85  void setPoint(int index, const QPoint &p);
86  void setPoints(int nPoints, const int *points);
87  void setPoints(int nPoints, int firstx, int firsty, ...);
88  void putPoints(int index, int nPoints, const int *points);
89  void putPoints(int index, int nPoints, int firstx, int firsty, ...);
90  void putPoints(int index, int nPoints, const QPolygon & from, int fromIndex=0);
91 
92  bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const;
93 
94  QPolygon united(const QPolygon &r) const;
95  QPolygon intersected(const QPolygon &r) const;
96  QPolygon subtracted(const QPolygon &r) const;
97 };
98 
99 inline QPolygon::QPolygon(int asize) : QVector<QPoint>(asize) {}
100 
101 #ifndef QT_NO_DEBUG_STREAM
103 #endif
104 
105 /*****************************************************************************
106  QPolygon stream functions
107  *****************************************************************************/
108 #ifndef QT_NO_DATASTREAM
111 #endif
112 
113 /*****************************************************************************
114  Misc. QPolygon functions
115  *****************************************************************************/
116 
117 inline void QPolygon::setPoint(int index, const QPoint &pt)
118 { (*this)[index] = pt; }
119 
120 inline void QPolygon::setPoint(int index, int x, int y)
121 { (*this)[index] = QPoint(x, y); }
122 
123 inline QPoint QPolygon::point(int index) const
124 { return at(index); }
125 
126 inline void QPolygon::translate(const QPoint &offset)
127 { translate(offset.x(), offset.y()); }
128 
129 inline QPolygon QPolygon::translated(const QPoint &offset) const
130 { return translated(offset.x(), offset.y()); }
131 
132 class QRectF;
133 
134 class Q_GUI_EXPORT QPolygonF : public QVector<QPointF>
135 {
136 public:
137  inline QPolygonF() {}
138  inline ~QPolygonF() {}
139  inline QPolygonF(int size);
140  inline QPolygonF(const QPolygonF &a) : QVector<QPointF>(a) {}
141  inline QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {}
142  QPolygonF(const QRectF &r);
143  QPolygonF(const QPolygon &a);
144  inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps
145 
146  inline void translate(qreal dx, qreal dy);
147  void translate(const QPointF &offset);
148 
149  inline QPolygonF translated(qreal dx, qreal dy) const;
150  QPolygonF translated(const QPointF &offset) const;
151 
152  QPolygon toPolygon() const;
153 
154  bool isClosed() const { return !isEmpty() && first() == last(); }
155 
156  QRectF boundingRect() const;
157 
158  bool containsPoint(const QPointF &pt, Qt::FillRule fillRule) const;
159 
160  QPolygonF united(const QPolygonF &r) const;
161  QPolygonF intersected(const QPolygonF &r) const;
162  QPolygonF subtracted(const QPolygonF &r) const;
163 };
164 
165 inline QPolygonF::QPolygonF(int asize) : QVector<QPointF>(asize) {}
166 
167 #ifndef QT_NO_DEBUG_STREAM
169 #endif
170 
171 /*****************************************************************************
172  QPolygonF stream functions
173  *****************************************************************************/
174 #ifndef QT_NO_DATASTREAM
177 #endif
178 
179 inline void QPolygonF::translate(qreal dx, qreal dy)
180 { translate(QPointF(dx, dy)); }
181 
183 { return translated(QPointF(dx, dy)); }
184 
186 
188 
189 #endif // QPOLYGON_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
QPolygon united(const QPolygon &r) const
Returns a polygon which is the union of this polygon and r.
Definition: qpolygon.cpp:1012
double qreal
Definition: qglobal.h:1193
QDataStream & operator<<(QDataStream &stream, const QPolygonF &polygon)
Writes the given polygon to the given stream, and returns a reference to the stream.
Definition: qpolygon.cpp:871
QDataStream & operator>>(QDataStream &stream, QPolygon &polygon)
Reads a polygon from the given stream into the given polygon, and returns a reference to the stream...
Definition: qpolygon.cpp:847
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
~QPolygon()
Destroys the polygon.
Definition: qpolygon.h:64
QDataStream & operator<<(QDataStream &stream, const QPolygon &polygon)
Writes the given polygon to the given stream, and returns a reference to the stream.
Definition: qpolygon.cpp:828
QPolygonF(const QPolygonF &a)
Constructs a copy of the given polygon.
Definition: qpolygon.h:140
QPolygon translated(int dx, int dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition: qpolygon.cpp:270
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QPoint & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
FillRule
Definition: qnamespace.h:1485
QPolygon()
Constructs a polygon with no points.
Definition: qpolygon.h:63
long ASN1_INTEGER_get ASN1_INTEGER * a
QPolygonF()
Constructs a polygon with no points.
Definition: qpolygon.h:137
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
void swap(QVector< T > &other)
Swaps vector other with this vector.
Definition: qvector.h:130
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QPolygon(const QVector< QPoint > &v)
Constructs a polygon containing the specified points.
Definition: qpolygon.h:67
QDataStream & operator>>(QDataStream &stream, QPolygonF &polygon)
Reads a polygon from the given stream into the given polygon, and returns a reference to the stream...
Definition: qpolygon.cpp:895
~QPolygonF()
Destroys the polygon.
Definition: qpolygon.h:138
static const QRectF boundingRect(const QPointF *points, int pointCount)
QPolygonF translated(qreal dx, qreal dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition: qpolygon.h:182
void translate(int dx, int dy)
Translates all points in the polygon by ({dx}, {dy}).
Definition: qpolygon.cpp:238
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static FILE * stream
QPolygon subtracted(const QPolygon &r) const
Returns a polygon which is r subtracted from this polygon.
Definition: qpolygon.cpp:1053
QPolygonF(const QVector< QPointF > &v)
Constructs a polygon containing the specified points.
Definition: qpolygon.h:141
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
void translate(qreal dx, qreal dy)
Translates all points in the polygon by ({dx}, {dy}).
Definition: qpolygon.h:179
const QPoint & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QPolygon(const QPolygon &a)
Constructs a copy of the given polygon.
Definition: qpolygon.h:66
void swap(QPolygonF &other)
Swaps polygon other with this polygon.
Definition: qpolygon.h:144
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QPoint & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
void swap(QPolygon &other)
Swaps polygon other with this polygon.
Definition: qpolygon.h:70
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setPoint(int index, int x, int y)
Sets the point at the given index to the point specified by ({x}, {y}).
Definition: qpolygon.h:120
QRect boundingRect() const
Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, 0) if the polygon is empty...
Definition: qpolygon.cpp:492
bool containsPoint(const QPoint &pt, Qt::FillRule fillRule) const
Returns true if the given point is inside the polygon according to the specified fillRule; otherwise ...
Definition: qpolygon.cpp:974
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
bool isClosed() const
Returns true if the polygon is closed; otherwise returns false.
Definition: qpolygon.h:154
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
#define QT_END_HEADER
Definition: qglobal.h:137
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
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:297
QPolygon intersected(const QPolygon &r) const
Returns a polygon which is the intersection of this polygon and r.
Definition: qpolygon.cpp:1032
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65