返回介绍

QPointArray Class

发布于 2019-10-04 15:02:01 字数 9774 浏览 1312 评论 0 收藏 0

The QPointArray class provides an array of points. More...

#include <qpointarray.h>

Inherits QMemArray<QPoint>.

List of all member functions.

Public Members

  • QPointArray ()
  • ~QPointArray ()
  • QPointArray ( intsize )
  • QPointArray ( constQPointArray&a )
  • QPointArray ( constQRect&r, boolclosed = FALSE )
  • QPointArray & operator= ( constQPointArray&a )
  • QPointArray copy () const
  • void translate ( intdx, intdy )
  • QRect boundingRect () const
  • void point ( uintindex, int*x, int*y ) const
  • QPoint point ( uintindex ) const
  • void setPoint ( uintindex, intx, inty )
  • void setPoint ( uinti, constQPoint&p )
  • bool putPoints ( intindex, intnPoints, intfirstx, intfirsty, ... )
  • bool putPoints ( intindex, intnPoints, constQPointArray&from, intfromIndex = 0 )
  • void makeArc ( intx, inty, intw, inth, inta1, inta2 )
  • void makeEllipse ( intx, inty, intw, inth )
  • void makeArc ( intx, inty, intw, inth, inta1, inta2, constQWMatrix&xf )
  • QPointArray cubicBezier () const

Related Functions

  • QDataStream & operator<< ( QDataStream&s, constQPointArray&a )
  • QDataStream & operator>> ( QDataStream&s, QPointArray&a )

Detailed Description

The QPointArray class provides an array of points.

A QPointArray is an array of QPoint objects. In addition to the functions provided by QMemArray, QPointArray provides some point-specific functions.

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

For geometry operations: boundingRect() and translate(). There is also a QWMatrix::map() function for more general transformation 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().

Note that because this class is a QMemArray, copying an array and modifying the copy modifies the original as well, i.e. a shallow copy. If you need a deep copy use copy() or detach(), for example:

        void drawGiraffe( const QPointArray & r, QPainter * p )
        {
            QPointArray tmp = r;
            tmp.detach();
            // some code that modifies tmp
            p->drawPoints( tmp );
        }
    

If you forget the tmp.detach(), the const array will be modified.

See also QPainter, QWMatrix, QMemArray, Graphics Classes, Image Processing Classes and Implicitly and Explicitly Shared Classes.


Member Function Documentation

QPointArray::QPointArray ()

Constructs a null point array.

See also isNull().

QPointArray::QPointArray ( intsize )

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

See also resize() and isNull().

QPointArray::QPointArray ( constQPointArray&a )

Constructs a shallow copy of the point array a.

See also copy().

QPointArray::QPointArray ( constQRect&r, boolclosed = 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::copy () const

Creates a deep copy of the array.

QPointArray QPointArray::cubicBezier () const

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

void QPointArray::makeArc ( intx, inty, intw, inth, inta1, inta2 )

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 QWMatrix 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 ( intx, inty, intw, inth, inta1, inta2, constQWMatrix&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 the angle diagram.

void QPointArray::makeEllipse ( intx, inty, intw, inth )

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.

QPointArray& QPointArray::operator= ( constQPointArray&a )

Assigns a shallow copy of a to this point array and returns a reference to this point array.

Equivalent to assign(a).

See also copy().

void QPointArray::point ( uintindex, 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 ( uintindex ) 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.

bool QPointArray::putPoints ( intindex, intnPoints, intfirstx, intfirsty, ... )

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.

Returns TRUE if successful, or FALSE if the array could not be resized (typically due to lack of memory).

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.

See also resize().

bool QPointArray::putPoints ( intindex, intnPoints, constQPointArray&from, intfromIndex = 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 ( uintindex, intx, inty )

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

Example: themes/wood.cpp.

void QPointArray::setPoint ( uinti, constQPoint&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::translate ( intdx, intdy )

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

Related Functions

QDataStream& operator<< ( QDataStream&s, constQPointArray&a )

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 )

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

See also Format of the QDataStream operators.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文