Qt Jambi Home

com.trolltech.qt.gui
Class QPolygonF

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.gui.QPolygonF
All Implemented Interfaces:
QtJambiInterface

public class QPolygonF
extends QtJambiObject

The QPolygonF class provides a vector of points using floating point precision.

A QPolygonF is a QVector<QPointF>. The easiest way to add points to a QPolygonF is to use its streaming operator, as illustrated below:

            QPolygonF polygon;
            polygon << QPointF(10.4, 20.5) << QPointF(20.2, 30.2);

In addition to the functions provided by QVector, QPolygonF provides the boundingRect and translate functions for geometry operations. Use the QMatrix::map() function for more general transformations of QPolygonFs.

QPolygonF also provides the isClosed function to determine whether a polygon's start and end points are the same, and the toPolygon function returning an integer precision copy of this polygon.

The QPolygonF class is implicitly shared.

See Also:
QVector, QPolygon, QLineF

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QPolygonF()
          Constructs a polygon with no points.
QPolygonF(int size)
          Constructs a polygon of the given size.
QPolygonF(java.util.List<QPointF> v)
          Constructs a polygon containing the specified v.
QPolygonF(QPolygon a)
          Constructs a float based polygon from the specified integer based a.
QPolygonF(QPolygonF a)
          Constructs a copy of the given a.
QPolygonF(QRectF r)
          Constructs a closed polygon from the specified r.
 
Method Summary
 QPolygonF add(double x, double y)
          Adds the point (x, y) to the end of this polygon's point list.
 QPolygonF add(QPointF pt)
          Adds pt to the end of this polygons point list.
 QPolygonF add(QPolygonF p)
          Appends the points of p to the end of this polygons point list.
 void append(QPointF t)
          Inserts t at the end of the vector.
 QPointF at(int i)
          Returns the item at index position i in the vector.
 QRectF boundingRect()
          Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty.
 int capacity()
          Returns the maximum number of items that can be stored in the vector without forcing a reallocation.
 void clear()
          Removes all the elements from the vector.
 boolean contains(QPointF t)
          Returns true if the vector contains an occurrence of t; otherwise returns false.
 boolean containsPoint(QPointF pt, Qt.FillRule fillRule)
          Returns true if the given pt is inside the polygon according to the specified fillRule; otherwise returns false.
 int count()
          Same as size.
 int count(QPointF t)
          Returns the number of occurrences of t in the vector.
 boolean empty()
          This function is provided for STL compatibility.
 boolean equals(java.lang.Object other)
          
 java.util.List<QPointF> fill(QPointF t, int size)
          Assigns t to all items in the vector.
static java.util.List<QPointF> fromList(java.util.List<QPointF> list)
          Returns a QVector object with the data contained in list.
static QPolygonF fromNativePointer(QNativePointer nativePointer)
          This function returns the QPolygonF instance pointed to by nativePointer
 int indexOf(QPointF t, int from)
          Returns the index position of the first occurrence of t in the vector, searching forward from index position from.
 QPolygonF intersected(QPolygonF r)
          Returns a polygon which is the intersection of this polygon and r.
 boolean isClosed()
          Returns true if the polygon is closed; otherwise returns false.
 boolean isEmpty()
          Returns true if the vector has size 0; otherwise returns false.
 int lastIndexOf(QPointF t, int from)
          Returns the index position of the last occurrence of the value t in the vector, searching backward from index position from.
 java.util.List<QPointF> mid(int pos, int length)
          Returns a vector whose elements are copied from this vector, starting at position pos.
static QNativePointer nativePointerArray(QPolygonF[] array)
          This function returns a QNativePointer that is pointing to the specified QPolygonF array.
 void pop_back()
          This function is provided for STL compatibility.
 void pop_front()
          This function is provided for STL compatibility.
 void prepend(QPointF t)
          Inserts t at the beginning of the vector.
 void push_back(QPointF t)
          This function is provided for STL compatibility.
 void push_front(QPointF t)
          This function is provided for STL compatibility.
 void readFrom(QDataStream stream)
          Reads a QPolygonF from stream.
 void remove(int i)
          Removes the element at index position i.
 void remove(int i, int n)
          Removes n elements from the middle of the vector, starting at index position i.
 void replace(int i, QPointF t)
          Replaces the item at index position i with t.
 void reserve(int size)
          Attempts to allocate memory for at least size elements.
 void resize(int size)
          Sets the size of the vector to size.
 void setSharable(boolean sharable)
          
 int size()
          Returns the number of items in the vector.
 void squeeze()
          Releases any memory not required to store the items.
 QPolygonF subtracted(QPolygonF r)
          Returns a polygon which is r subtracted from this polygon.
 java.util.List<QPointF> toList()
          Returns a QList object with the data contained in this QVector.
 QPolygon toPolygon()
          Creates and returns a QPolygon by converting each QPointF to a QPoint.
 void translate(double dx, double dy)
          Translates all points in the polygon by (dx, dy).
 void translate(QPointF offset)
          Translate all points in the polygon by the given offset.
 QPolygonF united(QPolygonF r)
          Returns a polygon which is the union of this polygon and r.
 QPointF value(int i)
          Returns the value at index position i in the vector.
 QPointF value(int i, QPointF defaultValue)
          If the index i is out of bounds, the function returns defaultValue.
 void writeTo(QDataStream stream)
          Writes thisQPolygonF to stream.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QPolygonF

public QPolygonF(java.util.List<QPointF> v)

Constructs a polygon containing the specified v.


QPolygonF

public QPolygonF(int size)

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

See Also:
QVector::isEmpty

QPolygonF

public QPolygonF(QPolygon a)

Constructs a float based polygon from the specified integer based a.

See Also:
toPolygon

QPolygonF

public QPolygonF()

Constructs a polygon with no points.

See Also:
QVector::isEmpty

QPolygonF

public QPolygonF(QPolygonF a)

Constructs a copy of the given a.


QPolygonF

public QPolygonF(QRectF r)

Constructs a closed polygon from the specified r.

The polygon contains the four vertices of the rectangle in clockwise order starting and ending with the top-left vertex.

See Also:
isClosed
Method Detail

append

public final void append(QPointF t)

Inserts t at the end of the vector.

Example:

    QVector<QString> vector(0);
    vector.append("one");
    vector.append("two");
    vector.append("three");
    // vector: ["one", "two", three"]

This is the same as calling resize(size + 1) and assigning t to the new last element in the vector.

This operation is relatively fast, because QVector typically allocates more memory than necessary, so it can grow without reallocating the entire vector each time.

See Also:
operator<<, prepend, insert

at

public final QPointF at(int i)

Returns the item at index position i in the vector.

i must be a valid index position in the vector (i.e., 0 <= i < size).

See Also:
value, operator[]

boundingRect

public final QRectF boundingRect()

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

See Also:
QVector::isEmpty

capacity

public final int capacity()

Returns the maximum number of items that can be stored in the vector without forcing a reallocation.

The sole purpose of this function is to provide a means of fine tuning QVector's memory usage. In general, you will rarely ever need to call this function. If you want to know how many items are in the vector, call size.

See Also:
reserve, squeeze

clear

public final void clear()

Removes all the elements from the vector.

Same as resize(0).


contains

public final boolean contains(QPointF t)

Returns true if the vector contains an occurrence of t; otherwise returns false.

This function requires the value type to have an implementation of operator==().

See Also:
indexOf, count

containsPoint

public final boolean containsPoint(QPointF pt,
                                   Qt.FillRule fillRule)

Returns true if the given pt is inside the polygon according to the specified fillRule; otherwise returns false.


count

public final int count(QPointF t)

Returns the number of occurrences of t in the vector.

This function requires the value type to have an implementation of operator==().

See Also:
contains, indexOf

count

public final int count()

Same as size.


empty

public final boolean empty()

This function is provided for STL compatibility. It is equivalent to isEmpty, returning true if the vector is empty; otherwise returns false.


fill

public final java.util.List<QPointF> fill(QPointF t,
                                          int size)

Assigns t to all items in the vector. If size is different from -1 (the default), the vector is resized to size size beforehand.

Example:

    QVector<QString> vector(3);
    vector.fill("Yes");
    // vector: ["Yes", "Yes", "Yes"]

    vector.fill("oh", 5);
    // vector: ["oh", "oh", "oh", "oh", "oh"]

See Also:
resize

indexOf

public final int indexOf(QPointF t,
                         int from)

Returns the index position of the first occurrence of t in the vector, searching forward from index position from. Returns -1 if no item matched.

Example:

    QVector<QString> vector;
    vector << "A" << "B" << "C" << "B" << "A";
    vector.indexOf("B");            // returns 1
    vector.indexOf("B", 1);         // returns 1
    vector.indexOf("B", 2);         // returns 3
    vector.indexOf("X");            // returns -1

This function requires the value type to have an implementation of operator==().

See Also:
lastIndexOf, contains

intersected

public final QPolygonF intersected(QPolygonF r)

Returns a polygon which is the intersection of this polygon and r.


isClosed

public final boolean isClosed()

Returns true if the polygon is closed; otherwise returns false.

A polygon is said to be closed if its start point and end point are equal.

See Also:
QVector::first, QVector::last

isEmpty

public final boolean isEmpty()

Returns true if the vector has size 0; otherwise returns false.

See Also:
size, resize

lastIndexOf

public final int lastIndexOf(QPointF t,
                             int from)

Returns the index position of the last occurrence of the value t in the vector, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.

Example:

    QList<QString> vector;
    vector << "A" << "B" << "C" << "B" << "A";
    vector.lastIndexOf("B");        // returns 3
    vector.lastIndexOf("B", 3);     // returns 3
    vector.lastIndexOf("B", 2);     // returns 1
    vector.lastIndexOf("X");        // returns -1

This function requires the value type to have an implementation of operator==().

See Also:
indexOf

mid

public final java.util.List<QPointF> mid(int pos,
                                         int length)

Returns a vector whose elements are copied from this vector, starting at position pos. If length is -1 (the default), all elements after pos are copied; otherwise length elements (or all remaining elements if there are less than length elements) are copied.


writeTo

public final void writeTo(QDataStream stream)
Writes thisQPolygonF to stream.


readFrom

public final void readFrom(QDataStream stream)
Reads a QPolygonF from stream.


pop_back

public final void pop_back()

This function is provided for STL compatibility. It is equivalent to erase(end() - 1).


pop_front

public final void pop_front()

This function is provided for STL compatibility. It is equivalent to erase(begin()).


prepend

public final void prepend(QPointF t)

Inserts t at the beginning of the vector.

Example:

    QVector<QString> vector;
    vector.prepend("one");
    vector.prepend("two");
    vector.prepend("three");
    // vector: ["three", "two", "one"]

This is the same as vector.insert(0, t).

For large vectors, this operation can be slow (linear time), because it requires moving all the items in the vector by one position further in memory. If you want a container class that provides a fast prepend function, use QList or QLinkedList instead.

See Also:
append, insert

push_back

public final void push_back(QPointF t)

This function is provided for STL compatibility. It is equivalent to append(t).


push_front

public final void push_front(QPointF t)

This function is provided for STL compatibility. It is equivalent to prepend(t).


remove

public final void remove(int i,
                         int n)

Removes n elements from the middle of the vector, starting at index position i.

See Also:
insert, replace, fill

remove

public final void remove(int i)

Removes the element at index position i.

See Also:
insert, replace, fill

replace

public final void replace(int i,
                          QPointF t)

Replaces the item at index position i with t.

i must be a valid index position in the vector (i.e., 0 <= i < size).

See Also:
operator[], remove

reserve

public final void reserve(int size)

Attempts to allocate memory for at least size elements. If you know in advance how large the vector will be, you can call this function, and if you call resize often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QVector will be a bit slower.

The sole purpose of this function is to provide a means of fine tuning QVector's memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the vector, call resize.

See Also:
squeeze, capacity

resize

public final void resize(int size)

Sets the size of the vector to size. If size is greater than the current size, elements are added to the end; the new elements are initialized with a default-constructed value. If size is less than the current size, elements are removed from the end.

See Also:
size

setSharable

public final void setSharable(boolean sharable)


size

public final int size()

Returns the number of items in the vector.

See Also:
isEmpty, resize

squeeze

public final void squeeze()

Releases any memory not required to store the items.

The sole purpose of this function is to provide a means of fine tuning QVector's memory usage. In general, you will rarely ever need to call this function.

See Also:
reserve, capacity

subtracted

public final QPolygonF subtracted(QPolygonF r)

Returns a polygon which is r subtracted from this polygon.


toList

public final java.util.List<QPointF> toList()

Returns a QList object with the data contained in this QVector.

Example:

    QVector<double> vect;
    vect << "red" << "green" << "blue" << "black";

    QList<double> list = vect.toList();
    // list: ["red", "green", "blue", "black"]

See Also:
fromList, QList::fromVector

toPolygon

public final QPolygon toPolygon()

Creates and returns a QPolygon by converting each QPointF to a QPoint.

See Also:
QPointF::toPoint

translate

public final void translate(QPointF offset)

Translate all points in the polygon by the given offset.


translate

public final void translate(double dx,
                            double dy)

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


united

public final QPolygonF united(QPolygonF r)

Returns a polygon which is the union of this polygon and r.

See Also:
intersected, subtracted

value

public final QPointF value(int i,
                           QPointF defaultValue)

If the index i is out of bounds, the function returns defaultValue.


value

public final QPointF value(int i)

Returns the value at index position i in the vector.

If the index i is out of bounds, the function returns a default-constructed value. If you are certain that i is within bounds, you can use at instead, which is slightly faster.

See Also:
at, operator[]

fromList

public static java.util.List<QPointF> fromList(java.util.List<QPointF> list)

Returns a QVector object with the data contained in list.

Example:

    QStringList list;
    list << "Sven" << "Kim" << "Ola";

    QVector<QString> vect = QVector<QString>::fromList(list);
    // vect: ["Sven", "Kim", "Ola"]

See Also:
toList, QList::toVector

fromNativePointer

public static QPolygonF fromNativePointer(QNativePointer nativePointer)
This function returns the QPolygonF instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

nativePointerArray

public static QNativePointer nativePointerArray(QPolygonF[] array)
This function returns a QNativePointer that is pointing to the specified QPolygonF array.

Parameters:
array - the array that the returned pointer will point to.
Returns:
a QNativePointer that is pointing to the specified array.

equals

public boolean equals(java.lang.Object other)

Overrides:
equals in class java.lang.Object

add

public final QPolygonF add(double x,
                           double y)
Adds the point (x, y) to the end of this polygon's point list.


add

public final QPolygonF add(QPointF pt)
Adds pt to the end of this polygons point list.


add

public final QPolygonF add(QPolygonF p)
Appends the points of p to the end of this polygons point list.


Qt Jambi Home