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

TQPointArray Class Reference

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

#include <qpointarray.h>

Inherits TQMemArray<TQPoint>.

List of all member functions.

Public Members

Related Functions


Detailed Description

The TQPointArray class provides an array of points.

A TQPointArray is an array of TQPoint objects. In addition to the functions provided by TQMemArray, TQPointArray 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 TQWMatrix::map() function for more general transformations of TQPointArrays. You can also create arcs and ellipses with makeArc() and makeEllipse().

Among others, TQPointArray is used by TQPainter::drawLineSegments(), TQPainter::drawPolyline(), TQPainter::drawPolygon() and TQPainter::drawCubicBezier().

Note that because this class is a TQMemArray, 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 TQPointArray & r, TQPainter * p )
        {
            TQPointArray 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 TQPainter, TQWMatrix, TQMemArray, Graphics Classes, Image Processing Classes, and Implicitly and Explicitly Shared Classes.


Member Function Documentation

TQPointArray::TQPointArray ()

Constructs a null point array.

See also isNull().

TQPointArray::TQPointArray ( int size )

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

See also resize() and isNull().

TQPointArray::TQPointArray ( const TQPointArray & a )

Constructs a shallow copy of the point array a.

See also copy() and detach().

TQPointArray::TQPointArray ( const TQRect & 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().

TQPointArray::~TQPointArray ()

Destroys the point array.

TQRect TQPointArray::boundingRect () const

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

TQPointArray TQPointArray::copy () const

Creates a deep copy of the array.

See also detach().

TQPointArray TQPointArray::cubicBezier () const

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

void TQPointArray::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 TQWMatrix 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 TQPointArray::makeArc ( int x, int y, int w, int h, int a1, int a2, const TQWMatrix & 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 TQPointArray::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.

TQPointArray & TQPointArray::operator= ( const TQPointArray & 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() and detach().

void TQPointArray::point ( uint 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.

TQPoint TQPointArray::point ( uint 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.

bool TQPointArray::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.

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:

        TQPointArray a( 1 );
        a[0] = TQPoint( 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:

        TQPointArray 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 TQPointArray::putPoints ( int index, int nPoints, const TQPointArray & 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.

        TQPointArray a;
        a.putPoints( 0, 3, 1,2, 0,0, 5,6 );
        // a is now the three-point array ( 1,2, 0,0, 5,6 );
        TQPointArray 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 TQPointArray::setPoint ( uint index, int x, int y )

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

Example: themes/wood.cpp.

void TQPointArray::setPoint ( uint i, const TQPoint & 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 TQPointArray::translate ( int dx, int dy )

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

Related Functions

TQDataStream & operator<< ( TQDataStream & s, const TQPointArray & a )

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

See also Format of the TQDataStream operators.

TQDataStream & operator>> ( TQDataStream & s, TQPointArray & a )

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

See also Format of the TQDataStream operators.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8