Qt 4.8
|
The QPolygon class provides a vector of points using integer precision. More...
#include <qpolygon.h>
Public Functions | |
QRect | boundingRect () const |
Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, 0) if the polygon is empty. More... | |
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 returns false. More... | |
QPolygon | intersected (const QPolygon &r) const |
Returns a polygon which is the intersection of this polygon and r. More... | |
operator QVariant () const | |
Returns the polygon as a QVariant. More... | |
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). More... | |
QPoint | point (int i) const |
Returns the point at the given index. More... | |
void | putPoints (int index, int nPoints, const int *points) |
Copies nPoints points from the points coord array into this point array, and resizes the point array if index+nPoints exceeds the size of the array. More... | |
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. More... | |
void | putPoints (int index, int nPoints, const QPolygon &from, int fromIndex=0) |
Copies nPoints points from the given fromIndex ( 0 by default) in fromPolygon into this polygon, starting at the specified index. More... | |
QPolygon () | |
Constructs a polygon with no points. More... | |
QPolygon (int size) | |
Constructs a polygon of the given size. More... | |
QPolygon (const QPolygon &a) | |
Constructs a copy of the given polygon. More... | |
QPolygon (const QVector< QPoint > &v) | |
Constructs a polygon containing the specified points. More... | |
QPolygon (const QRect &r, bool closed=false) | |
Constructs a polygon from the given rectangle. More... | |
QPolygon (int nPoints, const int *points) | |
Constructs a point array with nPoints points, taken from the points array. More... | |
void | setPoint (int index, int x, int y) |
Sets the point at the given index to the point specified by ({x}, {y}). More... | |
void | setPoint (int index, const QPoint &p) |
Sets the point at the given index to the given point. More... | |
void | setPoints (int nPoints, const int *points) |
Resizes the polygon to nPoints and populates it with the given points. More... | |
void | setPoints (int nPoints, int firstx, int firsty,...) |
Resizes the polygon to nPoints and populates it with the points specified by the variable argument list. More... | |
QPolygon | subtracted (const QPolygon &r) const |
Returns a polygon which is r subtracted from this polygon. More... | |
void | swap (QPolygon &other) |
Swaps polygon other with this polygon. More... | |
void | translate (int dx, int dy) |
Translates all points in the polygon by ({dx}, {dy}). More... | |
void | translate (const QPoint &offset) |
Translates all points in the polygon by the given offset. More... | |
QPolygon | translated (int dx, int dy) const |
Returns a copy of the polygon that is translated by ({dx}, {dy}). More... | |
QPolygon | translated (const QPoint &offset) const |
Returns a copy of the polygon that is translated by the given offset. More... | |
QPolygon | united (const QPolygon &r) const |
Returns a polygon which is the union of this polygon and r. More... | |
~QPolygon () | |
Destroys the polygon. More... | |
Public Functions inherited from QVector< QPoint > | |
void | append (const QPoint &t) |
Inserts value at the end of the vector. More... | |
const QPoint & | at (int i) const |
Returns the item at index position i in the vector. More... | |
reference | back () |
This function is provided for STL compatibility. More... | |
const_reference | back () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
iterator | begin () |
Returns an STL-style iterator pointing to the first item in the vector. More... | |
const_iterator | begin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
int | capacity () const |
Returns the maximum number of items that can be stored in the vector without forcing a reallocation. More... | |
void | clear () |
Removes all the elements from the vector and releases the memory used by the vector. More... | |
const_iterator | constBegin () const |
Returns a const STL-style iterator pointing to the first item in the vector. More... | |
const QPoint * | constData () const |
Returns a const pointer to the data stored in the vector. More... | |
const_iterator | constEnd () const |
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector. More... | |
bool | contains (const QPoint &t) const |
Returns true if the vector contains an occurrence of value; otherwise returns false. More... | |
int | count (const QPoint &t) const |
Returns the number of occurrences of value in the vector. More... | |
int | count () const |
Same as size(). More... | |
QPoint * | data () |
Returns a pointer to the data stored in the vector. More... | |
const QPoint * | data () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | detach () |
bool | empty () const |
This function is provided for STL compatibility. More... | |
iterator | end () |
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector. More... | |
const_iterator | end () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
bool | endsWith (const QPoint &t) const |
Returns true if this vector is not empty and its last item is equal to value; otherwise returns false. More... | |
iterator | erase (iterator begin, iterator end) |
Removes all the items from begin up to (but not including) end. More... | |
iterator | erase (iterator pos) |
Removes the item pointed to by the iterator pos from the vector, and returns an iterator to the next item in the vector (which may be end()). More... | |
QVector< QPoint > & | fill (const QPoint &t, int size=-1) |
Assigns value to all items in the vector. More... | |
QPoint & | first () |
Returns a reference to the first item in the vector. More... | |
const QPoint & | first () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
QPoint & | front () |
This function is provided for STL compatibility. More... | |
const_reference | front () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
int | indexOf (const QPoint &t, int from=0) const |
Returns the index position of the first occurrence of value in the vector, searching forward from index position from. More... | |
void | insert (int i, const QPoint &t) |
Inserts value at index position i in the vector. More... | |
void | insert (int i, int n, const QPoint &t) |
Inserts count copies of value at index position i in the vector. More... | |
iterator | insert (iterator before, int n, const QPoint &x) |
Inserts count copies of value in front of the item pointed to by the iterator before. More... | |
iterator | insert (iterator before, const QPoint &x) |
Inserts value in front of the item pointed to by the iterator before. More... | |
bool | isDetached () const |
bool | isEmpty () const |
Returns true if the vector has size 0; otherwise returns false. More... | |
bool | isSharedWith (const QVector< QPoint > &other) const |
QPoint & | last () |
Returns a reference to the last item in the vector. More... | |
const QPoint & | last () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
int | lastIndexOf (const QPoint &t, int from=-1) const |
Returns the index position of the last occurrence of the value value in the vector, searching backward from index position from. More... | |
QVector< QPoint > | mid (int pos, int length=-1) const |
Returns a vector whose elements are copied from this vector, starting at position pos. More... | |
bool | operator!= (const QVector< QPoint > &v) const |
Returns true if other is not equal to this vector; otherwise returns false. More... | |
QVector< QPoint > | operator+ (const QVector< QPoint > &l) const |
Returns a vector that contains all the items in this vector followed by all the items in the other vector. More... | |
QVector< QPoint > & | operator+= (const QVector< QPoint > &l) |
Appends the items of the other vector to this vector and returns a reference to this vector. More... | |
QVector< QPoint > & | operator+= (const QPoint &t) |
Appends value to the vector. More... | |
QVector< QPoint > & | operator<< (const QVector< QPoint > &l) |
Appends other to the vector and returns a reference to the vector. More... | |
QVector< QPoint > & | operator<< (const QPoint &t) |
Appends value to the vector and returns a reference to this vector. More... | |
QVector< QPoint > & | operator= (const QVector< QPoint > &v) |
Assigns other to this vector and returns a reference to this vector. More... | |
bool | operator== (const QVector< QPoint > &v) const |
Returns true if other is equal to this vector; otherwise returns false. More... | |
QPoint & | operator[] (int i) |
Returns the item at index position i as a modifiable reference. More... | |
const QPoint & | operator[] (int i) const |
Same as at(i). More... | |
void | pop_back () |
This function is provided for STL compatibility. More... | |
void | pop_front () |
This function is provided for STL compatibility. More... | |
void | prepend (const QPoint &t) |
Inserts value at the beginning of the vector. More... | |
void | push_back (const QPoint &t) |
This function is provided for STL compatibility. More... | |
void | push_front (const QPoint &t) |
This function is provided for STL compatibility. More... | |
QVector () | |
Constructs an empty vector. More... | |
QVector (int size) | |
Constructs a vector with an initial size of size elements. More... | |
QVector (int size, const QPoint &t) | |
Constructs a vector with an initial size of size elements. More... | |
QVector (const QVector< QPoint > &v) | |
Constructs a copy of other. More... | |
void | remove (int i) |
Removes the element at index position i. More... | |
void | remove (int i, int n) |
Removes count elements from the middle of the vector, starting at index position i. More... | |
void | replace (int i, const QPoint &t) |
Replaces the item at index position i with value. More... | |
void | reserve (int size) |
Attempts to allocate memory for at least size elements. More... | |
void | resize (int size) |
Sets the size of the vector to size. More... | |
void | setSharable (bool sharable) |
int | size () const |
Returns the number of items in the vector. More... | |
void | squeeze () |
Releases any memory not required to store the items. More... | |
bool | startsWith (const QPoint &t) const |
Returns true if this vector is not empty and its first item is equal to value; otherwise returns false. More... | |
void | swap (QVector< QPoint > &other) |
Swaps vector other with this vector. More... | |
QList< QPoint > | toList () const |
Returns a QList object with the data contained in this QVector. More... | |
std::vector< QPoint > | toStdVector () const |
Returns a std::vector object with the data contained in this QVector. More... | |
QPoint | value (int i) const |
Returns the value at index position i in the vector. More... | |
QPoint | value (int i, const QPoint &defaultValue) const |
If the index i is out of bounds, the function returns defaultValue. More... | |
~QVector () | |
Destroys the vector. More... | |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &stream, const QPolygon &polygon) |
Writes the given polygon to the given stream, and returns a reference to the stream. More... | |
QDataStream & | operator>> (QDataStream &stream, QPolygon &polygon) |
Reads a polygon from the given stream into the given polygon, and returns a reference to the stream. More... | |
Related Functions inherited from QVector< QPoint > | |
QDataStream & | operator<< (QDataStream &out, const QVector< QPoint > &vector) |
Writes the vector vector to stream out. More... | |
QDataStream & | operator>> (QDataStream &in, QVector< QPoint > &vector) |
Reads a vector from stream in into vector. More... | |
Additional Inherited Members | |
Public Types inherited from QVector< QPoint > | |
typedef const QPoint * | const_iterator |
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack. More... | |
typedef const value_type * | const_pointer |
Typedef for const T *. More... | |
typedef const value_type & | const_reference |
Typedef for T &. More... | |
typedef const_iterator | ConstIterator |
Qt-style synonym for QVector::const_iterator. More... | |
typedef qptrdiff | difference_type |
Typedef for ptrdiff_t. More... | |
typedef QPoint * | iterator |
The QVector::iterator typedef provides an STL-style non-const iterator for QVector and QStack. More... | |
typedef iterator | Iterator |
Qt-style synonym for QVector::iterator. More... | |
typedef value_type * | pointer |
Typedef for T *. More... | |
typedef value_type & | reference |
Typedef for T &. More... | |
typedef int | size_type |
Typedef for int. More... | |
typedef QPoint | value_type |
Typedef for T. More... | |
Static Public Functions inherited from QVector< QPoint > | |
static QVector< QPoint > | fromList (const QList< QPoint > &list) |
Returns a QVector object with the data contained in list. More... | |
static QVector< QPoint > | fromStdVector (const std::vector< QPoint > &vector) |
Returns a QVector object with the data contained in vector. More... | |
Public Variables inherited from QVector< QPoint > | |
QVectorData * | d |
Data * | p |
The QPolygon class provides a vector of points using integer precision.
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:
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.
Definition at line 60 of file qpolygon.h.
|
inline |
Constructs a polygon with no points.
Definition at line 63 of file qpolygon.h.
|
inline |
|
inline |
Constructs a polygon of the given size.
Creates an empty polygon if size == 0.
Definition at line 99 of file qpolygon.h.
|
inline |
Constructs a copy of the given polygon.
Definition at line 66 of file qpolygon.h.
Constructs a polygon containing the specified points.
Definition at line 67 of file qpolygon.h.
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 194 of file qpolygon.cpp.
QPolygon::QPolygon | ( | int | nPoints, |
const int * | points | ||
) |
Constructs a point array with nPoints points, taken from the points array.
Equivalent to setPoints(nPoints, points).
Definition at line 216 of file qpolygon.cpp.
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 492 of file qpolygon.cpp.
Referenced by QWindowsStyle::drawPrimitive(), QX11PaintEnginePrivate::fillPolygon_dev(), and QPolygonF::isClosed().
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 974 of file qpolygon.cpp.
Referenced by QPolygonF::isClosed().
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 1032 of file qpolygon.cpp.
Referenced by QPolygonF::isClosed().
QPolygon::operator QVariant | ( | ) | const |
Returns the polygon as a QVariant.
Definition at line 806 of file qpolygon.cpp.
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 297 of file qpolygon.cpp.
Referenced by QCommonStyle::drawControl().
|
inline |
Returns the point at the given index.
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 123 of file qpolygon.h.
void QPolygon::putPoints | ( | int | index, |
int | nPoints, | ||
const int * | points | ||
) |
Copies nPoints points from the points coord array into this point array, and resizes the point array if index+nPoints
exceeds the size of the array.
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 406 of file qpolygon.cpp.
Referenced by QMotifStyle::drawPrimitive(), and qDrawPlainRect().
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 438 of file qpolygon.cpp.
void QPolygon::putPoints | ( | int | index, |
int | nPoints, | ||
const QPolygon & | fromPolygon, | ||
int | fromIndex = 0 |
||
) |
Copies nPoints points from the given fromIndex ( 0 by default) in fromPolygon into this polygon, starting at the specified index.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
For example:
Definition at line 471 of file qpolygon.cpp.
|
inline |
Sets the point at the given index to the point specified by ({x}, {y}).
Definition at line 120 of file qpolygon.h.
Referenced by addPoint(), QWindowsStyle::drawComplexControl(), QCommonStyle::drawControl(), QCommonStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), putPoints(), qDrawPlainRect(), rot(), and setPoints().
|
inline |
Sets the point at the given index to the given point.
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 117 of file qpolygon.h.
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):
Definition at line 350 of file qpolygon.cpp.
Referenced by QWindowsCEStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QMotifStyle::drawControl(), QCommonStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMatrix::mapToPolygon(), QTransform::mapToPolygon(), QColorLuminancePicker::paintEvent(), qDrawPlainRect(), qDrawShadeLine(), and QPolygon().
void QPolygon::setPoints | ( | int | nPoints, |
int | firstx, | ||
int | firsty, | ||
... | |||
) |
Resizes the polygon to nPoints and populates it with the points specified by the variable argument list.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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 377 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 1053 of file qpolygon.cpp.
Referenced by QPolygonF::isClosed().
|
inline |
Swaps polygon other with this polygon.
This operation is very fast and never fails.
Definition at line 70 of file qpolygon.h.
void QPolygon::translate | ( | int | dx, |
int | dy | ||
) |
Translates all points in the polygon by ({dx}, {dy}).
Definition at line 238 of file qpolygon.cpp.
Referenced by QCommonStyle::drawControl(), QCommonStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), qDrawPlainRect(), QPolygonF::swap(), translate(), and translated().
|
inline |
Translates all points in the polygon by the given offset.
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 126 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 270 of file qpolygon.cpp.
Referenced by QTransform::map(), QPolygonF::swap(), and translated().
Returns a copy of the polygon that is translated by the given offset.
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 129 of file qpolygon.h.
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 1012 of file qpolygon.cpp.
Referenced by QPolygonF::isClosed().
|
related |
Writes the given polygon to the given stream, and returns a reference to the stream.
Definition at line 828 of file qpolygon.cpp.
Referenced by QPolygon().
|
related |
Reads a polygon from the given stream into the given polygon, and returns a reference to the stream.
Definition at line 847 of file qpolygon.cpp.
Referenced by QPolygon().