|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QPolygon
public class QPolygon
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 QVector's 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.
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 | |
---|---|
QPolygon()
Constructs a polygon with no points. |
|
QPolygon(int size)
Constructs a polygon of the given size. |
|
QPolygon(java.util.List<QPoint> v)
Constructs a polygon containing the specified v. |
|
QPolygon(QPolygon a)
Constructs a copy of the given a. |
|
QPolygon(QRect r)
Equivalent to QPolygon(r, false). |
|
QPolygon(QRect r,
boolean closed)
Constructs a polygon from the given r. |
Method Summary | |
---|---|
QPolygon |
add(int x,
int y)
Adds the point (x, y) to the end of this QPolygon's point list. |
QPolygon |
add(QPoint pt)
Adds pt to this polygon's point list. |
QPolygon |
add(QPolygon p)
Adds the points in p to the end of this polygons point list. |
void |
append(QPoint t)
Inserts t at the end of the vector. |
QPoint |
at(int i)
Returns the item at index position i in the vector. |
QRect |
boundingRect()
Returns the bounding rectangle of the polygon, or QRect(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(QPoint t)
Returns true if the vector contains an occurrence of t; otherwise returns false. |
boolean |
containsPoint(QPoint 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(QPoint 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<QPoint> |
fill(QPoint t,
int size)
Assigns t to all items in the vector. |
static java.util.List<QPoint> |
fromList(java.util.List<QPoint> list)
Returns a QVector object with the data contained in list. |
static QPolygon |
fromNativePointer(QNativePointer nativePointer)
This function returns the QPolygon instance pointed to by nativePointer |
int |
indexOf(QPoint t,
int from)
Returns the index position of the first occurrence of t in the vector, searching forward from index position from. |
QPolygon |
intersected(QPolygon r)
Returns a polygon which is the intersection of this polygon and r. |
boolean |
isEmpty()
Returns true if the vector has size 0; otherwise returns false. |
int |
lastIndexOf(QPoint 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<QPoint> |
mid(int pos,
int length)
Returns a vector whose elements are copied from this vector, starting at position pos. |
static QNativePointer |
nativePointerArray(QPolygon[] array)
This function returns a QNativePointer that is pointing to the specified QPolygon array. |
void |
pop_back()
This function is provided for STL compatibility. |
void |
pop_front()
This function is provided for STL compatibility. |
void |
prepend(QPoint t)
Inserts t at the beginning of the vector. |
void |
push_back(QPoint t)
This function is provided for STL compatibility. |
void |
push_front(QPoint t)
This function is provided for STL compatibility. |
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,
QPoint 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)
This method is used internally by Qt Jambi. |
int |
size()
Returns the number of items in the vector. |
void |
squeeze()
Releases any memory not required to store the items. |
QPolygon |
subtracted(QPolygon r)
Returns a polygon which is r subtracted from this polygon. |
java.util.List<QPoint> |
toList()
Returns a QList object with the data contained in this QVector. |
void |
translate(int dx,
int dy)
Translates all points in the polygon by (dx, dy). |
void |
translate(QPoint offset)
Translates all points in the polygon by the given offset. |
QPolygon |
united(QPolygon r)
Returns a polygon which is the union of this polygon and r. |
QPoint |
value(int i)
Returns the value at index position i in the vector. |
QPoint |
value(int i,
QPoint defaultValue)
If the index i is out of bounds, the function returns defaultValue. |
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 |
---|
public QPolygon(QRect r)
Equivalent to QPolygon(r, false).
public QPolygon(QRect r, boolean closed)
Constructs a polygon from the given r. 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 r.topLeft().
Note that the bottom-right corner of the rectangle is located at (rectangle.x() + rectangle.width(), rectangle.y() + rectangle.height()).
public QPolygon(int size)
Constructs a polygon of the given size. Creates an empty polygon if size == 0.
public QPolygon()
Constructs a polygon with no points.
public QPolygon(java.util.List<QPoint> v)
Constructs a polygon containing the specified v.
public QPolygon(QPolygon a)
Constructs a copy of the given a.
Method Detail |
---|
public final void append(QPoint 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.
public final QPoint 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).
public final QRect boundingRect()
Returns the bounding rectangle of the polygon, or QRect(0, 0, 0, 0) if the polygon is empty.
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.
public final void clear()
Removes all the elements from the vector.
Same as resize(0).
public final boolean contains(QPoint 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==().
public final boolean containsPoint(QPoint pt, Qt.FillRule fillRule)
Returns true if the given pt is inside the polygon according to the specified fillRule; otherwise returns false.
public final int count(QPoint t)
Returns the number of occurrences of t in the vector.
This function requires the value type to have an implementation of operator==().
public final int count()
Same as size.
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.
public final java.util.List<QPoint> fill(QPoint 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"]
public final int indexOf(QPoint 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==().
public final QPolygon intersected(QPolygon r)
Returns a polygon which is the intersection of this polygon and r.
public final boolean isEmpty()
Returns true if the vector has size 0; otherwise returns false.
public final int lastIndexOf(QPoint 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==().
public final java.util.List<QPoint> 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.
public final void pop_back()
This function is provided for STL compatibility. It is equivalent to erase(end() - 1).
public final void pop_front()
This function is provided for STL compatibility. It is equivalent to erase(begin()).
public final void prepend(QPoint 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.
public final void push_back(QPoint t)
This function is provided for STL compatibility. It is equivalent to append(t).
public final void push_front(QPoint t)
This function is provided for STL compatibility. It is equivalent to prepend(t).
public final void remove(int i, int n)
Removes n elements from the middle of the vector, starting at index position i.
public final void remove(int i)
Removes the element at index position i.
public final void replace(int i, QPoint 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).
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.
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.
public final void setSharable(boolean sharable)
This method is used internally by Qt Jambi. Do not use it in your applications.
public final int size()
Returns the number of items in the vector.
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.
public final QPolygon subtracted(QPolygon r)
Returns a polygon which is r subtracted from this polygon.
public final java.util.List<QPoint> 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"]
public final void translate(int dx, int dy)
Translates all points in the polygon by (dx, dy).
public final void translate(QPoint offset)
Translates all points in the polygon by the given offset.
public final QPolygon united(QPolygon r)
Returns a polygon which is the union of this polygon and r.
public final QPoint value(int i, QPoint defaultValue)
If the index i is out of bounds, the function returns defaultValue.
public final QPoint 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.
public static java.util.List<QPoint> fromList(java.util.List<QPoint> 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"]
public static QPolygon fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public static QNativePointer nativePointerArray(QPolygon[] array)
array
- the array that the returned pointer will point to.
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public final QPolygon add(int x, int y)
public final QPolygon add(QPoint pt)
public final QPolygon add(QPolygon p)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |