Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QPointArray Class Reference

The QPointArray class provides a vector of points. More...

    #include <QPointArray>

Inherits QVector<QPoint>.

Note: All the functions in this class are reentrant, except shortPoints() and cleanBuffers().

- List of all members, including inherited members
- Compatibility members

### Public Functions

- QPointArray ()
- QPointArray ( int size )
- QPointArray ( const QPointArray & a )
- QPointArray ( const QVector<QPoint> & v )
- QPointArray ( const QRect & r, bool closed = false )
- ~QPointArray ()
- QRect boundingRect () const
- QPointArray cubicBezier () const
- void makeArc ( int x, int y, int w, int h, int a1, int a2 )
- void makeArc ( int x, int y, int w, int h, int a1, int a2, const QMatrix & xf )
- void makeEllipse ( int x, int y, int w, int h )
- void point ( int index, int * x, int * y ) const
- QPoint point ( int index ) const
- void putPoints ( int index, int nPoints, int firstx, int firsty, ... )
- void putPoints ( int index, int nPoints, const QPointArray & from, int fromIndex = 0 )
- void setPoint ( int index, int x, int y )
- void setPoint ( int i, const QPoint & p )
- void setPoints ( int nPoints, const QCOORD * points )
- void setPoints ( int nPoints, int firstx, int firsty, ... )
- void translate ( int dx, int dy )
- void translate ( const QPoint & offset )

- 59 public functions inherited from QVector

### Related Non-Members

- QDataStream & operator<< ( QDataStream & s, const QPointArray & a )
- QDataStream & operator>> ( QDataStream & s, QPointArray & a )

## Detailed Description

The QPointArray class provides a vector of points.

A QPointArray is a QVector<QPoint>. It is implicitly shared. In addition to the functions provided by QVector, QPointArray provides some point-specific functions.

For convenient reading and writing of the point data use setPoints(), putPoints(), point(), and setPoint().

For geometry operations use boundingRect() and translate(). There is also the QMatrix::map() function for more general transformations of QPointArrays. You can also create arcs and ellipses with makeArc() and makeEllipse().

Among others, QPointArray is used by QPainter::drawLineSegments(), QPainter::drawPolyline(), QPainter::drawPolygon() and QPainter::drawCubicBezier().

See also QPainter, QMatrix, and QVector.

## Member Function Documentation

### QPointArray::QPointArray ()

Constructs a null point array.

See also QVector::isEmpty().

### QPointArray::QPointArray ( int size )

Constructs a point array with room for size points. Makes a null array if size == 0.

See also QVector::isEmpty().

### QPointArray::QPointArray ( const QPointArray & a )

Constructs a copy of the point array a.

### QPointArray::QPointArray ( const QVector<QPoint> & v )

### QPointArray::QPointArray ( const QRect & r, bool closed = false )

Constructs a point array from the rectangle r.

If closed is false, then the point array just contains the following four points in the listed order: r.topLeft(), r.topRight(), r.bottomRight() and r.bottomLeft().

If closed is true, then a fifth point is set to r.topLeft().

### QPointArray::~QPointArray ()

Destroys the point array.

### QRect QPointArray::boundingRect () const

Returns the bounding rectangle of the points in the array, or QRect(0, 0, 0, 0) if the array is empty.

### QPointArray QPointArray::cubicBezier () const

Returns the Bezier points for the four control points in this array.

### void QPointArray::makeArc ( int x, int y, int w, int h, int a1, int a2 )

Sets the points of the array to those describing an arc of an ellipse with size, width w by height h, and position (x, y), starting from angle a1 and spanning by angle a2. The resulting array has sufficient resolution for pixel accuracy (see the overloaded function which takes an additional QMatrix parameter).

Angles are specified in 16ths of a degree, i.e. a full circle equals 5760 (16*360). Positive values mean counter-clockwise, whereas negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

See the angle diagram.

### void QPointArray::makeArc ( int x, int y, int w, int h, int a1, int a2, const QMatrix & xf )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the points of the array to those describing an arc of an ellipse with width w and height h and position (x, y), starting from angle a1, and spanning angle by a2, and transformed by the matrix xf. The resulting array has sufficient resolution for pixel accuracy.

Angles are specified in 16ths of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values mean counter-clockwise, whereas negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

See also angle diagram.

### void QPointArray::makeEllipse ( int x, int y, int w, int h )

Sets the points of the array to those describing an ellipse with size, width w by height h, and position (x, y).

The returned array has sufficient resolution for use as pixels.

### void QPointArray::point ( int index, int * x, int * y ) const

Reads the coordinates of the point at position index within the array and writes them into `*`x and `*`y.

### QPoint QPointArray::point ( int index ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the point at position index within the array.

### void QPointArray::putPoints ( int index, int nPoints, int firstx, int firsty, ... )

Copies nPoints points from the variable argument list into this point array from position index, and resizes the point array if `index+nPoints` exceeds the size of the array.

The example code creates an array with three points (4,5), (6,7) and (8,9), by expanding the array from 1 to 3 points:

        QPointArray a(1);
        a[0] = QPoint(4, 5);
        a.putPoints(1, 2, 6,7, 8,9); // index == 1, points == 2

This has the same result, but here putPoints overwrites rather than extends:

        QPointArray a(3);
        a.putPoints(0, 3, 4,5, 0,0, 8,9);
        a.putPoints(1, 1, 6,7);

The points are given as a sequence of integers, starting with firstx then firsty, and so on.

### void QPointArray::putPoints ( int index, int nPoints, const QPointArray & from, int fromIndex = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version of the function copies nPoints from from into this array, starting at index in this array and fromIndex in from. fromIndex is 0 by default.

        QPointArray a;
        a.putPoints(0, 3, 1,2, 0,0, 5,6);
        // a is now the three-point array (1,2, 0,0, 5,6);
        QPointArray b;
        b.putPoints(0, 3, 4,4, 5,5, 6,6);
        // b is now (4,4, 5,5, 6,6);
        a.putPoints(2, 3, b);
        // a is now (1,2, 0,0, 4,4, 5,5, 6,6);

### void QPointArray::setPoint ( int index, int x, int y )

Sets the point at position index in the array to (x, y).

### void QPointArray::setPoint ( int i, const QPoint & p )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the point at array index i to p.

### void QPointArray::setPoints ( int nPoints, const QCOORD * points )

Resizes the array to nPoints and sets the points in the array to the values taken from points.

The example code creates an array with two points (10, 20) and (30, 40):

        static const QCOORD points[] = { 10, 20, 30, 40 };
        QPointArray a;
        a.setPoints(2, points);

`QCOORD` is a typedef for a signed integer type with at least 32 bits.

See also resize().

### void QPointArray::setPoints ( int nPoints, int firstx, int firsty, ... )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Resizes the array to nPoints and sets the points in the array to the values taken from the variable argument list.

The example code creates an array with two points (10, 20) and (30, 40):

        QPointArray a;
        a.setPoints(2, 10, 20, 30, 40);

The points are given as a sequence of integers, starting with firstx then firsty, and so on.

See also resize() and putPoints().

### void QPointArray::translate ( int dx, int dy )

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

### void QPointArray::translate ( const QPoint & offset )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Translates all points in the array by offset.

## Related Non-Members

### QDataStream & operator<< ( QDataStream & s, const QPointArray & a )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Writes the point array, a to the stream s and returns a reference to the stream.

See also Format of the QDataStream operators.

### QDataStream & operator>> ( QDataStream & s, QPointArray & a )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Reads a point array, a from the stream s and returns a reference to the stream.

See also Format of the QDataStream operators.