QtBase
v6.3.1
|
The QPolygon class provides a list of points using integer precision. \inmodule QtGui. More...
#include <qpolygon.h>
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &stream, const QPolygon &polygon) |
QDataStream & | operator>> (QDataStream &stream, QPolygon &polygon) |
Additional Inherited Members | |
Public Types inherited from QList< QPoint > | |
using | Type = QPoint |
using | value_type = QPoint |
using | pointer = QPoint * |
using | const_pointer = const QPoint * |
using | reference = QPoint & |
using | const_reference = const QPoint & |
using | size_type = qsizetype |
using | difference_type = qptrdiff |
using | parameter_type = typename DataPointer::parameter_type |
using | rvalue_ref = typename std::conditional< DataPointer::pass_parameter_by_value, DisableRValueRefs, QPoint && >::type |
using | Iterator = iterator |
using | ConstIterator = const_iterator |
using | reverse_iterator = std::reverse_iterator< iterator > |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Static Public Member Functions inherited from QList< QPoint > | |
static QList< QPoint > | fromList (const QList< QPoint > &list) noexcept |
static QList< QPoint > | fromVector (const QList< QPoint > &vector) noexcept |
static QList< QPoint > | fromReadOnlyData (const QPoint(&t)[N]) noexcept |
Protected Types inherited from QListSpecialMethodsBase< T > | |
using | Self = QList< T > |
Protected Member Functions inherited from QListSpecialMethods< QPoint > | |
~QListSpecialMethods ()=default | |
Protected Member Functions inherited from QListSpecialMethodsBase< T > | |
~QListSpecialMethodsBase ()=default | |
Self * | self () |
const Self * | self () const |
The QPolygon class provides a list of points using integer precision. \inmodule QtGui.
\reentrant
A QPolygon object is a QList<QPoint>. The easiest way to add points to a QPolygon is to use QList's streaming operator, as illustrated below:
In addition to the functions provided by QList, 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 QTransform::map() function for more general transformations of QPolygons.
The QPolygon class is \l {Implicit Data Sharing}{implicitly shared}.
Definition at line 56 of file qpolygon.h.
|
default |
Constructs a polygon with no points.
Constructs a polygon containing the specified points.
Definition at line 61 of file qpolygon.h.
Definition at line 62 of file qpolygon.h.
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 159 of file qpolygon.cpp.
QPolygon::QPolygon | ( | int | nPoints, |
const int * | points | ||
) |
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 422 of file qpolygon.cpp.
bool QPolygon::containsPoint | ( | const QPoint & | point, |
Qt::FillRule | fillRule | ||
) | const |
Returns true
if the given point is inside the polygon according to the specified fillRule; otherwise returns false
.
Definition at line 818 of file qpolygon.cpp.
Returns a polygon which is the intersection of this polygon and r.
Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.
Definition at line 872 of file qpolygon.cpp.
Returns true
if the current polygon intersects at any point the given polygon p. Also returns true
if the current polygon contains or is contained by any part of p.
Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.
Definition at line 910 of file qpolygon.cpp.
QPolygon::operator QVariant | ( | ) | const |
Returns the polygon as a QVariant
Definition at line 673 of file qpolygon.cpp.
|
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 116 of file qpolygon.h.
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 242 of file qpolygon.cpp.
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 339 of file qpolygon.cpp.
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:
Definition at line 401 of file qpolygon.cpp.
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:
The following code has the same result, but here the putPoints() function overwrites rather than extends:
Definition at line 371 of file qpolygon.cpp.
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 113 of file qpolygon.h.
void QPolygon::setPoint | ( | int | index, |
int | x, | ||
int | y | ||
) |
Sets the point at the given index to the point specified by ({x}, {y}).
Definition at line 271 of file qpolygon.cpp.
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):
Definition at line 289 of file qpolygon.cpp.
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):
Definition at line 313 of file qpolygon.cpp.
Returns a polygon which is r subtracted from this polygon.
Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.
Definition at line 890 of file qpolygon.cpp.
Swaps polygon other with this polygon. This operation is very fast and never fails.
Definition at line 65 of file qpolygon.h.
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 119 of file qpolygon.h.
void QPolygon::translate | ( | int | dx, |
int | dy | ||
) |
Translates all points in the polygon by ({dx}, {dy}).
Definition at line 189 of file qpolygon.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a copy of the polygon that is translated by the given offset.
Definition at line 122 of file qpolygon.h.
QPolygon QPolygon::translated | ( | int | dx, |
int | dy | ||
) | const |
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition at line 218 of file qpolygon.cpp.
Returns a polygon which is the union of this polygon and r.
Set operations on polygons, will treat the polygons as areas, and implicitly close the polygon.
Definition at line 853 of file qpolygon.cpp.
|
related |
Writes the given polygon to the given stream, and returns a reference to the stream.
Definition at line 692 of file qpolygon.cpp.
|
related |
Reads a polygon from the given stream into the given polygon, and returns a reference to the stream.
Definition at line 708 of file qpolygon.cpp.