#include <qpolygon.h>
Inheritance diagram for QPolygon:


A QPolygon object is a QVector<QPoint>. The easiest way to add points to a QPolygon is to use QVector's streaming operator, as illustrated below:
snippets/polygon/polygon.cpp STREAM QPolygon QPoint
In addition to the functions provided by QVector, QPolygon provides some point-specific functions.
Each point in a polygon can be retrieved by passing its index to the point() function. To populate the polygon, QPolygon provides the setPoint() function to set the point at a given index, the setPoints() function to set all the points in the polygon (resizing it to the given number of points), and the putPoints() function which copies a number of given points into the polygon from a specified index (resizing the polygon if necessary).
QPolygon provides the boundingRect() and translate() functions for geometry functions. Use the QMatrix::map() function for more general transformations of QPolygons.
The QPolygon class is {Implicit Data Sharing}{implicitly shared}.
Definition at line 39 of file qpolygon.h.
Public Member Functions | |
| QPolygon () | |
| ~QPolygon () | |
| QPolygon (int size) | |
| QPolygon (const QPolygon &a) | |
| QPolygon (const QVector< QPoint > &v) | |
| QPolygon (const QRect &r, bool closed=false) | |
| QPolygon (int nPoints, const int *points) | |
| operator QVariant () const | |
| void | translate (int dx, int dy) |
| void | translate (const QPoint &offset) |
| QRect | boundingRect () const |
| void | point (int i, int *x, int *y) const |
| QPoint | point (int i) const |
| void | setPoint (int index, int x, int y) |
| void | setPoint (int index, const QPoint &p) |
| void | setPoints (int nPoints, const int *points) |
| void | setPoints (int nPoints, int firstx, int firsty,...) |
| void | putPoints (int index, int nPoints, const int *points) |
| void | putPoints (int index, int nPoints, int firstx, int firsty,...) |
| void | putPoints (int index, int nPoints, const QPolygon &from, int fromIndex=0) |
| QPolygon::QPolygon | ( | ) | [inline] |
Constructs a polygon with no points.
Definition at line 42 of file qpolygon.h.
Referenced by Q3PointArray::cubicBezier().
| QPolygon::~QPolygon | ( | ) | [inline] |
| QPolygon::QPolygon | ( | int | size | ) | [inline] |
Constructs a polygon of the given size. Creates an empty polygon if size == 0.
Definition at line 66 of file qpolygon.h.
00066 : QVector<QPoint>(asize) {}
| QPolygon::QPolygon | ( | const QPolygon & | polygon | ) | [inline] |
Constructs a copy of the given polygon.
Definition at line 45 of file qpolygon.h.
00045 : QVector<QPoint>(a) {}
Constructs a polygon containing the specified points.
Definition at line 46 of file qpolygon.h.
00046 : QVector<QPoint>(v) {}
| QPolygon::QPolygon | ( | const QRect & | rectangle, | |
| bool | closed = false | |||
| ) |
Constructs a polygon from the given rectangle. If closed is false, the polygon just contains the four points of the rectangle ordered clockwise, otherwise the polygon's fifth point is set to {rectangle}.topLeft().
Note that the bottom-right corner of the rectangle is located at (rectangle.x() + rectangle.width(), rectangle.y() + rectangle.height()).
Definition at line 129 of file qpolygon.cpp.
References QRect::height(), QRect::left(), QVector< QPoint >::reserve(), QRect::top(), QRect::width(), QRect::x(), and QRect::y().
00130 { 00131 reserve(closed ? 5 : 4); 00132 *this << QPoint(r.x(), r.y()) 00133 << QPoint(r.x() + r.width(), r.y()) 00134 << QPoint(r.x() + r.width(), r.y() + r.height()) 00135 << QPoint(r.x(), r.y() + r.height()); 00136 if (closed) 00137 *this << QPoint(r.left(), r.top()); 00138 }
Here is the call graph for this function:

| QPolygon::QPolygon | ( | int | nPoints, | |
| const int * | points | |||
| ) |
Definition at line 148 of file qpolygon.cpp.
References setPoints().
00149 { 00150 setPoints(nPoints, points); 00151 }
Here is the call graph for this function:

| QPolygon::operator QVariant | ( | ) | const |
Returns the polygon as a QVariant
Definition at line 616 of file qpolygon.cpp.
References QVariant::Polygon.
00617 { 00618 return QVariant(QVariant::Polygon, this); 00619 }
| void QPolygon::translate | ( | int | dx, | |
| int | dy | |||
| ) |
Translates all points in the polygon by ({dx}, {dy}).
Definition at line 165 of file qpolygon.cpp.
References QVector< QPoint >::data(), i, QVector< QPoint >::p, and QVector< QPoint >::size().
Referenced by Q3CanvasPolygonalItem::areaPointsAdvanced(), QMotifStyle::drawPrimitive(), Q3CanvasPolygon::moveBy(), Q3CanvasPolygon::points(), Q3CanvasPolygon::setPoints(), and translate().
00166 { 00167 register QPoint *p = data(); 00168 register int i = size(); 00169 QPoint pt(dx, dy); 00170 while (i--) { 00171 *p += pt; 00172 ++p; 00173 } 00174 }
Here is the call graph for this function:

| void QPolygon::translate | ( | const QPoint & | offset | ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Translates all points in the polygon by the given offset.
Definition at line 85 of file qpolygon.h.
References translate(), QPoint::x(), and QPoint::y().
Here is the call graph for this function:

| QRect QPolygon::boundingRect | ( | ) | const |
Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, 0) if the polygon is empty.
Definition at line 383 of file qpolygon.cpp.
References QVector< QPoint >::constData(), i, QVector< QPoint >::isEmpty(), QVector< QPoint >::size(), QPoint::x(), and QPoint::y().
Referenced by Q3CanvasPolygonalItem::boundingRect(), and QPolygonalProcessor::QPolygonalProcessor().
00384 { 00385 if (isEmpty()) 00386 return QRect(0, 0, 0, 0); 00387 register const QPoint *pd = constData(); 00388 int minx, maxx, miny, maxy; 00389 minx = maxx = pd->x(); 00390 miny = maxy = pd->y(); 00391 ++pd; 00392 for (int i = 1; i < size(); ++i) { 00393 if (pd->x() < minx) 00394 minx = pd->x(); 00395 else if (pd->x() > maxx) 00396 maxx = pd->x(); 00397 if (pd->y() < miny) 00398 miny = pd->y(); 00399 else if (pd->y() > maxy) 00400 maxy = pd->y(); 00401 ++pd; 00402 } 00403 return QRect(QPoint(minx,miny), QPoint(maxx,maxy)); 00404 }
Here is the call graph for this function:

| void QPolygon::point | ( | int | index, | |
| 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 at line 191 of file qpolygon.cpp.
References QVector< QPoint >::at(), int, and QVector< QPoint >::p.
00192 { 00193 QPoint p = at(index); 00194 if (x) 00195 *x = (int)p.x(); 00196 if (y) 00197 *y = (int)p.y(); 00198 }
Here is the call graph for this function:

| QPoint QPolygon::point | ( | int | index | ) | const [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the point at the given index.
Definition at line 82 of file qpolygon.h.
References QVector< QPoint >::at().
Here is the call graph for this function:

| void QPolygon::setPoint | ( | int | index, | |
| int | x, | |||
| int | y | |||
| ) | [inline] |
Sets the point at the given index to the point specified by ({x}, {y}).
Definition at line 79 of file qpolygon.h.
Referenced by Q3CanvasEllipse::areaPoints(), QCommonStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), putPoints(), and setPoints().
| void QPolygon::setPoint | ( | int | index, | |
| const QPoint & | point | |||
| ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the point at the given index to the given point.
Definition at line 76 of file qpolygon.h.
00077 { (*this)[index] = pt; }
| void QPolygon::setPoints | ( | int | nPoints, | |
| const int * | points | |||
| ) |
Resizes the polygon to nPoints and populates it with the given points.
The example code creates a polygon with two points (10, 20) and (30, 40):
snippets/polygon/polygon.cpp SETPOINTS static setPoints
Definition at line 238 of file qpolygon.cpp.
References i, QVector< QPoint >::resize(), and setPoint().
Referenced by QMotifStyle::drawPrimitive(), and QPolygon().
00239 { 00240 resize(nPoints); 00241 int i = 0; 00242 while (nPoints--) { 00243 setPoint(i++, *points, *(points+1)); 00244 points += 2; 00245 } 00246 }
Here is the call graph for this function:

| void QPolygon::setPoints | ( | int | nPoints, | |
| int | firstx, | |||
| int | firsty, | |||
| ... | ||||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Resizes the polygon to nPoints and populates it with the points specified by the variable argument list. The points are given as a sequence of integers, starting with firstx then firsty, and so on.
The example code creates a polygon with two points (10, 20) and (30, 40):
snippets/polygon/polygon.cpp SETPOINTS2 QPolygon setPoints
Definition at line 265 of file qpolygon.cpp.
References i, QVector< QPoint >::resize(), setPoint(), x, and y.
00266 { 00267 va_list ap; 00268 resize(nPoints); 00269 setPoint(0, firstx, firsty); 00270 int i = 0, x, y; 00271 va_start(ap, firsty); 00272 while (--nPoints) { 00273 x = va_arg(ap, int); 00274 y = va_arg(ap, int); 00275 setPoint(++i, x, y); 00276 } 00277 va_end(ap); 00278 }
Here is the call graph for this function:

| void QPolygon::putPoints | ( | int | index, | |
| int | nPoints, | |||
| const int * | points | |||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 291 of file qpolygon.cpp.
References i, QVector< QPoint >::resize(), setPoint(), and QVector< QPoint >::size().
Referenced by QMotifStyle::drawPrimitive(), and Skin::Skin().
00292 { 00293 if (index + nPoints > size()) 00294 resize(index + nPoints); 00295 int i = index; 00296 while (nPoints--) { 00297 setPoint(i++, *points, *(points+1)); 00298 points += 2; 00299 } 00300 }
Here is the call graph for this function:

| void QPolygon::putPoints | ( | int | index, | |
| int | nPoints, | |||
| int | firstx, | |||
| int | firsty, | |||
| ... | ||||
| ) |
Copies nPoints points from the variable argument list into this polygon from the given index.
The points are given as a sequence of integers, starting with firstx then firsty, and so on. The polygon is resized if {index+nPoints} exceeds its current size.
The example code creates a polygon with three points (4,5), (6,7) and (8,9), by expanding the polygon from 1 to 3 points:
snippets/polygon/polygon.cpp PUTPOINTS QPolygon putPoints
The following code has the same result, but here the putPoints() function overwrites rather than extends:
snippets/polygon/polygon.cpp PUTPOINTS2 QPolygon putPoints(1, 1
Definition at line 329 of file qpolygon.cpp.
References i, QVector< QPoint >::resize(), setPoint(), QVector< QPoint >::size(), x, and y.
00330 { 00331 va_list ap; 00332 if (index + nPoints > size()) 00333 resize(index + nPoints); 00334 if (nPoints <= 0) 00335 return; 00336 setPoint(index, firstx, firsty); 00337 int i = index, x, y; 00338 va_start(ap, firsty); 00339 while (--nPoints) { 00340 x = va_arg(ap, int); 00341 y = va_arg(ap, int); 00342 setPoint(++i, x, y); 00343 } 00344 va_end(ap); 00345 }
Here is the call graph for this function:

| void QPolygon::putPoints | ( | int | index, | |
| int | nPoints, | |||
| const QPolygon & | fromPolygon, | |||
| int | fromIndex = 0 | |||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Copies nPoints points from the given fromIndex ( 0 by default) in fromPolygon into this polygon, starting at the specified index. For example:
snippets/polygon/polygon.cpp PUTPOINTS3 QPolygon }
Definition at line 362 of file qpolygon.cpp.
References n, QVector< QPoint >::resize(), setPoint(), and QVector< QPoint >::size().
00363 { 00364 if (index + nPoints > size()) 00365 resize(index + nPoints); 00366 if (nPoints <= 0) 00367 return; 00368 int n = 0; 00369 while(n < nPoints) { 00370 setPoint(index + n, from[fromIndex+n]); 00371 ++n; 00372 } 00373 }
Here is the call graph for this function:

1.5.1