<tdalign="right"valign="center"><imgsrc="logo32.png"align="right"width="64"height="32"border="0"></td></tr></table><h1align=center>TQPtrList Class Reference</h1>
<p>The TQPtrList class is a template class that provides a list.
for ( uint i = 0; i < list.<ahref="#count">count</a>(); ++i )
if ( list.<ahref="#at">at</a>(i) )
cout << list.<ahref="#at">at</a>( i )->surname().latin1() << endl;
</pre>
<p> The output is
<pre>
Doe, John earns 50000
Williams, Jane earns 80000
Jones, Tom earns 60000
Doe
Williams
Jones
</pre>
<p> TQPtrList has several member functions for traversing the list, but
using a <ahref="qptrlistiterator.html">TQPtrListIterator</a> can be more practical. Multiple list
iterators may traverse the same list, independently of each other
and of the current list item.
<p> In the example above we make the call <ahref="qptrcollection.html#setAutoDelete">setAutoDelete</a>(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.
<p> When inserting an item into a list only the pointer is copied, not
the item itself, i.e. a <ahref="shclass.html#shallow-copy">shallow copy</a>. It is possible to make the
list copy all of the item's data (deep copy) when an item is
inserted. <ahref="#insert">insert</a>(), <ahref="#inSort">inSort</a>() and <ahref="#append">append</a>() call the virtual
function <ahref="qptrcollection.html#newItem">TQPtrCollection::newItem</a>() for the item to be inserted.
Inherit a list and reimplement <ahref="qptrcollection.html#newItem">newItem</a>() to have deep copies.
<p> When removing an item from a list, the virtual function
<ahref="qptrcollection.html#deleteItem">TQPtrCollection::deleteItem</a>() is called. TQPtrList's default
implementation is to delete the item if auto-deletion is enabled.
<p> The virtual function <ahref="#compareItems">compareItems</a>() can be reimplemented to
compare two list items. This function is called from all list
functions that need to compare list items, for instance
<ahref="#remove">remove</a>(const type*). If you only want to deal with pointers, there
are functions that compare pointers instead, for instance
<ahref="#removeRef">removeRef</a>(const type*). These functions are somewhat faster than
those that call compareItems().
<p> List items are stored as <tt>void*</tt> in an internal TQLNode, which
also holds pointers to the next and previous list items. The
functions <ahref="#currentNode">currentNode</a>(), <ahref="#removeNode">removeNode</a>(), and <ahref="#takeNode">takeNode</a>() operate
directly on the TQLNode, but they should be used with care. The
data component of the node is available through TQLNode::getData().
<p> The <ahref="qstrlist.html">TQStrList</a> class defined in <ahref="qstrlist-h.html">qstrlist.h</a> is a list of <tt>char*</tt>.
It reimplements <ahref="qptrcollection.html#newItem">newItem</a>(), <ahref="qptrcollection.html#deleteItem">deleteItem</a>() and <ahref="#compareItems">compareItems</a>(). (But
see <ahref="qstringlist.html">TQStringList</a> for a list of Unicode TQStrings.)
<p><p>See also <ahref="qptrlistiterator.html">TQPtrListIterator</a>, <ahref="collection.html">Collection Classes</a>, and <ahref="tools.html">Non-GUI Classes</a>.
<p> Finds the first occurrence of <em>item</em> in the list.
<p> 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.
<p> The <ahref="#compareItems">compareItems</a>() function is called when searching for the item
in the list. If compareItems() is not reimplemented, it is more
efficient to call <ahref="#findRef">findRef</a>().
<p><p>See also <ahref="#findNext">findNext</a>(), <ahref="#findRef">findRef</a>(), <ahref="#compareItems">compareItems</a>(), and <ahref="#current">current</a>().
<p> Finds the next occurrence of <em>item</em> in the list, starting from
the current list item.
<p> 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.
<p> The <ahref="#compareItems">compareItems</a>() function is called when searching for the item
in the list. If compareItems() is not reimplemented, it is more
efficient to call <ahref="#findNextRef">findNextRef</a>().
<p><p>See also <ahref="#find">find</a>(), <ahref="#findNextRef">findNextRef</a>(), <ahref="#compareItems">compareItems</a>(), and <ahref="#current">current</a>().
<p> Returns a pointer to the first item in the list and makes this the
current list item; returns 0 if the list is empty.
<p><p>See also <ahref="#getFirst">getFirst</a>(), <ahref="#last">last</a>(), <ahref="#next">next</a>(), <ahref="#prev">prev</a>(), and <ahref="#current">current</a>().
<p>Examples: <ahref="grapher-nsplugin-example.html#x2772">grapher/grapher.cpp</a>, <ahref="listviews-example.html#x132">listviews/listviews.h</a>, and <ahref="showimg-example.html#x1343">showimg/showimg.cpp</a>.
<p> Inserts the <em>item</em> at its sorted position in the list.
<p> The sort order depends on the virtual <ahref="#compareItems">compareItems</a>() function. All
items must be inserted with <ahref="#inSort">inSort</a>() to maintain the sorting
order.
<p> The inserted item becomes the current list item.
<p><em>item</em> must not be 0.
<p><b>Warning:</b> Using inSort() is slow. An alternative, especially if you
have lots of items, is to simply <ahref="#append">append</a>() or <ahref="#insert">insert</a>() them and
then use <ahref="#sort">sort</a>(). 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.
<p><p>See also <ahref="#insert">insert</a>(), <ahref="#compareItems">compareItems</a>(), <ahref="#current">current</a>(), and <ahref="#sort">sort</a>().
<p> Returns a pointer to the last item in the list and makes this the
current list item; returns 0 if the list is empty.
<p><p>See also <ahref="#getLast">getLast</a>(), <ahref="#first">first</a>(), <ahref="#next">next</a>(), <ahref="#prev">prev</a>(), and <ahref="#current">current</a>().
<p> Returns a pointer to the item succeeding the current item. Returns
0 if the current item is 0 or equal to the last item.
<p> 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.
<p><p>See also <ahref="#first">first</a>(), <ahref="#last">last</a>(), <ahref="#prev">prev</a>(), and <ahref="#current">current</a>().
<p>Examples: <ahref="grapher-nsplugin-example.html#x2773">grapher/grapher.cpp</a>, <ahref="listviews-example.html#x133">listviews/listviews.h</a>, and <ahref="showimg-example.html#x1344">showimg/showimg.cpp</a>.
<p> Removes the item at position <em>index</em> in the list.
<p> Returns TRUE if successful, i.e. if <em>index</em> is in range;
otherwise returns FALSE. The valid range is <tt>0..(count() - 1)</tt>
inclusive.
<p> The removed item is deleted if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
<p> 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.
<p> All list iterators that refer to the removed item will be set to
point to the new current item.
<p><p>See also <ahref="#take">take</a>(), <ahref="#clear">clear</a>(), <ahref="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <ahref="#current">current</a>(), and <ahref="#removeRef">removeRef</a>().
<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Removes the current list item.
<p> Returns TRUE if successful, i.e. if the current item isn't 0;
otherwise returns FALSE.
<p> The removed item is deleted if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
<p> 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.
<p> All list iterators that refer to the removed item will be set to
point to the new current item.
<p><p>See also <ahref="#take">take</a>(), <ahref="#clear">clear</a>(), <ahref="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <ahref="#current">current</a>(), and <ahref="#removeRef">removeRef</a>().
<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Removes the first occurrence of <em>item</em> from the list.
<p> Returns TRUE if successful, i.e. if <em>item</em> is in the list;
otherwise returns FALSE.
<p> The removed item is deleted if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
<p> The <ahref="#compareItems">compareItems</a>() function is called when searching for the item
in the list. If compareItems() is not reimplemented, it is more
efficient to call <ahref="#removeRef">removeRef</a>().
<p> If <em>item</em> is NULL then the current item is removed from the list.
<p> 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.
<p> All list iterators that refer to the removed item will be set to
point to the new current item.
<p><p>See also <ahref="#removeRef">removeRef</a>(), <ahref="#take">take</a>(), <ahref="#clear">clear</a>(), <ahref="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <ahref="#compareItems">compareItems</a>(), and <ahref="#current">current</a>().
<p> Removes the first item from the list. Returns TRUE if successful,
i.e. if the list isn't empty; otherwise returns FALSE.
<p> The removed item is deleted if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
<p> The first item in the list becomes the new current list item. The
current item is set to 0 if the list becomes empty.
<p> All list iterators that refer to the removed item will be set to
point to the new current item.
<p><p>See also <ahref="#removeLast">removeLast</a>(), <ahref="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <ahref="#current">current</a>(), and <ahref="#remove">remove</a>().
<p> Removes the last item from the list. Returns TRUE if successful,
i.e. if the list isn't empty; otherwise returns FALSE.
<p> The removed item is deleted if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
<p> The last item in the list becomes the new current list item. The
current item is set to 0 if the list becomes empty.
<p> All list iterators that refer to the removed item will be set to
point to the new current item.
<p><p>See also <ahref="#removeFirst">removeFirst</a>(), <ahref="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), and <ahref="#current">current</a>().
<p> This node must exist in the list, otherwise the program may crash.
<p> The removed item is deleted if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
<p> 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.
<p> 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.
<p><b>Warning:</b> Do not call this function unless you are an expert.
<p><p>See also <ahref="#takeNode">takeNode</a>(), <ahref="#currentNode">currentNode</a>(), <ahref="#remove">remove</a>(), and <ahref="#removeRef">removeRef</a>().
<p> Removes the first occurrence of <em>item</em> from the list.
<p> Returns TRUE if successful, i.e. if <em>item</em> is in the list;
otherwise returns FALSE.
<p> The removed item is deleted if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
<p> Equivalent to:
<pre>
if ( list.findRef( item ) != -1 )
list.remove();
</pre>
<p> 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.
<p> All list iterators that refer to the removed item will be set to
point to the new current item.
<p><p>See also <ahref="#remove">remove</a>(), <ahref="#clear">clear</a>(), <ahref="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), and <ahref="#current">current</a>().
<p> Sets the collection to auto-delete its contents if <em>enable</em> is
TRUE and to never delete them if <em>enable</em> is FALSE.
<p> 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.
<p> 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.
<p> Note that the auto-delete setting may also affect other functions
in subclasses. For example, a subclass that has a <ahref="#remove">remove</a>()
function will remove the item from its data structure, and if
auto-delete is enabled, will also delete the item.
<p><p>See also <ahref="qptrcollection.html#autoDelete">autoDelete</a>().
<p>Examples: <ahref="grapher-nsplugin-example.html#x2769">grapher/grapher.cpp</a>, <ahref="scribble-example.html#x924">scribble/scribble.cpp</a>, and <ahref="bigtable-example.html#x1291">table/bigtable/main.cpp</a>.
<p> Takes the item at position <em>index</em> out of the list without
deleting it (even if <ahref="qptrcollection.html#setAutoDelete">auto-deletion</a>
is enabled).
<p> Returns a pointer to the item taken out of the list, or 0 if the
index is out of range. The valid range is <tt>0..(count() - 1)</tt>
inclusive.
<p> 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.
<p> All list iterators that refer to the taken item will be set to
point to the new current item.
<p><p>See also <ahref="#remove">remove</a>(), <ahref="#clear">clear</a>(), and <ahref="#current">current</a>().
<p>Examples: <ahref="customlayout-example.html#x1503">customlayout/border.cpp</a>, <ahref="customlayout-example.html#x1521">customlayout/card.cpp</a>, and <ahref="customlayout-example.html#x1480">customlayout/flow.cpp</a>.