The list class is indexable and has a current index and a current item. The first item corresponds to index position 0. The current index is -1 if the current item is 0.
.PP
Items are inserted with prepend(), insert() or append(). Items are removed with remove(), removeRef(), removeFirst() and removeLast(). You can search for an item using find(), findNext(), findRef() or findNextRef(). The list can be sorted with sort(). You can count the number of occurrences of an item with contains() or containsRef(). You can get a pointer to the current item with current(), to an item at a particular index position in the list with at() or to the first or last item with getFirst() and getLast(). You can also iterate over the list with first(), last(), next() and prev() (which all update current()). The list's deletion property is set with setAutoDelete().
TQPtrList has several member functions for traversing the list, but using a TQPtrListIterator can be more practical. Multiple list iterators may traverse the same list, independently of each other and of the current list item.
In the example above we make the call setAutoDelete(TRUE). Enabling auto-deletion tells the list to delete items that are removed. The default is to not delete items when they are removed but this would cause a memory leak in the example because there are no other references to the list items.
When inserting an item into a list only the pointer is copied, not the item itself, i.e. a shallow copy. It is possible to make the list copy all of the item's data (deep copy) when an item is inserted. insert(), inSort() and append() call the virtual function TQPtrCollection::newItem() for the item to be inserted. Inherit a list and reimplement newItem() to have deep copies.
When removing an item from a list, the virtual function TQPtrCollection::deleteItem() is called. TQPtrList's default implementation is to delete the item if auto-deletion is enabled.
The virtual function compareItems() can be reimplemented to compare two list items. This function is called from all list functions that need to compare list items, for instance remove(const type*). If you only want to deal with pointers, there are functions that compare pointers instead, for instance removeRef(const type*). These functions are somewhat faster than those that call compareItems().
.PP
List items are stored as \fCvoid*\fR in an internal QLNode, which also holds pointers to the next and previous list items. The functions currentNode(), removeNode(), and takeNode() operate directly on the QLNode, but they should be used with care. The data component of the node is available through QLNode::getData().
The TQStrList class defined in tqstrlist.h is a list of \fCchar*\fR. It reimplements newItem(), deleteItem() and compareItems(). (But see TQStringList for a list of Unicode TQStrings.)
Returns the number of occurrences of \fIitem\fR in the list.
.PP
The compareItems() function is called when looking for the \fIitem\fR in the list. If compareItems() is not reimplemented, it is more efficient to call containsRef().
.PP
This function does not affect the current list item.
Returns the number of occurrences of \fIitem\fR in the list.
.PP
Calling this function is much faster than contains() because contains() compares \fIitem\fR with each list item using compareItems(), whereas his function only compares the pointers.
.PP
This function does not affect the current list item.
Finds the first occurrence of \fIitem\fR in the list.
.PP
If the item is found, the list sets the current item to point to the found item and returns the index of this item. If the item is not found, the list sets the current item to 0, the current index to -1, and returns -1.
.PP
The compareItems() function is called when searching for the item in the list. If compareItems() is not reimplemented, it is more efficient to call findRef().
.PP
See also findNext(), findRef(), compareItems(), and current().
Finds the next occurrence of \fIitem\fR in the list, starting from the current list item.
.PP
If the item is found, the list sets the current item to point to the found item and returns the index of this item. If the item is not found, the list sets the current item to 0, the current index to -1, and returns -1.
.PP
The compareItems() function is called when searching for the item in the list. If compareItems() is not reimplemented, it is more efficient to call findNextRef().
.PP
See also find(), findNextRef(), compareItems(), and current().
Finds the next occurrence of \fIitem\fR in the list, starting from the current list item.
.PP
If the item is found, the list sets the current item to point to the found item and returns the index of this item. If the item is not found, the list sets the current item to 0, the current index to -1, and returns -1.
.PP
Calling this function is much faster than findNext() because findNext() compares \fIitem\fR with each list item using compareItems(), whereas this function only compares the pointers.
Finds the first occurrence of \fIitem\fR in the list.
.PP
If the item is found, the list sets the current item to point to the found item and returns the index of this item. If the item is not found, the list sets the current item to 0, the current index to -1, and returns -1.
.PP
Calling this function is much faster than find() because find() compares \fIitem\fR with each list item using compareItems(), whereas this function only compares the pointers.
Inserts the \fIitem\fR at its sorted position in the list.
.PP
The sort order depends on the virtual compareItems() function. All items must be inserted with inSort() to maintain the sorting order.
.PP
The inserted item becomes the current list item.
.PP
\fIitem\fR must not be 0.
.PP
\fBWarning:\fR Using inSort() is slow. An alternative, especially if you have lots of items, is to simply append() or insert() them and then use sort(). inSort() takes up to O(n) compares. That means inserting n items in your list will need O(n^2) compares whereas sort() only needs O(n*log n) for the same task. So use inSort() only if you already have a presorted list and want to insert just a few additional items.
.PP
See also insert(), compareItems(), current(), and sort().
Inserts the \fIitem\fR at position \fIindex\fR in the list.
.PP
Returns TRUE if successful, i.e. if \fIindex\fR is in range; otherwise returns FALSE. The valid range is 0 to count() (inclusively). The item is appended if \fIindex\fR == count().
Returns a pointer to the item succeeding the current item. Returns 0 if the current item is 0 or equal to the last item.
.PP
Makes the succeeding item current. If the current item before this function call was the last item, the current item will be set to 0. If the current item was 0, this function does nothing.
.PP
See also first(), last(), prev(), and current().
.PP
Examples:
.)l grapher/grapher.cpp, listviews/listviews.h, and showimg/showimg.cpp.
Assigns \fIlist\fR to this list and returns a reference to this list.
.PP
This list is first cleared and then each item in \fIlist\fR is appended to this list. Only the pointers are copied (shallow copy) unless newItem() has been reimplemented.
Returns a pointer to the item preceding the current item. Returns 0 if the current item is 0 or equal to the first item.
.PP
Makes the preceding item current. If the current item before this function call was the first item, the current item will be set to 0. If the current item was 0, this function does nothing.
Removes the item at position \fIindex\fR in the list.
.PP
Returns TRUE if successful, i.e. if \fIindex\fR is in range; otherwise returns FALSE. The valid range is \fC0..(count() - 1)\fR inclusive.
.PP
The removed item is deleted if auto-deletion is enabled.
.PP
The item after the removed item becomes the new current list item if the removed item is not the last item in the list. If the last item is removed, the new last item becomes the current item.
.PP
All list iterators that refer to the removed item will be set to point to the new current item.
.PP
See also take(), clear(), setAutoDelete(), current(), and removeRef().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Removes the current list item.
.PP
Returns TRUE if successful, i.e. if the current item isn't 0; otherwise returns FALSE.
.PP
The removed item is deleted if auto-deletion is enabled.
.PP
The item after the removed item becomes the new current list item if the removed item is not the last item in the list. If the last item is removed, the new last item becomes the current item. The current item is set to 0 if the list becomes empty.
.PP
All list iterators that refer to the removed item will be set to point to the new current item.
.PP
See also take(), clear(), setAutoDelete(), current(), and removeRef().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Removes the first occurrence of \fIitem\fR from the list.
.PP
Returns TRUE if successful, i.e. if \fIitem\fR is in the list; otherwise returns FALSE.
.PP
The removed item is deleted if auto-deletion is enabled.
.PP
The compareItems() function is called when searching for the item in the list. If compareItems() is not reimplemented, it is more efficient to call removeRef().
.PP
If \fIitem\fR is NULL then the current item is removed from the list.
.PP
The item after the removed item becomes the new current list item if the removed item is not the last item in the list. If the last item is removed, the new last item becomes the current item. The current item is set to 0 if the list becomes empty.
.PP
All list iterators that refer to the removed item will be set to point to the new current item.
.PP
See also removeRef(), take(), clear(), setAutoDelete(), compareItems(), and current().
This node must exist in the list, otherwise the program may crash.
.PP
The removed item is deleted if auto-deletion is enabled.
.PP
The first item in the list will become the new current list item. The current item is set to 0 if the list becomes empty.
.PP
All list iterators that refer to the removed item will be set to point to the item succeeding this item or to the preceding item if the removed item was the last item.
.PP
\fBWarning:\fR Do not call this function unless you are an expert.
.PP
See also takeNode(), currentNode(), remove(), and removeRef().
Removes the first occurrence of \fIitem\fR from the list.
.PP
Returns TRUE if successful, i.e. if \fIitem\fR is in the list; otherwise returns FALSE.
.PP
The removed item is deleted if auto-deletion is enabled.
.PP
Equivalent to:
.PP
.nf
.br
if ( list.findRef( item ) != -1 )
.br
list.remove();
.br
.fi
.PP
The item after the removed item becomes the new current list item if the removed item is not the last item in the list. If the last item is removed, the new last item becomes the current item. The current item is set to 0 if the list becomes empty.
.PP
All list iterators that refer to the removed item will be set to point to the new current item.
.PP
See also remove(), clear(), setAutoDelete(), and current().
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.
Sorts the list by the result of the virtual compareItems() function.
.PP
The heap sort algorithm is used for sorting. It sorts n items with O(n*log n) comparisons. This is the asymptotic optimal solution of the sorting problem.
Takes the item at position \fIindex\fR out of the list without deleting it (even if auto-deletion is enabled).
.PP
Returns a pointer to the item taken out of the list, or 0 if the index is out of range. The valid range is \fC0..(count() - 1)\fR inclusive.
.PP
The item after the removed item becomes the new current list item if the removed item is not the last item in the list. If the last item is removed, the new last item becomes the current item. The current item is set to 0 if the list becomes empty.
.PP
All list iterators that refer to the taken item will be set to point to the new current item.
.PP
See also remove(), clear(), and current().
.PP
Examples:
.)l customlayout/border.cpp, customlayout/card.cpp, and customlayout/flow.cpp.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Takes the current item out of the list without deleting it (even if auto-deletion is enabled).
.PP
Returns a pointer to the item taken out of the list, or 0 if the current item is 0.
.PP
The item after the removed item becomes the new current list item if the removed item is not the last item in the list. If the last item is removed, the new last item becomes the current item. The current item is set to 0 if the list becomes empty.
.PP
All list iterators that refer to the taken item will be set to point to the new current item.
Takes the \fInode\fR out of the list without deleting its item (even if auto-deletion is enabled). Returns a pointer to the item taken out of the list.
.PP
This node must exist in the list, otherwise the program may crash.
.PP
The first item in the list becomes the new current list item.
.PP
All list iterators that refer to the taken item will be set to point to the item succeeding this item or to the preceding item if the taken item was the last item.
.PP
\fBWarning:\fR Do not call this function unless you are an expert.