![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QPolygon class provides a list of points using integer precision. More...
#include <qpolygon.h>
Public Member Functions | |
QPolygon ()=default | |
Constructs a polygon with no points. | |
Q_IMPLICIT | QPolygon (const QList< QPoint > &v) |
Constructs a polygon containing the specified points. | |
Q_IMPLICIT | QPolygon (QList< QPoint > &&v) noexcept |
Q_IMPLICIT Q_GUI_EXPORT | QPolygon (const QRect &r, bool closed=false) |
Constructs a polygon from the given rectangle. | |
Q_GUI_EXPORT | QPolygon (int nPoints, const int *points) |
void | swap (QPolygon &other) noexcept |
Q_GUI_EXPORT | operator QVariant () const |
Returns the polygon as a QVariant. | |
Q_GUI_EXPORT void | translate (int dx, int dy) |
Translates all points in the polygon by ({dx}, {dy}). | |
void | translate (const QPoint &offset) |
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. | |
Q_GUI_EXPORT QPolygon | translated (int dx, int dy) const |
Returns a copy of the polygon that is translated by ({dx}, {dy}). | |
QPolygon | translated (const QPoint &offset) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Q_GUI_EXPORT QRect | boundingRect () const |
Returns the bounding rectangle of the polygon, or QRect(0, 0, 0,
0) if the polygon is empty. | |
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). | |
QPoint | point (int i) const |
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. | |
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}). | |
void | setPoint (int index, const QPoint &p) |
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. | |
Q_GUI_EXPORT void | setPoints (int nPoints, const int *points) |
Resizes the polygon to nPoints and populates it with the given points. | |
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 only in what argument(s) it accepts.Resizes the polygon to nPoints and populates it with the points specified by the variable argument list. | |
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 only in what argument(s) it accepts. | |
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. | |
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 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. | |
Q_GUI_EXPORT bool | containsPoint (const QPoint &pt, Qt::FillRule fillRule) const |
Q_GUI_EXPORT QPolygon | united (const QPolygon &r) const |
Q_GUI_EXPORT QPolygon | intersected (const QPolygon &r) const |
Q_GUI_EXPORT QPolygon | subtracted (const QPolygon &r) const |
Q_GUI_EXPORT bool | intersects (const QPolygon &r) const |
QPolygonF | toPolygonF () const |
![]() | |
DataPointer & | data_ptr () & |
const DataPointer & | data_ptr () const & |
DataPointer && | data_ptr () && |
QList (DataPointer dd) noexcept | |
constexpr | QList () noexcept=default |
QList (qsizetype size) | |
QList (qsizetype size, parameter_type t) | |
QList (std::initializer_list< QPoint > args) | |
QList (InputIterator i1, InputIterator i2) | |
QList (const String &str) | |
QList (qsizetype size, Qt::Initialization) | |
QList< QPoint > & | operator= (std::initializer_list< QPoint > args) |
void | swap (QList &other) noexcept |
QTypeTraits::compare_eq_result_container< QList, U > | operator== (const QList &other) const |
QTypeTraits::compare_eq_result_container< QList, U > | operator!= (const QList &other) const |
QTypeTraits::compare_lt_result_container< QList, U > | operator< (const QList &other) const noexcept(noexcept(std::lexicographical_compare< typename QList< U >::const_iterator, typename QList::const_iterator >(std::declval< QList< U > >().begin(), std::declval< QList< U > >().end(), other.begin(), other.end()))) |
QTypeTraits::compare_lt_result_container< QList, U > | operator> (const QList &other) const noexcept(noexcept(other< std::declval< QList< U > >())) |
QTypeTraits::compare_lt_result_container< QList, U > | operator<= (const QList &other) const noexcept(noexcept(other< std::declval< QList< U > >())) |
QTypeTraits::compare_lt_result_container< QList, U > | operator>= (const QList &other) const noexcept(noexcept(std::declval< QList< U > >()< other)) |
constexpr qsizetype | size () const noexcept |
constexpr qsizetype | count () const noexcept |
qsizetype | count (const AT &t) const noexcept |
constexpr qsizetype | length () const noexcept |
constexpr bool | isEmpty () const noexcept |
void | resize (qsizetype size) |
void | resize (qsizetype size, parameter_type c) |
void | resizeForOverwrite (qsizetype size) |
qsizetype | capacity () const |
void | reserve (qsizetype size) |
void | squeeze () |
void | detach () |
bool | isDetached () const noexcept |
bool | isSharedWith (const QList< QPoint > &other) const |
pointer | data () |
const_pointer | data () const noexcept |
const_pointer | constData () const noexcept |
void | clear () |
const_reference | at (qsizetype i) const noexcept |
reference | operator[] (qsizetype i) |
const_reference | operator[] (qsizetype i) const noexcept |
void | append (parameter_type t) |
void | append (const_iterator i1, const_iterator i2) |
void | append (rvalue_ref t) |
void | append (const QList< QPoint > &l) |
void | append (QList< QPoint > &&l) |
void | prepend (rvalue_ref t) |
void | prepend (parameter_type t) |
reference | emplaceBack (Args &&... args) |
reference | emplaceFront (Args &&... args) |
iterator | insert (qsizetype i, parameter_type t) |
iterator | insert (qsizetype i, qsizetype n, parameter_type t) |
iterator | insert (const_iterator before, parameter_type t) |
iterator | insert (const_iterator before, qsizetype n, parameter_type t) |
iterator | insert (const_iterator before, rvalue_ref t) |
iterator | insert (qsizetype i, rvalue_ref t) |
QList & | assign (qsizetype n, parameter_type t) |
QList & | assign (InputIterator first, InputIterator last) |
QList & | assign (std::initializer_list< QPoint > l) |
iterator | emplace (const_iterator before, Args &&... args) |
iterator | emplace (qsizetype i, Args &&... args) |
void | replace (qsizetype i, parameter_type t) |
void | replace (qsizetype i, rvalue_ref t) |
void | remove (qsizetype i, qsizetype n=1) |
void | removeFirst () noexcept |
void | removeLast () noexcept |
value_type | takeFirst () |
value_type | takeLast () |
QList< QPoint > & | fill (parameter_type t, qsizetype size=-1) |
void | removeAt (qsizetype i) |
qsizetype | removeAll (const AT &t) |
bool | removeOne (const AT &t) |
qsizetype | removeIf (Predicate pred) |
QPoint | takeAt (qsizetype i) |
void | move (qsizetype from, qsizetype to) |
iterator | begin () |
const_iterator | begin () const noexcept |
iterator | end () |
const_iterator | end () const noexcept |
const_iterator | cbegin () const noexcept |
const_iterator | cend () const noexcept |
const_iterator | constBegin () const noexcept |
const_iterator | constEnd () const noexcept |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const noexcept |
reverse_iterator | rend () |
const_reverse_iterator | rend () const noexcept |
const_reverse_iterator | crbegin () const noexcept |
const_reverse_iterator | crend () const noexcept |
iterator | erase (const_iterator begin, const_iterator end) |
iterator | erase (const_iterator pos) |
QPoint & | first () |
const QPoint & | first () const noexcept |
QList< QPoint > | first (qsizetype n) const |
const QPoint & | constFirst () const noexcept |
QPoint & | last () |
const QPoint & | last () const noexcept |
QList< QPoint > | last (qsizetype n) const |
const QPoint & | constLast () const noexcept |
bool | startsWith (parameter_type t) const |
bool | endsWith (parameter_type t) const |
QList< QPoint > | mid (qsizetype pos, qsizetype len=-1) const |
QList< QPoint > | sliced (qsizetype pos) const |
QList< QPoint > | sliced (qsizetype pos, qsizetype n) const |
QPoint | value (qsizetype i) const |
QPoint | value (qsizetype i, parameter_type defaultValue) const |
void | swapItemsAt (qsizetype i, qsizetype j) |
void | push_back (parameter_type t) |
void | push_back (rvalue_ref t) |
void | push_front (rvalue_ref t) |
void | push_front (parameter_type t) |
void | pop_back () noexcept |
void | pop_front () noexcept |
reference | emplace_back (Args &&... args) |
bool | empty () const noexcept |
reference | front () |
const_reference | front () const noexcept |
reference | back () |
const_reference | back () const noexcept |
void | shrink_to_fit () |
constexpr qsizetype | max_size () const noexcept |
QList< QPoint > & | operator+= (const QList< QPoint > &l) |
QList< QPoint > & | operator+= (QList< QPoint > &&l) |
QList< QPoint > & | operator+= (parameter_type t) |
QList< QPoint > & | operator+= (rvalue_ref t) |
QList< QPoint > | operator+ (const QList< QPoint > &l) const & |
QList< QPoint > | operator+ (const QList< QPoint > &l) && |
QList< QPoint > | operator+ (QList< QPoint > &&l) const & |
QList< QPoint > | operator+ (QList< QPoint > &&l) && |
QList< QPoint > & | operator<< (parameter_type t) |
QList< QPoint > & | operator<< (const QList< QPoint > &l) |
QList< QPoint > & | operator<< (QList< QPoint > &&l) |
QList< QPoint > & | operator<< (rvalue_ref t) |
QList< QPoint > | toList () const noexcept |
QList< QPoint > | toVector () const noexcept |
![]() | |
qsizetype | indexOf (const AT &t, qsizetype from=0) const noexcept |
qsizetype | lastIndexOf (const AT &t, qsizetype from=-1) const noexcept |
bool | contains (const AT &t) const noexcept |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &stream, const QPolygon &polygon) |
QDataStream & | operator>> (QDataStream &stream, QPolygon &polygon) |
Additional Inherited Members | |
![]() | |
using | Type |
using | value_type |
using | pointer |
using | const_pointer |
using | reference |
using | const_reference |
using | size_type |
using | difference_type |
using | parameter_type |
using | rvalue_ref |
using | Iterator |
using | ConstIterator |
using | reverse_iterator |
using | const_reverse_iterator |
![]() | |
static constexpr qsizetype | maxSize () |
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 |
![]() | |
using | Self |
![]() | |
QListSpecialMethods ()=default | |
![]() | |
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 22 of file qpolygon.h.
|
default |
Constructs a polygon with no points.
|
inline |
Constructs a polygon containing the specified points.
Definition at line 27 of file qpolygon.h.
|
inlinenoexcept |
Definition at line 28 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 123 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 142 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 386 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 762 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 816 of file qpolygon.cpp.
bool QPolygon::intersects | ( | const QPolygon & | p | ) | const |
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 854 of file qpolygon.cpp.
QPolygon::operator QVariant | ( | ) | const |
Returns the polygon as a QVariant.
Definition at line 638 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 84 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 206 of file qpolygon.cpp.
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.
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.
Definition at line 303 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 365 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 335 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 81 of file qpolygon.h.
References setPoint().
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 235 of file qpolygon.cpp.
Referenced by setPoint().
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 253 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 277 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 834 of file qpolygon.cpp.
Definition at line 31 of file qpolygon.h.
|
inlinenodiscard |
Returns this polygon as a polygon with floating point accuracy.
Definition at line 130 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 87 of file qpolygon.h.
References translate().
void QPolygon::translate | ( | int | dx, |
int | dy ) |
Translates all points in the polygon by ({dx}, {dy}).
Definition at line 153 of file qpolygon.cpp.
Referenced by translate().
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 90 of file qpolygon.h.
|
nodiscard |
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition at line 182 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 797 of file qpolygon.cpp.
|
Writes the given polygon to the given stream, and returns a reference to the stream.
|
Reads a polygon from the given stream into the given polygon, and returns a reference to the stream.