QtBase  v6.3.1
Public Member Functions | Related Functions | List of all members
QPolygon Class Reference

The QPolygon class provides a list of points using integer precision. \inmodule QtGui. More...

#include <qpolygon.h>

Inheritance diagram for QPolygon:
Inheritance graph
[legend]
Collaboration diagram for QPolygon:
Collaboration graph
[legend]

Public Member Functions

 QPolygon ()=default
 
Q_IMPLICIT QPolygon (const QList< QPoint > &v)
 
Q_IMPLICIT QPolygon (QList< QPoint > &&v) noexcept
 
Q_IMPLICIT Q_GUI_EXPORT QPolygon (const QRect &r, bool closed=false)
 
Q_GUI_EXPORT QPolygon (int nPoints, const int *points)
 
void swap (QPolygon &other) noexcept
 
Q_GUI_EXPORT operator QVariant () const
 
Q_GUI_EXPORT void translate (int dx, int dy)
 
void translate (const QPoint &offset)
 
Q_GUI_EXPORT QPolygon translated (int dx, int dy) const
 
QPolygon translated (const QPoint &offset) const
 
Q_GUI_EXPORT QRect boundingRect () const
 
Q_GUI_EXPORT void point (int i, int *x, int *y) const
 
QPoint point (int i) const
 
Q_GUI_EXPORT void setPoint (int index, int x, int y)
 
void setPoint (int index, const QPoint &p)
 
Q_GUI_EXPORT void setPoints (int nPoints, const int *points)
 
Q_GUI_EXPORT void setPoints (int nPoints, int firstx, int firsty,...)
 
Q_GUI_EXPORT void putPoints (int index, int nPoints, const int *points)
 
Q_GUI_EXPORT void putPoints (int index, int nPoints, int firstx, int firsty,...)
 
Q_GUI_EXPORT void putPoints (int index, int nPoints, const QPolygon &from, int fromIndex=0)
 
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
 
- Public Member Functions inherited from QList< QPoint >
 QList (DataPointer dd) noexcept
 
 QList ()=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< QPoint > & operator= (std::initializer_list< QPoint > args)
 
void swap (QList &other) noexcept
 
QTypeTraits::compare_eq_result_container< QList, Uoperator== (const QList &other) const
 
QTypeTraits::compare_eq_result_container< QList, Uoperator!= (const QList &other) const
 
QTypeTraits::compare_lt_result_container< QList, Uoperator< (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, Uoperator> (const QList &other) const noexcept(noexcept(other< std::declval< QList< U >>()))
 
QTypeTraits::compare_lt_result_container< QList, Uoperator<= (const QList &other) const noexcept(noexcept(other< std::declval< QList< U >>()))
 
QTypeTraits::compare_lt_result_container< QList, Uoperator>= (const QList &other) const noexcept(noexcept(std::declval< QList< U >>()< other))
 
qsizetype size () const noexcept
 
qsizetype count () const noexcept
 
qsizetype count (const AT &t) const noexcept
 
qsizetype length () const noexcept
 
bool isEmpty () const noexcept
 
void resize (qsizetype size)
 
void resize (qsizetype size, parameter_type c)
 
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)
 
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)
 
QPointfirst ()
 
const QPointfirst () const noexcept
 
QList< QPointfirst (qsizetype n) const
 
const QPointconstFirst () const noexcept
 
QPointlast ()
 
const QPointlast () const noexcept
 
QList< QPointlast (qsizetype n) const
 
const QPointconstLast () const noexcept
 
bool startsWith (parameter_type t) const
 
bool endsWith (parameter_type t) const
 
QList< QPointmid (qsizetype pos, qsizetype len=-1) const
 
QList< QPointsliced (qsizetype pos) const
 
QList< QPointsliced (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 ()
 
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< QPointoperator+ (const QList< QPoint > &l) const
 
QList< QPointoperator+ (QList< QPoint > &&l) const
 
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< QPointtoList () const noexcept
 
QList< QPointtoVector () const noexcept
 
- Public Member Functions inherited from QListSpecialMethodsBase< T >
template<typename AT = T>
qsizetype indexOf (const AT &t, qsizetype from=0) const noexcept
 
template<typename AT = T>
qsizetype lastIndexOf (const AT &t, qsizetype from=-1) const noexcept
 
template<typename AT = T>
bool contains (const AT &t) const noexcept
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &stream, const QPolygon &polygon)
 
QDataStreamoperator>> (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< QPointfromList (const QList< QPoint > &list) noexcept
 
static QList< QPointfromVector (const QList< QPoint > &vector) noexcept
 
static QList< QPointfromReadOnlyData (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
 
Selfself ()
 
const Selfself () const
 

Detailed Description

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}.

See also
QList, QPolygonF, QLine

Definition at line 56 of file qpolygon.h.

Constructor & Destructor Documentation

◆ QPolygon() [1/5]

QPolygon::QPolygon ( )
default

Constructs a polygon with no points.

See also
QList::isEmpty()

◆ QPolygon() [2/5]

QPolygon::QPolygon ( const QList< QPoint > &  points)
inline

Constructs a polygon containing the specified points.

See also
setPoints()

Definition at line 61 of file qpolygon.h.

◆ QPolygon() [3/5]

Q_IMPLICIT QPolygon::QPolygon ( QList< QPoint > &&  v)
inlinenoexcept

Definition at line 62 of file qpolygon.h.

◆ QPolygon() [4/5]

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()).

See also
setPoints()

Definition at line 159 of file qpolygon.cpp.

Here is the call graph for this function:

◆ QPolygon() [5/5]

QPolygon::QPolygon ( int  nPoints,
const int *  points 
)

Definition at line 178 of file qpolygon.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ boundingRect()

QRect QPolygon::boundingRect ( ) const

Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, 0) if the polygon is empty.

See also
QList::isEmpty()

Definition at line 422 of file qpolygon.cpp.

Here is the call graph for this function:

◆ containsPoint()

bool QPolygon::containsPoint ( const QPoint point,
Qt::FillRule  fillRule 
) const
Since
4.3

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.

Here is the call graph for this function:

◆ intersected()

QPolygon QPolygon::intersected ( const QPolygon r) const
Since
4.3

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.

See also
intersects()

Definition at line 872 of file qpolygon.cpp.

Here is the call graph for this function:

◆ intersects()

bool QPolygon::intersects ( const QPolygon p) const
Since
5.10

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.

See also
intersected()

Definition at line 910 of file qpolygon.cpp.

Here is the call graph for this function:

◆ operator QVariant()

QPolygon::operator QVariant ( ) const

Returns the polygon as a QVariant

Definition at line 673 of file qpolygon.cpp.

Here is the call graph for this function:

◆ point() [1/2]

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 116 of file qpolygon.h.

Here is the call graph for this function:

◆ point() [2/2]

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).

See also
setPoint()

Definition at line 242 of file qpolygon.cpp.

Here is the call graph for this function:

◆ putPoints() [1/3]

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 339 of file qpolygon.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ putPoints() [2/3]

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.

Here is the call graph for this function:

◆ putPoints() [3/3]

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:

See also
setPoints()

Definition at line 371 of file qpolygon.cpp.

Here is the call graph for this function:

◆ setPoint() [1/2]

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 113 of file qpolygon.h.

Here is the call graph for this function:

◆ setPoint() [2/2]

void QPolygon::setPoint ( int  index,
int  x,
int  y 
)

Sets the point at the given index to the point specified by ({x}, {y}).

See also
point(), putPoints(), setPoints(),

Definition at line 271 of file qpolygon.cpp.

Here is the caller graph for this function:

◆ setPoints() [1/2]

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):

See also
setPoint(), putPoints()

Definition at line 289 of file qpolygon.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPoints() [2/2]

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.

Here is the call graph for this function:

◆ subtracted()

QPolygon QPolygon::subtracted ( const QPolygon r) const
Since
4.3

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.

Here is the call graph for this function:

◆ swap()

void QPolygon::swap ( QPolygon other)
inlinenoexcept
Since
4.8

Swaps polygon other with this polygon. This operation is very fast and never fails.

Definition at line 65 of file qpolygon.h.

Here is the call graph for this function:

◆ translate() [1/2]

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.

See also
translated()

Definition at line 119 of file qpolygon.h.

Here is the call graph for this function:

◆ translate() [2/2]

void QPolygon::translate ( int  dx,
int  dy 
)

Translates all points in the polygon by ({dx}, {dy}).

See also
translated()

Definition at line 189 of file qpolygon.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ translated() [1/2]

QPolygon QPolygon::translated ( const QPoint offset) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

Returns a copy of the polygon that is translated by the given offset.

See also
translate()

Definition at line 122 of file qpolygon.h.

Here is the call graph for this function:

◆ translated() [2/2]

QPolygon QPolygon::translated ( int  dx,
int  dy 
) const

Returns a copy of the polygon that is translated by ({dx}, {dy}).

Since
4.6
See also
translate()

Definition at line 218 of file qpolygon.cpp.

Here is the caller graph for this function:

◆ united()

QPolygon QPolygon::united ( const QPolygon r) const
Since
4.3

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.

See also
intersected(), subtracted()

Definition at line 853 of file qpolygon.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<()

QDataStream & operator<< ( QDataStream stream,
const QPolygon polygon 
)
related
Since
4.4

Writes the given polygon to the given stream, and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 692 of file qpolygon.cpp.

◆ operator>>()

QDataStream & operator>> ( QDataStream stream,
QPolygon polygon 
)
related
Since
4.4

Reads a polygon from the given stream into the given polygon, and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 708 of file qpolygon.cpp.


The documentation for this class was generated from the following files: