CopperSpice API  1.9.1
QPolygon Class Reference

The QPolygon class provides a vector of points using integer precision. More...

Inheritance diagram for QPolygon:
QVector< QPoint >

Public Methods

 QPolygon ()
 
 QPolygon (const QPolygon &other)
 
 QPolygon (const QRect &rect, bool closed=false)
 
 QPolygon (const QVector< QPoint > &points)
 
 QPolygon (int size)
 
 QPolygon (QPolygon &&other)
 
 QPolygon (QVector< QPoint > &&points)
 
 ~QPolygon ()
 
QRect boundingRect () const
 
bool containsPoint (const QPoint &point, Qt::FillRule fillRule) const
 
QPolygon intersected (const QPolygon &other) const
 
bool intersects (const QPolygon &other) const
 
 operator QVariant () const
 
QPolygon & operator= (const QPolygon &other)
 
QPolygon & operator= (QPolygon &&other)
 
QPoint point (int index) const
 
void point (int index, int *x, int *y) const
 
void putPoints (int index, int nPoints, const QPolygon &fromPolygon, int fromIndex=0)
 
void putPoints (int index, int nPoints, int firstx, int firsty,...)
 
void setPoint (int index, const QPoint &point)
 
void setPoint (int index, int x, int y)
 
void setPoints (int nPoints, const int *points)
 
void setPoints (int nPoints, int firstx, int firsty,...)
 
QPolygon subtracted (const QPolygon &other) const
 
void swap (QPolygon &other)
 
void translate (const QPoint &offset)
 
void translate (int dx, int dy)
 
QPolygon translated (const QPoint &offset) const
 
QPolygon translated (int dx, int dy) const
 
QPolygon united (const QPolygon &other) const
 
- Public Methods inherited from QVector< QPoint >
 QVector () = default
 
 QVector (const QVector< QPoint > &other) = default
 
 QVector (Input_Iterator first, Input_Iterator last)
 
 QVector (QVector< QPoint > &&other) = default
 
 QVector (size_type size)
 
 QVector (size_type size, const QPoint &value)
 
 QVector (std::initializer_list< QPoint > args)
 
 ~QVector () = default
 
void append (const QPoint &value)
 
void append (const QVector< QPoint > &other)
 
void append (Iter begin, Iter end)
 
void append (QPoint &&value)
 
const_reference at (size_type pos) const
 
reference back ()
 
const_reference back () const
 
iterator begin ()
 
const_iterator begin () const
 
size_type capacity () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
const_iterator constBegin () const
 
const QPointconstData () const
 
const_iterator constEnd () const
 
const_reference constFirst () const
 
const_reference constLast () const
 
bool contains (const QPoint &value) const
 
size_type count () const
 
size_type count (const QPoint &value) const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
QPointdata ()
 
const QPointdata () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
bool endsWith (const QPoint &value) const
 
iterator erase (const_iterator begin, const_iterator end)
 
iterator erase (const_iterator pos)
 
QVector< QPoint > & fill (const QPoint &value, size_type size=-1)
 
reference first ()
 
const_reference first () const
 
reference front ()
 
const_reference front () const
 
size_type indexOf (const QPoint &value, size_type from=0) const
 
iterator insert (iterator before, const QPoint &value)
 
iterator insert (iterator before, size_type count, const QPoint &value)
 
iterator insert (iterator pos, Iter begin, Iter end)
 
void insert (size_type pos, const QPoint &value)
 
void insert (size_type pos, size_type count, const QPoint &value)
 
bool isEmpty () const
 
reference last ()
 
const_reference last () const
 
size_type lastIndexOf (const QPoint &value, size_type from=-1) const
 
size_type length () const
 
QVector< QPointmid (size_type pos, size_type length=-1) const
 
void move (size_type from, size_type to)
 
bool operator!= (const QVector< QPoint > &other) const
 
QVector< QPointoperator+ (const QVector< QPoint > &other) const
 
QVector< QPoint > & operator+= (const QPoint &value)
 
QVector< QPoint > & operator+= (const QVector< QPoint > &other)
 
QVector< QPoint > & operator<< (const QPoint &value)
 
QVector< QPoint > & operator<< (const QVector< QPoint > &other)
 
QVector< QPoint > & operator= (const QVector< QPoint > &other) = default
 
QVector< QPoint > & operator= (QVector< QPoint > &&other) = default
 
bool operator== (const QVector< QPoint > &other) const
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
void pop_back ()
 
void pop_front ()
 
void prepend (const QPoint &value)
 
void push_back (const QPoint &value)
 
void push_back (QPoint &&value)
 
void push_front (const QPoint &value)
 
void push_front (QPoint &&value)
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
void remove (size_type pos)
 
void remove (size_type pos, size_type count)
 
size_type removeAll (const QPoint &value)
 
void removeAt (size_type pos)
 
void removeFirst ()
 
void removeLast ()
 
bool removeOne (const QPoint &value)
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
void replace (size_type i, const QPoint &value)
 
void reserve (size_type size)
 
void resize (size_type size)
 
size_type size () const
 
void squeeze ()
 
bool startsWith (const QPoint &value) const
 
void swap (QVector< QPoint > &other)
 
QPoint takeAt (size_type pos)
 
QPoint takeFirst ()
 
QPoint takeLast ()
 
QList< QPointtoList () const
 
std::vector< QPointtoStdVector () const
 
QPoint value (size_type pos) const
 
QPoint value (size_type pos, const QPoint &defaultValue) const
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QPolygon &polygon)
 
QDataStreamoperator>> (QDataStream &stream, QPolygon &polygon)
 

Additional Inherited Members

- Public Typedefs inherited from QVector< QPoint >
using allocator_type = typename std::vector< QPoint >::allocator_type
 
using const_iterator = typename std::vector< QPoint >::const_iterator
 
using const_pointer = typename std::vector< QPoint >::const_pointer
 
using const_reference = typename std::vector< QPoint >::const_reference
 
using const_reverse_iterator = typename std::vector< QPoint >::const_reverse_iterator
 
using difference_type = typename std::vector< QPoint >::difference_type
 
using iterator = typename std::vector< QPoint >::iterator
 
using Java_Iterator = QVectorIterator< QPoint >
 
using Java_MutableIterator = QMutableVectorIterator< QPoint >
 
using pointer = typename std::vector< QPoint >::pointer
 
using reference = typename std::vector< QPoint >::reference
 
using reverse_iterator = typename std::vector< QPoint >::reverse_iterator
 
using size_type = typename std::vector< QPoint >::difference_type
 
using value_type = typename std::vector< QPoint >::value_type
 
- Static Public Methods inherited from QVector< QPoint >
static QVector< QPointfromList (const QList< QPoint > &list)
 
static QVector< QPointfromStdVector (const std::vector< QPoint > &vector)
 

Detailed Description

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 the streaming operator as illustrated below.

QPolygon polygon;
polygon << QPoint(10, 20) << QPoint(20, 30);

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 implicitly shared.

See also
QVector, QPolygonF, QLine

Constructor & Destructor Documentation

QPolygon::QPolygon ( )
inline

Constructs a polygon with no points.

See also
QVector::isEmpty()
QPolygon::QPolygon ( int  size)
inlineexplicit

Constructs a polygon of the given size. Creates an empty polygon if size == 0.

See also
QVector::isEmpty()
QPolygon::QPolygon ( const QPolygon &  other)
inline

Constructs a copy of other.

See also
setPoints()
QPolygon::QPolygon ( QPolygon &&  other)
inline

Move constructs a copy of other.

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

Constructs a polygon containing the specified points.

See also
setPoints()
QPolygon::QPolygon ( QVector< QPoint > &&  points)
inline

Move constructs a polygon containing the specified points.

See also
setPoints()
QPolygon::QPolygon ( const QRect rect,
bool  closed = false 
)

Constructs a polygon from the given rect. 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().

The bottom-right corner of the rectangle is located at (rectangle.x() + rectangle.width(), rectangle.y() + rectangle.height()).

See also
setPoints()
QPolygon::~QPolygon ( )
inline

Destroys the polygon object.

Method Documentation

QRect QPolygon::boundingRect ( ) const

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

See also
QVector::isEmpty()
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.

QPolygon QPolygon::intersected ( const QPolygon &  other) const

Returns a polygon which is the intersection of this polygon and other. Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.

bool QPolygon::intersects ( const QPolygon &  other) const

Returns true if the current polygon intersects at any point the given other. Also returns true if the current polygon contains or is contained by any part of rectangle. Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.

QPolygon::operator QVariant ( ) const

Returns the polygon as a QVariant.

QPolygon & QPolygon::operator= ( const QPolygon &  other)
inline

Copy assigns from other and returns a reference to this object

QPolygon & QPolygon::operator= ( QPolygon &&  other)
inline

Move assigns from other and returns a reference to this object.

QPoint QPolygon::point ( int  index) const
inline

Returns the point at the given index.

See also
setPoint()
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()
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.

QPolygon polygon1;
polygon1.putPoints(0, 3, 1,2, 0,0, 5,6); // polygon1 is now the three-point polygon(1,2, 0,0, 5,6);
QPolygon polygon2;
polygon2.putPoints(0, 3, 4,4, 5,5, 6,6); // polygon2 is now (4,4, 5,5, 6,6);
polygon1.putPoints(2, 3, polygon2); // polygon1 is now the five-point polygon(1,2, 0,0, 4,4, 5,5, 6,6);
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:

QPolygon polygon(1);
polygon[0] = QPoint(4, 5);
polygon.putPoints(1, 2, 6,7, 8,9);

The following code has the same result, but here the putPoints() function overwrites rather than extends:

QPolygon polygon(3);
polygon.putPoints(0, 3, 4,5, 0,0, 8,9);
polygon.putPoints(1, 1, 6,7);
See also
setPoints()
void QPolygon::setPoint ( int  index,
const QPoint point 
)
inline

Sets the point at the given index to the given point.

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

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

See also
point(), putPoints(), setPoints()
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):

static const int points[] = { 10, 20, 30, 40 };
QPolygon polygon;
polygon.setPoints(2, points);
See also
setPoint(), putPoints()
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. 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):

QPolygon polygon;
polygon.setPoints(2, 10, 20, 30, 40);
QPolygon QPolygon::subtracted ( const QPolygon &  other) const

Returns a polygon which is other subtracted from this polygon. Set operations on polygons will treat the polygons as areas. Non-closed polygons will be treated as implicitly closed.

void QPolygon::swap ( QPolygon &  other)
inline

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

void QPolygon::translate ( const QPoint offset)
inline

Translates all points in the polygon by the given offset.

See also
translated()
void QPolygon::translate ( int  dx,
int  dy 
)

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

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

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

See also
translate()
QPolygon QPolygon::translated ( int  dx,
int  dy 
) const

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

See also
translate()
QPolygon QPolygon::united ( const QPolygon &  other) const

Returns a polygon which is the union of this polygon and other. Set operations on polygons will treat the polygons as areas and implicitly close the polygon.

See also
intersected(), subtracted()

Friends And Related Function Documentation

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

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

Refer to Serializing Data Types for additional information.

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

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

Refer to Serializing Data Types for additional information.