source: trunk/doc/html/qptrlist.html

Last change on this file was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 42.1 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/qptrlist.doc:41 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QPtrList Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QPtrList Class Reference</h1>
33
34<p>The QPtrList class is a template class that provides a list.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qptrlist-h.html">qptrlist.h</a>&gt;</tt>
37<p>Inherits <a href="qptrcollection.html">QPtrCollection</a>.
38<p>Inherited by <a href="qobjectlist.html">QObjectList</a>, <a href="qsortedlist.html">QSortedList</a>, and <a href="qstrlist.html">QStrList</a>.
39<p><a href="qptrlist-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn><a href="#QPtrList"><b>QPtrList</b></a> ()</li>
43<li class=fn><a href="#QPtrList-2"><b>QPtrList</b></a> ( const&nbsp;QPtrList&lt;type&gt;&nbsp;&amp;&nbsp;list )</li>
44<li class=fn><a href="#~QPtrList"><b>~QPtrList</b></a> ()</li>
45<li class=fn>QPtrList&lt;type&gt; &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QPtrList&lt;type&gt;&nbsp;&amp;&nbsp;list )</li>
46<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QPtrList&lt;type&gt;&nbsp;&amp;&nbsp;list ) const</li>
47<li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const&nbsp;QPtrList&lt;type&gt;&nbsp;&amp;&nbsp;list ) const</li>
48<li class=fn>virtual uint <a href="#count"><b>count</b></a> () const</li>
49<li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
50<li class=fn>bool <a href="#insert"><b>insert</b></a> ( uint&nbsp;index, const&nbsp;type&nbsp;*&nbsp;item )</li>
51<li class=fn>void <a href="#inSort"><b>inSort</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
52<li class=fn>void <a href="#prepend"><b>prepend</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
53<li class=fn>void <a href="#append"><b>append</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
54<li class=fn>bool <a href="#remove"><b>remove</b></a> ( uint&nbsp;index )</li>
55<li class=fn>bool <a href="#remove-2"><b>remove</b></a> ()</li>
56<li class=fn>bool <a href="#remove-3"><b>remove</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
57<li class=fn>bool <a href="#removeRef"><b>removeRef</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
58<li class=fn>void <a href="#removeNode"><b>removeNode</b></a> ( QLNode&nbsp;*&nbsp;node )</li>
59<li class=fn>bool <a href="#removeFirst"><b>removeFirst</b></a> ()</li>
60<li class=fn>bool <a href="#removeLast"><b>removeLast</b></a> ()</li>
61<li class=fn>type * <a href="#take"><b>take</b></a> ( uint&nbsp;index )</li>
62<li class=fn>type * <a href="#take-2"><b>take</b></a> ()</li>
63<li class=fn>type * <a href="#takeNode"><b>takeNode</b></a> ( QLNode&nbsp;*&nbsp;node )</li>
64<li class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</li>
65<li class=fn>void <a href="#sort"><b>sort</b></a> ()</li>
66<li class=fn>int <a href="#find"><b>find</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
67<li class=fn>int <a href="#findNext"><b>findNext</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
68<li class=fn>int <a href="#findRef"><b>findRef</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
69<li class=fn>int <a href="#findNextRef"><b>findNextRef</b></a> ( const&nbsp;type&nbsp;*&nbsp;item )</li>
70<li class=fn>uint <a href="#contains"><b>contains</b></a> ( const&nbsp;type&nbsp;*&nbsp;item ) const</li>
71<li class=fn>uint <a href="#containsRef"><b>containsRef</b></a> ( const&nbsp;type&nbsp;*&nbsp;item ) const</li>
72<li class=fn>bool <a href="#replace"><b>replace</b></a> ( uint&nbsp;index, const&nbsp;type&nbsp;*&nbsp;item )</li>
73<li class=fn>type * <a href="#at"><b>at</b></a> ( uint&nbsp;index )</li>
74<li class=fn>int <a href="#at-2"><b>at</b></a> () const</li>
75<li class=fn>type * <a href="#current"><b>current</b></a> () const</li>
76<li class=fn>QLNode * <a href="#currentNode"><b>currentNode</b></a> () const</li>
77<li class=fn>type * <a href="#getFirst"><b>getFirst</b></a> () const</li>
78<li class=fn>type * <a href="#getLast"><b>getLast</b></a> () const</li>
79<li class=fn>type * <a href="#first"><b>first</b></a> ()</li>
80<li class=fn>type * <a href="#last"><b>last</b></a> ()</li>
81<li class=fn>type * <a href="#next"><b>next</b></a> ()</li>
82<li class=fn>type * <a href="#prev"><b>prev</b></a> ()</li>
83<li class=fn>void <a href="#toVector"><b>toVector</b></a> ( QGVector&nbsp;*&nbsp;vec ) const</li>
84</ul>
85<h2>Important Inherited Members</h2>
86<ul>
87<li class=fn>bool <a href="#autoDelete"><b>autoDelete</b></a> () const</li>
88<li class=fn>void <a href="#setAutoDelete"><b>setAutoDelete</b></a> ( bool&nbsp;enable )</li>
89</ul>
90<h2>Protected Members</h2>
91<ul>
92<li class=fn>virtual int <a href="#compareItems"><b>compareItems</b></a> ( QPtrCollection::Item&nbsp;item1, QPtrCollection::Item&nbsp;item2 )</li>
93<li class=fn>virtual QDataStream &amp; <a href="#read"><b>read</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QPtrCollection::Item&nbsp;&amp;&nbsp;item )</li>
94<li class=fn>virtual QDataStream &amp; <a href="#write"><b>write</b></a> ( QDataStream&nbsp;&amp;&nbsp;s, QPtrCollection::Item&nbsp;item ) const</li>
95</ul>
96<hr><a name="details"></a><h2>Detailed Description</h2>
97
98
99The QPtrList class is a template class that provides a list.
100<p>
101
102<p>
103<p> <a href="qvaluelist.html">QValueList</a> is an STL-compatible alternative to this class.
104<p> Define a template instance QPtrList&lt;X&gt; to create a list that
105operates on pointers to X (X*).
106<p> The list class is indexable and has a <a href="#at">current
107 index</a> and a <a href="#current">current item</a>. The
108first item corresponds to index position 0. The current index is
109-1 if the current item is 0.
110<p> Items are inserted with <a href="#prepend">prepend</a>(), <a href="#insert">insert</a>() or <a href="#append">append</a>(). Items are
111removed with <a href="#remove">remove</a>(), <a href="#removeRef">removeRef</a>(), <a href="#removeFirst">removeFirst</a>() and
112<a href="#removeLast">removeLast</a>(). You can search for an item using <a href="#find">find</a>(), <a href="#findNext">findNext</a>(),
113<a href="#findRef">findRef</a>() or <a href="#findNextRef">findNextRef</a>(). The list can be sorted with <a href="#sort">sort</a>().
114You can count the number of occurrences of an item with <a href="#contains">contains</a>()
115or <a href="#containsRef">containsRef</a>(). You can get a pointer to the current item with
116<a href="#current">current</a>(), to an item at a particular index position in the list
117with <a href="#at">at</a>() or to the first or last item with <a href="#getFirst">getFirst</a>() and
118<a href="#getLast">getLast</a>(). You can also iterate over the list with <a href="#first">first</a>(),
119<a href="#last">last</a>(), <a href="#next">next</a>() and <a href="#prev">prev</a>() (which all update current()). The list's
120deletion property is set with <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
121<p> <a name="example"></a>
122Example:
123<pre>
124 class Employee
125 {
126 public:
127 Employee() : sn( 0 ) { }
128 Employee( const <a href="qstring.html">QString</a>&amp; forename, const <a href="qstring.html">QString</a>&amp; surname, int salary )
129 : fn( forename ), sn( surname ), sal( salary )
130 { }
131
132 void setSalary( int salary ) { sal = salary; }
133
134 <a href="qstring.html">QString</a> forename() const { return fn; }
135 <a href="qstring.html">QString</a> surname() const { return sn; }
136 int salary() const { return sal; }
137
138 private:
139 <a href="qstring.html">QString</a> fn;
140 <a href="qstring.html">QString</a> sn;
141 int sal;
142 };
143
144 QPtrList&lt;Employee&gt; list;
145 list.<a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>( TRUE ); // the list owns the objects
146
147 list.<a href="#append">append</a>( new Employee("John", "Doe", 50000) );
148 list.<a href="#append">append</a>( new Employee("Jane", "Williams", 80000) );
149 list.<a href="#append">append</a>( new Employee("Tom", "Jones", 60000) );
150
151 Employee *employee;
152 for ( employee = list.<a href="#first">first</a>(); employee; employee = list.<a href="#next">next</a>() )
153 cout &lt;&lt; employee-&gt;surname().latin1() &lt;&lt; ", " &lt;&lt;
154 employee-&gt;forename().latin1() &lt;&lt; " earns " &lt;&lt;
155 employee-&gt;salary() &lt;&lt; endl;
156 cout &lt;&lt; endl;
157
158 // very inefficient for big lists
159 for ( uint i = 0; i &lt; list.<a href="#count">count</a>(); ++i )
160 if ( list.<a href="#at">at</a>(i) )
161 cout &lt;&lt; list.<a href="#at">at</a>( i )-&gt;surname().latin1() &lt;&lt; endl;
162 </pre>
163
164<p> The output is
165<pre>
166 Doe, John earns 50000
167 Williams, Jane earns 80000
168 Jones, Tom earns 60000
169
170 Doe
171 Williams
172 Jones
173 </pre>
174
175<p> QPtrList has several member functions for traversing the list, but
176using a <a href="qptrlistiterator.html">QPtrListIterator</a> can be more practical. Multiple list
177iterators may traverse the same list, independently of each other
178and of the current list item.
179<p> In the example above we make the call <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(TRUE).
180Enabling auto-deletion tells the list to delete items that are
181removed. The default is to not delete items when they are removed
182but this would cause a memory leak in the example because there
183are no other references to the list items.
184<p> When inserting an item into a list only the pointer is copied, not
185the item itself, i.e. a <a href="shclass.html#shallow-copy">shallow copy</a>. It is possible to make the
186list copy all of the item's data (deep copy) when an item is
187inserted. <a href="#insert">insert</a>(), <a href="#inSort">inSort</a>() and <a href="#append">append</a>() call the virtual
188function <a href="qptrcollection.html#newItem">QPtrCollection::newItem</a>() for the item to be inserted.
189Inherit a list and reimplement <a href="qptrcollection.html#newItem">newItem</a>() to have deep copies.
190<p> When removing an item from a list, the virtual function
191<a href="qptrcollection.html#deleteItem">QPtrCollection::deleteItem</a>() is called. QPtrList's default
192implementation is to delete the item if auto-deletion is enabled.
193<p> The virtual function <a href="#compareItems">compareItems</a>() can be reimplemented to
194compare two list items. This function is called from all list
195functions that need to compare list items, for instance
196<a href="#remove">remove</a>(const type*). If you only want to deal with pointers, there
197are functions that compare pointers instead, for instance
198<a href="#removeRef">removeRef</a>(const type*). These functions are somewhat faster than
199those that call compareItems().
200<p> List items are stored as <tt>void*</tt> in an internal QLNode, which
201also holds pointers to the next and previous list items. The
202functions <a href="#currentNode">currentNode</a>(), <a href="#removeNode">removeNode</a>(), and <a href="#takeNode">takeNode</a>() operate
203directly on the QLNode, but they should be used with care. The
204data component of the node is available through QLNode::getData().
205<p> The <a href="qstrlist.html">QStrList</a> class defined in <a href="qstrlist-h.html">qstrlist.h</a> is a list of <tt>char*</tt>.
206It reimplements <a href="qptrcollection.html#newItem">newItem</a>(), <a href="qptrcollection.html#deleteItem">deleteItem</a>() and <a href="#compareItems">compareItems</a>(). (But
207see <a href="qstringlist.html">QStringList</a> for a list of Unicode QStrings.)
208<p> <p>See also <a href="qptrlistiterator.html">QPtrListIterator</a>, <a href="collection.html">Collection Classes</a>, and <a href="tools.html">Non-GUI Classes</a>.
209
210<hr><h2>Member Function Documentation</h2>
211<h3 class=fn><a name="QPtrList"></a>QPtrList::QPtrList ()
212</h3>
213
214<p> Constructs an empty list.
215
216<h3 class=fn><a name="QPtrList-2"></a>QPtrList::QPtrList ( const&nbsp;<a href="qptrlist.html">QPtrList</a>&lt;type&gt;&nbsp;&amp;&nbsp;list )
217</h3>
218
219<p> Constructs a copy of <em>list</em>.
220<p> Each item in <em>list</em> is <a href="#append">appended</a> to this
221list. Only the pointers are copied (shallow copy).
222
223<h3 class=fn><a name="~QPtrList"></a>QPtrList::~QPtrList ()
224</h3>
225
226<p> Removes all items from the list and destroys the list.
227<p> All list iterators that access this list will be reset.
228<p> <p>See also <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
229
230<h3 class=fn>void <a name="append"></a>QPtrList::append ( const&nbsp;type&nbsp;*&nbsp;item )
231</h3>
232
233<p> Inserts the <em>item</em> at the end of the list.
234<p> The inserted item becomes the current list item. This is
235equivalent to <tt>insert( count(), item )</tt>.
236<p> <em>item</em> must not be 0.
237<p> <p>See also <a href="#insert">insert</a>(), <a href="#current">current</a>(), and <a href="#prepend">prepend</a>().
238
239<p>Examples: <a href="customlayout-example.html#x1500">customlayout/border.cpp</a>, <a href="customlayout-example.html#x1518">customlayout/card.cpp</a>, <a href="customlayout-example.html#x1477">customlayout/flow.cpp</a>, <a href="grapher-nsplugin-example.html#x2770">grapher/grapher.cpp</a>, <a href="listviews-example.html#x160">listviews/listviews.cpp</a>, <a href="listviews-example.html#x131">listviews/listviews.h</a>, and <a href="qwerty-example.html#x387">qwerty/qwerty.cpp</a>.
240<h3 class=fn>type * <a name="at"></a>QPtrList::at ( uint&nbsp;index )
241</h3>
242
243<p> Returns a pointer to the item at position <em>index</em> in the list, or
2440 if the index is out of range.
245<p> Sets the current list item to this item if <em>index</em> is valid. The
246valid range is <tt>0..(count() - 1)</tt> inclusive.
247<p> This function is very efficient. It starts scanning from the first
248item, last item, or current item, whichever is closest to <em>index</em>.
249<p> <p>See also <a href="#current">current</a>().
250
251<p>Examples: <a href="customlayout-example.html#x1501">customlayout/border.cpp</a>, <a href="customlayout-example.html#x1519">customlayout/card.cpp</a>, <a href="customlayout-example.html#x1478">customlayout/flow.cpp</a>, <a href="dirview-example.html#x1697">dirview/dirview.cpp</a>, <a href="mdi-example.html#x2053">mdi/application.cpp</a>, and <a href="qwerty-example.html#x388">qwerty/qwerty.cpp</a>.
252<h3 class=fn>int <a name="at-2"></a>QPtrList::at () const
253</h3>
254
255<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
256<p> Returns the index of the current list item. The returned value is
257-1 if the current item is 0.
258<p> <p>See also <a href="#current">current</a>().
259
260<h3 class=fn>bool <a name="autoDelete"></a>QPtrCollection::autoDelete () const
261</h3>
262
263<p> Returns the setting of the auto-delete option. The default is FALSE.
264<p> <p>See also <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
265
266<h3 class=fn>void <a name="clear"></a>QPtrList::clear ()<tt> [virtual]</tt>
267</h3>
268
269<p> Removes all items from the list.
270<p> The removed items are deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
271<p> All list iterators that access this list will be reset.
272<p> <p>See also <a href="#remove">remove</a>(), <a href="#take">take</a>(), and <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
273
274<p>Reimplemented from <a href="qptrcollection.html#clear">QPtrCollection</a>.
275<h3 class=fn>int <a name="compareItems"></a>QPtrList::compareItems ( <a href="qptrcollection.html#Item">QPtrCollection::Item</a>&nbsp;item1, <a href="qptrcollection.html#Item">QPtrCollection::Item</a>&nbsp;item2 )<tt> [virtual protected]</tt>
276</h3>
277
278<p> This virtual function compares two list items.
279<p> Returns:
280<ul>
281<li> zero if <em>item1</em> == <em>item2</em>
282<li> nonzero if <em>item1</em> != <em>item2</em>
283</ul>
284<p> This function returns <em>int</em> rather than <em>bool</em> so that
285reimplementations can return three values and use it to sort by:
286<p> <ul>
287<li> 0 if <em>item1</em> == <em>item2</em>
288<li> &gt; 0 (positive integer) if <em>item1</em> &gt; <em>item2</em>
289<li> &lt; 0 (negative integer) if <em>item1</em> &lt; <em>item2</em>
290</ul>
291<p> <a href="#inSort">inSort</a>() requires that <a href="#compareItems">compareItems</a>() is implemented as described
292here.
293<p> This function should not modify the list because some const
294functions call compareItems().
295<p> The default implementation compares the pointers.
296
297<h3 class=fn>uint <a name="contains"></a>QPtrList::contains ( const&nbsp;type&nbsp;*&nbsp;item ) const
298</h3>
299
300<p> Returns the number of occurrences of <em>item</em> in the list.
301<p> The <a href="#compareItems">compareItems</a>() function is called when looking for the <em>item</em>
302in the list. If compareItems() is not reimplemented, it is more
303efficient to call <a href="#containsRef">containsRef</a>().
304<p> This function does not affect the current list item.
305<p> <p>See also <a href="#containsRef">containsRef</a>() and <a href="#compareItems">compareItems</a>().
306
307<h3 class=fn>uint <a name="containsRef"></a>QPtrList::containsRef ( const&nbsp;type&nbsp;*&nbsp;item ) const
308</h3>
309
310<p> Returns the number of occurrences of <em>item</em> in the list.
311<p> Calling this function is much faster than <a href="#contains">contains</a>() because
312contains() compares <em>item</em> with each list item using
313<a href="#compareItems">compareItems</a>(), whereas his function only compares the pointers.
314<p> This function does not affect the current list item.
315<p> <p>See also <a href="#contains">contains</a>().
316
317<h3 class=fn>uint <a name="count"></a>QPtrList::count () const<tt> [virtual]</tt>
318</h3>
319
320<p> Returns the number of items in the list.
321<p> <p>See also <a href="#isEmpty">isEmpty</a>().
322
323<p>Examples: <a href="customlayout-example.html#x1502">customlayout/border.cpp</a>, <a href="customlayout-example.html#x1520">customlayout/card.cpp</a>, <a href="customlayout-example.html#x1479">customlayout/flow.cpp</a>, <a href="dirview-example.html#x1699">dirview/dirview.cpp</a>, <a href="grapher-nsplugin-example.html#x2771">grapher/grapher.cpp</a>, <a href="mdi-example.html#x2054">mdi/application.cpp</a>, and <a href="qwerty-example.html#x389">qwerty/qwerty.cpp</a>.
324<p>Reimplemented from <a href="qptrcollection.html#count">QPtrCollection</a>.
325<h3 class=fn>type * <a name="current"></a>QPtrList::current () const
326</h3>
327
328<p> Returns a pointer to the current list item. The current item may
329be 0 (implies that the current index is -1).
330<p> <p>See also <a href="#at">at</a>().
331
332<h3 class=fn>QLNode * <a name="currentNode"></a>QPtrList::currentNode () const
333</h3>
334
335<p> Returns a pointer to the current list node.
336<p> The node can be kept and removed later using <a href="#removeNode">removeNode</a>(). The
337advantage is that the item can be removed directly without
338searching the list.
339<p> <b>Warning:</b> Do not call this function unless you are an expert.
340<p> <p>See also <a href="#removeNode">removeNode</a>(), <a href="#takeNode">takeNode</a>(), and <a href="#current">current</a>().
341
342<h3 class=fn>int <a name="find"></a>QPtrList::find ( const&nbsp;type&nbsp;*&nbsp;item )
343</h3>
344
345<p> Finds the first occurrence of <em>item</em> in the list.
346<p> If the item is found, the list sets the current item to point to
347the found item and returns the index of this item. If the item is
348not found, the list sets the current item to 0, the current
349index to -1, and returns -1.
350<p> The <a href="#compareItems">compareItems</a>() function is called when searching for the item
351in the list. If compareItems() is not reimplemented, it is more
352efficient to call <a href="#findRef">findRef</a>().
353<p> <p>See also <a href="#findNext">findNext</a>(), <a href="#findRef">findRef</a>(), <a href="#compareItems">compareItems</a>(), and <a href="#current">current</a>().
354
355<h3 class=fn>int <a name="findNext"></a>QPtrList::findNext ( const&nbsp;type&nbsp;*&nbsp;item )
356</h3>
357
358<p> Finds the next occurrence of <em>item</em> in the list, starting from
359the current list item.
360<p> If the item is found, the list sets the current item to point to
361the found item and returns the index of this item. If the item is
362not found, the list sets the current item to 0, the current
363index to -1, and returns -1.
364<p> The <a href="#compareItems">compareItems</a>() function is called when searching for the item
365in the list. If compareItems() is not reimplemented, it is more
366efficient to call <a href="#findNextRef">findNextRef</a>().
367<p> <p>See also <a href="#find">find</a>(), <a href="#findNextRef">findNextRef</a>(), <a href="#compareItems">compareItems</a>(), and <a href="#current">current</a>().
368
369<h3 class=fn>int <a name="findNextRef"></a>QPtrList::findNextRef ( const&nbsp;type&nbsp;*&nbsp;item )
370</h3>
371
372<p> Finds the next occurrence of <em>item</em> in the list, starting from
373the current list item.
374<p> If the item is found, the list sets the current item to point to
375the found item and returns the index of this item. If the item is
376not found, the list sets the current item to 0, the current
377index to -1, and returns -1.
378<p> Calling this function is much faster than <a href="#findNext">findNext</a>() because
379findNext() compares <em>item</em> with each list item using
380<a href="#compareItems">compareItems</a>(), whereas this function only compares the pointers.
381<p> <p>See also <a href="#findRef">findRef</a>(), <a href="#findNext">findNext</a>(), and <a href="#current">current</a>().
382
383<h3 class=fn>int <a name="findRef"></a>QPtrList::findRef ( const&nbsp;type&nbsp;*&nbsp;item )
384</h3>
385
386<p> Finds the first occurrence of <em>item</em> in the list.
387<p> If the item is found, the list sets the current item to point to
388the found item and returns the index of this item. If the item is
389not found, the list sets the current item to 0, the current
390index to -1, and returns -1.
391<p> Calling this function is much faster than <a href="#find">find</a>() because find()
392compares <em>item</em> with each list item using <a href="#compareItems">compareItems</a>(), whereas
393this function only compares the pointers.
394<p> <p>See also <a href="#findNextRef">findNextRef</a>(), <a href="#find">find</a>(), and <a href="#current">current</a>().
395
396<h3 class=fn>type * <a name="first"></a>QPtrList::first ()
397</h3>
398
399<p> Returns a pointer to the first item in the list and makes this the
400current list item; returns 0 if the list is empty.
401<p> <p>See also <a href="#getFirst">getFirst</a>(), <a href="#last">last</a>(), <a href="#next">next</a>(), <a href="#prev">prev</a>(), and <a href="#current">current</a>().
402
403<p>Examples: <a href="grapher-nsplugin-example.html#x2772">grapher/grapher.cpp</a>, <a href="listviews-example.html#x132">listviews/listviews.h</a>, and <a href="showimg-example.html#x1343">showimg/showimg.cpp</a>.
404<h3 class=fn>type * <a name="getFirst"></a>QPtrList::getFirst () const
405</h3>
406
407<p> Returns a pointer to the first item in the list, or 0 if the list
408is empty.
409<p> This function does not affect the current list item.
410<p> <p>See also <a href="#first">first</a>() and <a href="#getLast">getLast</a>().
411
412<h3 class=fn>type * <a name="getLast"></a>QPtrList::getLast () const
413</h3>
414
415<p> Returns a pointer to the last item in the list, or 0 if the list
416is empty.
417<p> This function does not affect the current list item.
418<p> <p>See also <a href="#last">last</a>() and <a href="#getFirst">getFirst</a>().
419
420<h3 class=fn>void <a name="inSort"></a>QPtrList::inSort ( const&nbsp;type&nbsp;*&nbsp;item )
421</h3>
422
423<p> Inserts the <em>item</em> at its sorted position in the list.
424<p> The sort order depends on the virtual <a href="#compareItems">compareItems</a>() function. All
425items must be inserted with <a href="#inSort">inSort</a>() to maintain the sorting
426order.
427<p> The inserted item becomes the current list item.
428<p> <em>item</em> must not be 0.
429<p> <b>Warning:</b> Using inSort() is slow. An alternative, especially if you
430have lots of items, is to simply <a href="#append">append</a>() or <a href="#insert">insert</a>() them and
431then use <a href="#sort">sort</a>(). inSort() takes up to O(n) compares. That means
432inserting n items in your list will need O(n^2) compares whereas
433sort() only needs O(n*log n) for the same task. So use inSort()
434only if you already have a presorted list and want to insert just
435a few additional items.
436<p> <p>See also <a href="#insert">insert</a>(), <a href="#compareItems">compareItems</a>(), <a href="#current">current</a>(), and <a href="#sort">sort</a>().
437
438<h3 class=fn>bool <a name="insert"></a>QPtrList::insert ( uint&nbsp;index, const&nbsp;type&nbsp;*&nbsp;item )
439</h3>
440
441<p> Inserts the <em>item</em> at position <em>index</em> in the list.
442<p> Returns TRUE if successful, i.e. if <em>index</em> is in range;
443otherwise returns FALSE. The valid range is 0 to <a href="#count">count</a>()
444(inclusively). The item is appended if <em>index</em> == count().
445<p> The inserted item becomes the current list item.
446<p> <em>item</em> must not be 0.
447<p> <p>See also <a href="#append">append</a>(), <a href="#current">current</a>(), and <a href="#replace">replace</a>().
448
449<h3 class=fn>bool <a name="isEmpty"></a>QPtrList::isEmpty () const
450</h3>
451
452<p> Returns TRUE if the list is empty; otherwise returns FALSE.
453<p> <p>See also <a href="#count">count</a>().
454
455<h3 class=fn>type * <a name="last"></a>QPtrList::last ()
456</h3>
457
458<p> Returns a pointer to the last item in the list and makes this the
459current list item; returns 0 if the list is empty.
460<p> <p>See also <a href="#getLast">getLast</a>(), <a href="#first">first</a>(), <a href="#next">next</a>(), <a href="#prev">prev</a>(), and <a href="#current">current</a>().
461
462<h3 class=fn>type * <a name="next"></a>QPtrList::next ()
463</h3>
464
465<p> Returns a pointer to the item succeeding the current item. Returns
4660 if the current item is 0 or equal to the last item.
467<p> Makes the succeeding item current. If the current item before this
468function call was the last item, the current item will be set to
4690. If the current item was 0, this function does nothing.
470<p> <p>See also <a href="#first">first</a>(), <a href="#last">last</a>(), <a href="#prev">prev</a>(), and <a href="#current">current</a>().
471
472<p>Examples: <a href="grapher-nsplugin-example.html#x2773">grapher/grapher.cpp</a>, <a href="listviews-example.html#x133">listviews/listviews.h</a>, and <a href="showimg-example.html#x1344">showimg/showimg.cpp</a>.
473<h3 class=fn>bool <a name="operator!-eq"></a>QPtrList::operator!= ( const&nbsp;<a href="qptrlist.html">QPtrList</a>&lt;type&gt;&nbsp;&amp;&nbsp;list ) const
474</h3>
475
476<p> Compares this list with <em>list</em>. Returns TRUE if the lists contain
477different data; otherwise returns FALSE.
478
479<h3 class=fn><a href="qptrlist.html">QPtrList</a>&lt;type&gt;&nbsp;&amp; <a name="operator-eq"></a>QPtrList::operator= ( const&nbsp;<a href="qptrlist.html">QPtrList</a>&lt;type&gt;&nbsp;&amp;&nbsp;list )
480</h3>
481
482<p> Assigns <em>list</em> to this list and returns a reference to this list.
483<p> This list is first cleared and then each item in <em>list</em> is <a href="#append">appended</a> to this list. Only the pointers are
484copied (shallow copy) unless <a href="qptrcollection.html#newItem">newItem</a>() has been reimplemented.
485
486<h3 class=fn>bool <a name="operator-eq-eq"></a>QPtrList::operator== ( const&nbsp;<a href="qptrlist.html">QPtrList</a>&lt;type&gt;&nbsp;&amp;&nbsp;list ) const
487</h3>
488
489<p> Compares this list with <em>list</em>. Returns TRUE if the lists contain
490the same data; otherwise returns FALSE.
491
492<h3 class=fn>void <a name="prepend"></a>QPtrList::prepend ( const&nbsp;type&nbsp;*&nbsp;item )
493</h3>
494
495<p> Inserts the <em>item</em> at the start of the list.
496<p> The inserted item becomes the current list item. This is
497equivalent to <tt>insert( 0, item )</tt>.
498<p> <em>item</em> must not be 0.
499<p> <p>See also <a href="#append">append</a>(), <a href="#insert">insert</a>(), and <a href="#current">current</a>().
500
501<h3 class=fn>type * <a name="prev"></a>QPtrList::prev ()
502</h3>
503
504<p> Returns a pointer to the item preceding the current item. Returns
5050 if the current item is 0 or equal to the first item.
506<p> Makes the preceding item current. If the current item before this
507function call was the first item, the current item will be set to
5080. If the current item was 0, this function does nothing.
509<p> <p>See also <a href="#first">first</a>(), <a href="#last">last</a>(), <a href="#next">next</a>(), and <a href="#current">current</a>().
510
511<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="read"></a>QPtrList::read ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a>&nbsp;&amp;&nbsp;item )<tt> [virtual protected]</tt>
512</h3>
513
514<p> Reads a list item from the stream <em>s</em> and returns a reference to
515the stream.
516<p> The default implementation sets <em>item</em> to 0.
517<p> <p>See also <a href="#write">write</a>().
518
519<h3 class=fn>bool <a name="remove"></a>QPtrList::remove ( uint&nbsp;index )
520</h3>
521
522<p> Removes the item at position <em>index</em> in the list.
523<p> Returns TRUE if successful, i.e. if <em>index</em> is in range;
524otherwise returns FALSE. The valid range is <tt>0..(count() - 1)</tt>
525inclusive.
526<p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
527<p> The item after the removed item becomes the new current list item
528if the removed item is not the last item in the list. If the last
529item is removed, the new last item becomes the current item.
530<p> All list iterators that refer to the removed item will be set to
531point to the new current item.
532<p> <p>See also <a href="#take">take</a>(), <a href="#clear">clear</a>(), <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <a href="#current">current</a>(), and <a href="#removeRef">removeRef</a>().
533
534<h3 class=fn>bool <a name="remove-2"></a>QPtrList::remove ()
535</h3>
536
537<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
538<p> Removes the current list item.
539<p> Returns TRUE if successful, i.e. if the current item isn't 0;
540otherwise returns FALSE.
541<p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
542<p> The item after the removed item becomes the new current list item
543if the removed item is not the last item in the list. If the last
544item is removed, the new last item becomes the current item. The
545current item is set to 0 if the list becomes empty.
546<p> All list iterators that refer to the removed item will be set to
547point to the new current item.
548<p> <p>See also <a href="#take">take</a>(), <a href="#clear">clear</a>(), <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <a href="#current">current</a>(), and <a href="#removeRef">removeRef</a>().
549
550<h3 class=fn>bool <a name="remove-3"></a>QPtrList::remove ( const&nbsp;type&nbsp;*&nbsp;item )
551</h3>
552
553<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
554<p> Removes the first occurrence of <em>item</em> from the list.
555<p> Returns TRUE if successful, i.e. if <em>item</em> is in the list;
556otherwise returns FALSE.
557<p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
558<p> The <a href="#compareItems">compareItems</a>() function is called when searching for the item
559in the list. If compareItems() is not reimplemented, it is more
560efficient to call <a href="#removeRef">removeRef</a>().
561<p> If <em>item</em> is NULL then the current item is removed from the list.
562<p> The item after the removed item becomes the new current list item
563if the removed item is not the last item in the list. If the last
564item is removed, the new last item becomes the current item. The
565current item is set to 0 if the list becomes empty.
566<p> All list iterators that refer to the removed item will be set to
567point to the new current item.
568<p> <p>See also <a href="#removeRef">removeRef</a>(), <a href="#take">take</a>(), <a href="#clear">clear</a>(), <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <a href="#compareItems">compareItems</a>(), and <a href="#current">current</a>().
569
570<h3 class=fn>bool <a name="removeFirst"></a>QPtrList::removeFirst ()
571</h3>
572
573<p> Removes the first item from the list. Returns TRUE if successful,
574i.e. if the list isn't empty; otherwise returns FALSE.
575<p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
576<p> The first item in the list becomes the new current list item. The
577current item is set to 0 if the list becomes empty.
578<p> All list iterators that refer to the removed item will be set to
579point to the new current item.
580<p> <p>See also <a href="#removeLast">removeLast</a>(), <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), <a href="#current">current</a>(), and <a href="#remove">remove</a>().
581
582<h3 class=fn>bool <a name="removeLast"></a>QPtrList::removeLast ()
583</h3>
584
585<p> Removes the last item from the list. Returns TRUE if successful,
586i.e. if the list isn't empty; otherwise returns FALSE.
587<p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
588<p> The last item in the list becomes the new current list item. The
589current item is set to 0 if the list becomes empty.
590<p> All list iterators that refer to the removed item will be set to
591point to the new current item.
592<p> <p>See also <a href="#removeFirst">removeFirst</a>(), <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), and <a href="#current">current</a>().
593
594<h3 class=fn>void <a name="removeNode"></a>QPtrList::removeNode ( QLNode&nbsp;*&nbsp;node )
595</h3>
596
597<p> Removes the <em>node</em> from the list.
598<p> This node must exist in the list, otherwise the program may crash.
599<p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
600<p> The first item in the list will become the new current list item.
601The current item is set to 0 if the list becomes empty.
602<p> All list iterators that refer to the removed item will be set to
603point to the item succeeding this item or to the preceding item if
604the removed item was the last item.
605<p> <b>Warning:</b> Do not call this function unless you are an expert.
606<p> <p>See also <a href="#takeNode">takeNode</a>(), <a href="#currentNode">currentNode</a>(), <a href="#remove">remove</a>(), and <a href="#removeRef">removeRef</a>().
607
608<h3 class=fn>bool <a name="removeRef"></a>QPtrList::removeRef ( const&nbsp;type&nbsp;*&nbsp;item )
609</h3>
610
611<p> Removes the first occurrence of <em>item</em> from the list.
612<p> Returns TRUE if successful, i.e. if <em>item</em> is in the list;
613otherwise returns FALSE.
614<p> The removed item is deleted if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled.
615<p> Equivalent to:
616<pre>
617 if ( list.findRef( item ) != -1 )
618 list.remove();
619 </pre>
620
621<p> The item after the removed item becomes the new current list item
622if the removed item is not the last item in the list. If the last
623item is removed, the new last item becomes the current item. The
624current item is set to 0 if the list becomes empty.
625<p> All list iterators that refer to the removed item will be set to
626point to the new current item.
627<p> <p>See also <a href="#remove">remove</a>(), <a href="#clear">clear</a>(), <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(), and <a href="#current">current</a>().
628
629<h3 class=fn>bool <a name="replace"></a>QPtrList::replace ( uint&nbsp;index, const&nbsp;type&nbsp;*&nbsp;item )
630</h3>
631
632<p> Replaces the item at position <em>index</em> with the new <em>item</em>.
633<p> Returns TRUE if successful, i.e. <em>index</em> is in the range 0 to
634<a href="#count">count</a>()-1.
635<p> <p>See also <a href="#append">append</a>(), <a href="#current">current</a>(), and <a href="#insert">insert</a>().
636
637<h3 class=fn>void <a name="setAutoDelete"></a>QPtrCollection::setAutoDelete ( bool&nbsp;enable )
638</h3>
639
640<p> Sets the collection to auto-delete its contents if <em>enable</em> is
641TRUE and to never delete them if <em>enable</em> is FALSE.
642<p> If auto-deleting is turned on, all the items in a collection are
643deleted when the collection itself is deleted. This is convenient
644if the collection has the only pointer to the items.
645<p> The default setting is FALSE, for safety. If you turn it on, be
646careful about copying the collection - you might find yourself
647with two collections deleting the same items.
648<p> Note that the auto-delete setting may also affect other functions
649in subclasses. For example, a subclass that has a <a href="#remove">remove</a>()
650function will remove the item from its data structure, and if
651auto-delete is enabled, will also delete the item.
652<p> <p>See also <a href="qptrcollection.html#autoDelete">autoDelete</a>().
653
654<p>Examples: <a href="grapher-nsplugin-example.html#x2769">grapher/grapher.cpp</a>, <a href="scribble-example.html#x924">scribble/scribble.cpp</a>, and <a href="bigtable-example.html#x1291">table/bigtable/main.cpp</a>.
655<h3 class=fn>void <a name="sort"></a>QPtrList::sort ()
656</h3>
657
658<p> Sorts the list by the result of the virtual <a href="#compareItems">compareItems</a>()
659function.
660<p> The heap sort algorithm is used for sorting. It sorts n items with
661O(n*log n) comparisons. This is the asymptotic optimal solution of
662the sorting problem.
663<p> If the items in your list support <a href="qcstring.html#operator-lt-2">operator&lt;</a>() and <a href="#operator-eq-eq">operator==</a>(),
664you might be better off with QSortedList because it implements the
665compareItems() function for you using these two operators.
666<p> <p>See also <a href="#inSort">inSort</a>().
667
668<h3 class=fn>type * <a name="take"></a>QPtrList::take ( uint&nbsp;index )
669</h3>
670
671<p> Takes the item at position <em>index</em> out of the list without
672deleting it (even if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a>
673is enabled).
674<p> Returns a pointer to the item taken out of the list, or 0 if the
675index is out of range. The valid range is <tt>0..(count() - 1)</tt>
676inclusive.
677<p> The item after the removed item becomes the new current list item
678if the removed item is not the last item in the list. If the last
679item is removed, the new last item becomes the current item. The
680current item is set to 0 if the list becomes empty.
681<p> All list iterators that refer to the taken item will be set to
682point to the new current item.
683<p> <p>See also <a href="#remove">remove</a>(), <a href="#clear">clear</a>(), and <a href="#current">current</a>().
684
685<p>Examples: <a href="customlayout-example.html#x1503">customlayout/border.cpp</a>, <a href="customlayout-example.html#x1521">customlayout/card.cpp</a>, and <a href="customlayout-example.html#x1480">customlayout/flow.cpp</a>.
686<h3 class=fn>type * <a name="take-2"></a>QPtrList::take ()
687</h3>
688
689<p> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
690<p> Takes the current item out of the list without deleting it (even
691if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled).
692<p> Returns a pointer to the item taken out of the list, or 0 if
693the current item is 0.
694<p> The item after the removed item becomes the new current list item
695if the removed item is not the last item in the list. If the last
696item is removed, the new last item becomes the current item. The
697current item is set to 0 if the list becomes empty.
698<p> All list iterators that refer to the taken item will be set to
699point to the new current item.
700<p> <p>See also <a href="#remove">remove</a>(), <a href="#clear">clear</a>(), and <a href="#current">current</a>().
701
702<h3 class=fn>type * <a name="takeNode"></a>QPtrList::takeNode ( QLNode&nbsp;*&nbsp;node )
703</h3>
704
705<p> Takes the <em>node</em> out of the list without deleting its item (even
706if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled).
707Returns a pointer to the item taken out of the list.
708<p> This node must exist in the list, otherwise the program may crash.
709<p> The first item in the list becomes the new current list item.
710<p> All list iterators that refer to the taken item will be set to
711point to the item succeeding this item or to the preceding item if
712the taken item was the last item.
713<p> <b>Warning:</b> Do not call this function unless you are an expert.
714<p> <p>See also <a href="#removeNode">removeNode</a>() and <a href="#currentNode">currentNode</a>().
715
716<h3 class=fn>void <a name="toVector"></a>QPtrList::toVector ( QGVector&nbsp;*&nbsp;vec ) const
717</h3>
718
719<p> Stores all list items in the vector <em>vec</em>.
720<p> The vector must be of the same item type, otherwise the result
721will be undefined.
722
723<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="write"></a>QPtrList::write ( <a href="qdatastream.html">QDataStream</a>&nbsp;&amp;&nbsp;s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a>&nbsp;item ) const<tt> [virtual protected]</tt>
724</h3>
725
726<p> Writes a list item, <em>item</em> to the stream <em>s</em> and returns a
727reference to the stream.
728<p> The default implementation does nothing.
729<p> <p>See also <a href="#read">read</a>().
730
731<!-- eof -->
732<hr><p>
733This file is part of the <a href="index.html">Qt toolkit</a>.
734Copyright &copy; 1995-2007
735<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
736<table width=100% cellspacing=0 border=0><tr>
737<td>Copyright &copy; 2007
738<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
739<td align=right><div align=right>Qt 3.3.8</div>
740</table></div></address></body>
741</html>
Note: See TracBrowser for help on using the repository browser.