QPtrVector is implemented as a template class. Defines a template instance QPtrVector<X> to create a vector that contains pointers to X (X*).
.PP
A vector is the same as an array. The main difference between QPtrVector and QMemArray is that QPtrVector stores pointers to the elements, whereas QMemArray stores the elements themselves (i.e. QMemArray is value-based and QPtrVector is pointer-based).
.PP
Items are added to the vector using insert() or fill(). Items are removed with remove(). You can get a pointer to an item at a particular index position using at().
.PP
Unless otherwise stated, all functions that remove items from the vector will also delete the element pointed to if auto-deletion is enabled. By default, auto-deletion is disabled; see setAutoDelete(). This behaviour can be changed in a subclass by reimplementing the virtual function deleteItem().
.PP
Functions that compare items (find() and sort() for example) will do so using the virtual function compareItems(). The default implementation of this function only compares the pointer values. Reimplement compareItems() in a subclass to get searching and sorting based on the item contents. You can perform a linear search for a pointer in the vector using findRef(), or a binary search (of a sorted vector) using bsearch(). You can count the number of times an item appears in the vector with contains() or containsRef().
.PP
See also QMemArray and Non-GUI Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QPtrVector::QPtrVector ()"
Constructs a null vector.
.PP
See also isNull().
.SH "QPtrVector::QPtrVector ( uint size )"
Constructs an vector with room for \fIsize\fR items. Makes a null vector if \fIsize\fR == 0.
.PP
All \fIsize\fR positions in the vector are initialized to 0.
.PP
See also size(), resize(), and isNull().
.SH "QPtrVector::QPtrVector ( const QPtrVector<type> & v )"
Constructs a copy of \fIv\fR. Only the pointers are copied (i.e. shallow copy).
.SH "QPtrVector::~QPtrVector ()"
Removes all items from the vector, and destroys the vector itself.
.PP
See also clear().
.SH "type * QPtrVector::at ( uint i ) const"
Returns the item at position \fIi\fR, or 0 if there is no item at that position. \fIi\fR must be less than size().
.SH "bool QPtrCollection::autoDelete () const"
Returns the setting of the auto-delete option. The default is FALSE.
.PP
See also setAutoDelete().
.SH "int QPtrVector::bsearch ( const type * d ) const"
In a sorted array, finds the first occurrence of \fId\fR using a binary search. For a sorted array, this is generally much faster than find(), which performs a linear search.
.PP
Returns the position of \fId\fR, or -1 if \fId\fR could not be found. \fId\fR must not be 0.
.PP
Compares items using the virtual function compareItems().
.PP
See also sort() and find().
.SH "void QPtrVector::clear ()\fC [virtual]\fR"
Removes all items from the vector, and destroys the vector itself.
Returns the number of items in the vector. The vector is empty if count() == 0.
.PP
See also isEmpty(), size(), and isNull().
.PP
Reimplemented from QPtrCollection.
.SH "type ** QPtrVector::data () const"
Returns a pointer to the actual vector data, which is an array of type*.
.PP
The vector is a null vector if data() == 0 (null pointer).
.PP
See also isNull().
.SH "bool QPtrVector::fill ( const type * d, int size = -1 )"
Inserts item \fId\fR in all positions in the vector. Any existing items are removed. If \fId\fR is 0, the vector becomes empty.
.PP
If \fIsize\fR >= 0, the vector is first resized to \fIsize\fR. By default, \fIsize\fR is -1.
.PP
Returns TRUE if successful, i.e. \fIsize\fR is the same as the current size, or \fIsize\fR is larger and the memory has successfully been allocated; otherwise returns FALSE.
.PP
See also resize(), insert(), and isEmpty().
.SH "int QPtrVector::find ( const type * d, uint i = 0 ) const"
Finds the first occurrence of item \fId\fR in the vector using a linear search. The search starts at position \fIi\fR, which must be less than size(). \fIi\fR is by default 0; i.e. the search starts at the start of the vector.
.PP
Returns the position of \fId\fR, or -1 if \fId\fR could not be found.
.PP
Compares items using the virtual function compareItems().
.PP
Use the much faster bsearch() to search a sorted vector.
.PP
See also findRef() and bsearch().
.SH "int QPtrVector::findRef ( const type * d, uint i = 0 ) const"
Finds the first occurrence of the item pointer \fId\fR in the vector using a linear search. The search starts at position \fIi\fR, which must be less than size(). \fIi\fR is by default 0; i.e. the search starts at the start of the vector.
.PP
Returns the position of \fId\fR, or -1 if \fId\fR could not be found.
.PP
This function does \fInot\fR use compareItems() to compare items.
.PP
Use the much faster bsearch() to search a sorted vector.
.PP
See also find() and bsearch().
.SH "bool QPtrVector::insert ( uint i, const type * d )"
Sets position \fIi\fR in the vector to contain the item \fId\fR. \fIi\fR must be less than size(). Any previous element in position \fIi\fR is removed.
.PP
See also at().
.SH "bool QPtrVector::isEmpty () const"
Returns TRUE if the vector is empty; otherwise returns FALSE.
.PP
See also count().
.SH "bool QPtrVector::isNull () const"
Returns TRUE if the vector is null; otherwise returns FALSE.
.PP
A null vector has size() == 0 and data() == 0.
.PP
See also size().
.SH "QPtrVector<type> & QPtrVector::operator= ( const QPtrVector<type> & v )"
Assigns \fIv\fR to this vector and returns a reference to this vector.
.PP
This vector is first cleared and then all the items from \fIv\fR are copied into the vector. Only the pointers are copied (i.e. shallow copy).
.PP
See also clear().
.SH "bool QPtrVector::operator== ( const QPtrVector<type> & v ) const"
Returns TRUE if this vector and \fIv\fR are equal; otherwise returns FALSE.
.SH "type * QPtrVector::operator[] ( int i ) const"
Returns the item at position \fIi\fR, or 0 if there is no item at that position. \fIi\fR must be less than size().
Sets the collection to auto-delete its contents if \fIenable\fR is TRUE and to never delete them if \fIenable\fR is FALSE.
.PP
If auto-deleting is turned on, all the items in a collection are deleted when the collection itself is deleted. This is convenient if the collection has the only pointer to the items.
.PP
The default setting is FALSE, for safety. If you turn it on, be careful about copying the collection - you might find yourself with two collections deleting the same items.
.PP
Note that the auto-delete setting may also affect other functions in subclasses. For example, a subclass that has a remove() function will remove the item from its data structure, and if auto-delete is enabled, will also delete the item.
.PP
See also autoDelete().
.PP
Examples:
.)l grapher/grapher.cpp, scribble/scribble.cpp, and table/bigtable/main.cpp.
.SH "uint QPtrVector::size () const"
Returns the size of the vector, i.e. the number of vector positions. This is also the maximum number of items the vector can hold.
.PP
The vector is a null vector if size() == 0.
.PP
See also isNull(), resize(), and count().
.SH "void QPtrVector::sort ()"
Sorts the items in ascending order. Any empty positions will be put last.
.PP
Compares items using the virtual function compareItems().
.PP
See also bsearch().
.SH "type * QPtrVector::take ( uint i )"
Returns the item at position \fIi\fR in the vector, and removes that item from the vector. \fIi\fR must be less than size(). If there is no item at position \fIi\fR, 0 is returned.
.PP
Unlike remove(), this function does \fInot\fR call deleteItem() for the removed item.