| 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"><!--
|
|---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
|---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
|---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
|---|
| 11 | body { 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 Classes</font></a>
|
|---|
| 23 | | <a href="mainclasses.html">
|
|---|
| 24 | <font color="#004faf">Main 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 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 <<a href="qptrlist-h.html">qptrlist.h</a>></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 QPtrList<type> & list )</li>
|
|---|
| 44 | <li class=fn><a href="#~QPtrList"><b>~QPtrList</b></a> ()</li>
|
|---|
| 45 | <li class=fn>QPtrList<type> & <a href="#operator-eq"><b>operator=</b></a> ( const QPtrList<type> & list )</li>
|
|---|
| 46 | <li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QPtrList<type> & list ) const</li>
|
|---|
| 47 | <li class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QPtrList<type> & 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 index, const type * item )</li>
|
|---|
| 51 | <li class=fn>void <a href="#inSort"><b>inSort</b></a> ( const type * item )</li>
|
|---|
| 52 | <li class=fn>void <a href="#prepend"><b>prepend</b></a> ( const type * item )</li>
|
|---|
| 53 | <li class=fn>void <a href="#append"><b>append</b></a> ( const type * item )</li>
|
|---|
| 54 | <li class=fn>bool <a href="#remove"><b>remove</b></a> ( uint 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 type * item )</li>
|
|---|
| 57 | <li class=fn>bool <a href="#removeRef"><b>removeRef</b></a> ( const type * item )</li>
|
|---|
| 58 | <li class=fn>void <a href="#removeNode"><b>removeNode</b></a> ( QLNode * 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 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 * 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 type * item )</li>
|
|---|
| 67 | <li class=fn>int <a href="#findNext"><b>findNext</b></a> ( const type * item )</li>
|
|---|
| 68 | <li class=fn>int <a href="#findRef"><b>findRef</b></a> ( const type * item )</li>
|
|---|
| 69 | <li class=fn>int <a href="#findNextRef"><b>findNextRef</b></a> ( const type * item )</li>
|
|---|
| 70 | <li class=fn>uint <a href="#contains"><b>contains</b></a> ( const type * item ) const</li>
|
|---|
| 71 | <li class=fn>uint <a href="#containsRef"><b>containsRef</b></a> ( const type * item ) const</li>
|
|---|
| 72 | <li class=fn>bool <a href="#replace"><b>replace</b></a> ( uint index, const type * item )</li>
|
|---|
| 73 | <li class=fn>type * <a href="#at"><b>at</b></a> ( uint 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 * 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 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 item1, QPtrCollection::Item item2 )</li>
|
|---|
| 93 | <li class=fn>virtual QDataStream & <a href="#read"><b>read</b></a> ( QDataStream & s, QPtrCollection::Item & item )</li>
|
|---|
| 94 | <li class=fn>virtual QDataStream & <a href="#write"><b>write</b></a> ( QDataStream & s, QPtrCollection::Item item ) const</li>
|
|---|
| 95 | </ul>
|
|---|
| 96 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | The 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<X> to create a list that
|
|---|
| 105 | operates 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
|
|---|
| 108 | first 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
|
|---|
| 111 | removed 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>().
|
|---|
| 114 | You can count the number of occurrences of an item with <a href="#contains">contains</a>()
|
|---|
| 115 | or <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
|
|---|
| 117 | with <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
|
|---|
| 120 | deletion property is set with <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>().
|
|---|
| 121 | <p> <a name="example"></a>
|
|---|
| 122 | Example:
|
|---|
| 123 | <pre>
|
|---|
| 124 | class Employee
|
|---|
| 125 | {
|
|---|
| 126 | public:
|
|---|
| 127 | Employee() : sn( 0 ) { }
|
|---|
| 128 | Employee( const <a href="qstring.html">QString</a>& forename, const <a href="qstring.html">QString</a>& 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<Employee> 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 << employee->surname().latin1() << ", " <<
|
|---|
| 154 | employee->forename().latin1() << " earns " <<
|
|---|
| 155 | employee->salary() << endl;
|
|---|
| 156 | cout << endl;
|
|---|
| 157 |
|
|---|
| 158 | // very inefficient for big lists
|
|---|
| 159 | for ( uint i = 0; i < list.<a href="#count">count</a>(); ++i )
|
|---|
| 160 | if ( list.<a href="#at">at</a>(i) )
|
|---|
| 161 | cout << list.<a href="#at">at</a>( i )->surname().latin1() << 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
|
|---|
| 176 | using a <a href="qptrlistiterator.html">QPtrListIterator</a> can be more practical. Multiple list
|
|---|
| 177 | iterators may traverse the same list, independently of each other
|
|---|
| 178 | and of the current list item.
|
|---|
| 179 | <p> In the example above we make the call <a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>(TRUE).
|
|---|
| 180 | Enabling auto-deletion tells the list to delete items that are
|
|---|
| 181 | removed. The default is to not delete items when they are removed
|
|---|
| 182 | but this would cause a memory leak in the example because there
|
|---|
| 183 | are no other references to the list items.
|
|---|
| 184 | <p> When inserting an item into a list only the pointer is copied, not
|
|---|
| 185 | the item itself, i.e. a <a href="shclass.html#shallow-copy">shallow copy</a>. It is possible to make the
|
|---|
| 186 | list copy all of the item's data (deep copy) when an item is
|
|---|
| 187 | inserted. <a href="#insert">insert</a>(), <a href="#inSort">inSort</a>() and <a href="#append">append</a>() call the virtual
|
|---|
| 188 | function <a href="qptrcollection.html#newItem">QPtrCollection::newItem</a>() for the item to be inserted.
|
|---|
| 189 | Inherit 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
|
|---|
| 192 | implementation is to delete the item if auto-deletion is enabled.
|
|---|
| 193 | <p> The virtual function <a href="#compareItems">compareItems</a>() can be reimplemented to
|
|---|
| 194 | compare two list items. This function is called from all list
|
|---|
| 195 | functions 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
|
|---|
| 197 | are functions that compare pointers instead, for instance
|
|---|
| 198 | <a href="#removeRef">removeRef</a>(const type*). These functions are somewhat faster than
|
|---|
| 199 | those that call compareItems().
|
|---|
| 200 | <p> List items are stored as <tt>void*</tt> in an internal QLNode, which
|
|---|
| 201 | also holds pointers to the next and previous list items. The
|
|---|
| 202 | functions <a href="#currentNode">currentNode</a>(), <a href="#removeNode">removeNode</a>(), and <a href="#takeNode">takeNode</a>() operate
|
|---|
| 203 | directly on the QLNode, but they should be used with care. The
|
|---|
| 204 | data 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>.
|
|---|
| 206 | It reimplements <a href="qptrcollection.html#newItem">newItem</a>(), <a href="qptrcollection.html#deleteItem">deleteItem</a>() and <a href="#compareItems">compareItems</a>(). (But
|
|---|
| 207 | see <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 <a href="qptrlist.html">QPtrList</a><type> & 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
|
|---|
| 221 | list. 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 type * 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
|
|---|
| 235 | equivalent 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 index )
|
|---|
| 241 | </h3>
|
|---|
| 242 |
|
|---|
| 243 | <p> Returns a pointer to the item at position <em>index</em> in the list, or
|
|---|
| 244 | 0 if the index is out of range.
|
|---|
| 245 | <p> Sets the current list item to this item if <em>index</em> is valid. The
|
|---|
| 246 | valid range is <tt>0..(count() - 1)</tt> inclusive.
|
|---|
| 247 | <p> This function is very efficient. It starts scanning from the first
|
|---|
| 248 | item, 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> item1, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> 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
|
|---|
| 285 | reimplementations 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> > 0 (positive integer) if <em>item1</em> > <em>item2</em>
|
|---|
| 289 | <li> < 0 (negative integer) if <em>item1</em> < <em>item2</em>
|
|---|
| 290 | </ul>
|
|---|
| 291 | <p> <a href="#inSort">inSort</a>() requires that <a href="#compareItems">compareItems</a>() is implemented as described
|
|---|
| 292 | here.
|
|---|
| 293 | <p> This function should not modify the list because some const
|
|---|
| 294 | functions call compareItems().
|
|---|
| 295 | <p> The default implementation compares the pointers.
|
|---|
| 296 |
|
|---|
| 297 | <h3 class=fn>uint <a name="contains"></a>QPtrList::contains ( const type * 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>
|
|---|
| 302 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 303 | efficient 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 type * 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
|
|---|
| 312 | contains() 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
|
|---|
| 329 | be 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
|
|---|
| 337 | advantage is that the item can be removed directly without
|
|---|
| 338 | searching 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 type * 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
|
|---|
| 347 | the found item and returns the index of this item. If the item is
|
|---|
| 348 | not found, the list sets the current item to 0, the current
|
|---|
| 349 | index to -1, and returns -1.
|
|---|
| 350 | <p> The <a href="#compareItems">compareItems</a>() function is called when searching for the item
|
|---|
| 351 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 352 | efficient 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 type * item )
|
|---|
| 356 | </h3>
|
|---|
| 357 |
|
|---|
| 358 | <p> Finds the next occurrence of <em>item</em> in the list, starting from
|
|---|
| 359 | the current list item.
|
|---|
| 360 | <p> If the item is found, the list sets the current item to point to
|
|---|
| 361 | the found item and returns the index of this item. If the item is
|
|---|
| 362 | not found, the list sets the current item to 0, the current
|
|---|
| 363 | index to -1, and returns -1.
|
|---|
| 364 | <p> The <a href="#compareItems">compareItems</a>() function is called when searching for the item
|
|---|
| 365 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 366 | efficient 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 type * item )
|
|---|
| 370 | </h3>
|
|---|
| 371 |
|
|---|
| 372 | <p> Finds the next occurrence of <em>item</em> in the list, starting from
|
|---|
| 373 | the current list item.
|
|---|
| 374 | <p> If the item is found, the list sets the current item to point to
|
|---|
| 375 | the found item and returns the index of this item. If the item is
|
|---|
| 376 | not found, the list sets the current item to 0, the current
|
|---|
| 377 | index to -1, and returns -1.
|
|---|
| 378 | <p> Calling this function is much faster than <a href="#findNext">findNext</a>() because
|
|---|
| 379 | findNext() 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 type * 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
|
|---|
| 388 | the found item and returns the index of this item. If the item is
|
|---|
| 389 | not found, the list sets the current item to 0, the current
|
|---|
| 390 | index to -1, and returns -1.
|
|---|
| 391 | <p> Calling this function is much faster than <a href="#find">find</a>() because find()
|
|---|
| 392 | compares <em>item</em> with each list item using <a href="#compareItems">compareItems</a>(), whereas
|
|---|
| 393 | this 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
|
|---|
| 400 | current 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
|
|---|
| 408 | is 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
|
|---|
| 416 | is 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 type * 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
|
|---|
| 425 | items must be inserted with <a href="#inSort">inSort</a>() to maintain the sorting
|
|---|
| 426 | order.
|
|---|
| 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
|
|---|
| 430 | have lots of items, is to simply <a href="#append">append</a>() or <a href="#insert">insert</a>() them and
|
|---|
| 431 | then use <a href="#sort">sort</a>(). inSort() takes up to O(n) compares. That means
|
|---|
| 432 | inserting n items in your list will need O(n^2) compares whereas
|
|---|
| 433 | sort() only needs O(n*log n) for the same task. So use inSort()
|
|---|
| 434 | only if you already have a presorted list and want to insert just
|
|---|
| 435 | a 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 index, const type * 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;
|
|---|
| 443 | otherwise 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
|
|---|
| 459 | current 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
|
|---|
| 466 | 0 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
|
|---|
| 468 | function call was the last item, the current item will be set to
|
|---|
| 469 | 0. 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 <a href="qptrlist.html">QPtrList</a><type> & list ) const
|
|---|
| 474 | </h3>
|
|---|
| 475 |
|
|---|
| 476 | <p> Compares this list with <em>list</em>. Returns TRUE if the lists contain
|
|---|
| 477 | different data; otherwise returns FALSE.
|
|---|
| 478 |
|
|---|
| 479 | <h3 class=fn><a href="qptrlist.html">QPtrList</a><type> & <a name="operator-eq"></a>QPtrList::operator= ( const <a href="qptrlist.html">QPtrList</a><type> & 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
|
|---|
| 484 | copied (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 <a href="qptrlist.html">QPtrList</a><type> & list ) const
|
|---|
| 487 | </h3>
|
|---|
| 488 |
|
|---|
| 489 | <p> Compares this list with <em>list</em>. Returns TRUE if the lists contain
|
|---|
| 490 | the same data; otherwise returns FALSE.
|
|---|
| 491 |
|
|---|
| 492 | <h3 class=fn>void <a name="prepend"></a>QPtrList::prepend ( const type * 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
|
|---|
| 497 | equivalent 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
|
|---|
| 505 | 0 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
|
|---|
| 507 | function call was the first item, the current item will be set to
|
|---|
| 508 | 0. 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> & <a name="read"></a>QPtrList::read ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> & 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
|
|---|
| 515 | the 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 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;
|
|---|
| 524 | otherwise returns FALSE. The valid range is <tt>0..(count() - 1)</tt>
|
|---|
| 525 | inclusive.
|
|---|
| 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
|
|---|
| 528 | if the removed item is not the last item in the list. If the last
|
|---|
| 529 | item 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
|
|---|
| 531 | point 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;
|
|---|
| 540 | otherwise 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
|
|---|
| 543 | if the removed item is not the last item in the list. If the last
|
|---|
| 544 | item is removed, the new last item becomes the current item. The
|
|---|
| 545 | current 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
|
|---|
| 547 | point 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 type * 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;
|
|---|
| 556 | otherwise 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
|
|---|
| 559 | in the list. If compareItems() is not reimplemented, it is more
|
|---|
| 560 | efficient 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
|
|---|
| 563 | if the removed item is not the last item in the list. If the last
|
|---|
| 564 | item is removed, the new last item becomes the current item. The
|
|---|
| 565 | current 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
|
|---|
| 567 | point 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,
|
|---|
| 574 | i.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
|
|---|
| 577 | current 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
|
|---|
| 579 | point 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,
|
|---|
| 586 | i.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
|
|---|
| 589 | current 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
|
|---|
| 591 | point 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 * 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.
|
|---|
| 601 | The 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
|
|---|
| 603 | point to the item succeeding this item or to the preceding item if
|
|---|
| 604 | the 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 type * 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;
|
|---|
| 613 | otherwise 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
|
|---|
| 622 | if the removed item is not the last item in the list. If the last
|
|---|
| 623 | item is removed, the new last item becomes the current item. The
|
|---|
| 624 | current 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
|
|---|
| 626 | point 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 index, const type * 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 enable )
|
|---|
| 638 | </h3>
|
|---|
| 639 |
|
|---|
| 640 | <p> Sets the collection to auto-delete its contents if <em>enable</em> is
|
|---|
| 641 | TRUE 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
|
|---|
| 643 | deleted when the collection itself is deleted. This is convenient
|
|---|
| 644 | if the collection has the only pointer to the items.
|
|---|
| 645 | <p> The default setting is FALSE, for safety. If you turn it on, be
|
|---|
| 646 | careful about copying the collection - you might find yourself
|
|---|
| 647 | with two collections deleting the same items.
|
|---|
| 648 | <p> Note that the auto-delete setting may also affect other functions
|
|---|
| 649 | in subclasses. For example, a subclass that has a <a href="#remove">remove</a>()
|
|---|
| 650 | function will remove the item from its data structure, and if
|
|---|
| 651 | auto-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>()
|
|---|
| 659 | function.
|
|---|
| 660 | <p> The heap sort algorithm is used for sorting. It sorts n items with
|
|---|
| 661 | O(n*log n) comparisons. This is the asymptotic optimal solution of
|
|---|
| 662 | the sorting problem.
|
|---|
| 663 | <p> If the items in your list support <a href="qcstring.html#operator-lt-2">operator<</a>() and <a href="#operator-eq-eq">operator==</a>(),
|
|---|
| 664 | you might be better off with QSortedList because it implements the
|
|---|
| 665 | compareItems() 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 index )
|
|---|
| 669 | </h3>
|
|---|
| 670 |
|
|---|
| 671 | <p> Takes the item at position <em>index</em> out of the list without
|
|---|
| 672 | deleting it (even if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a>
|
|---|
| 673 | is enabled).
|
|---|
| 674 | <p> Returns a pointer to the item taken out of the list, or 0 if the
|
|---|
| 675 | index is out of range. The valid range is <tt>0..(count() - 1)</tt>
|
|---|
| 676 | inclusive.
|
|---|
| 677 | <p> The item after the removed item becomes the new current list item
|
|---|
| 678 | if the removed item is not the last item in the list. If the last
|
|---|
| 679 | item is removed, the new last item becomes the current item. The
|
|---|
| 680 | current 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
|
|---|
| 682 | point 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
|
|---|
| 691 | if <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
|
|---|
| 693 | the current item is 0.
|
|---|
| 694 | <p> The item after the removed item becomes the new current list item
|
|---|
| 695 | if the removed item is not the last item in the list. If the last
|
|---|
| 696 | item is removed, the new last item becomes the current item. The
|
|---|
| 697 | current 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
|
|---|
| 699 | point 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 * node )
|
|---|
| 703 | </h3>
|
|---|
| 704 |
|
|---|
| 705 | <p> Takes the <em>node</em> out of the list without deleting its item (even
|
|---|
| 706 | if <a href="qptrcollection.html#setAutoDelete">auto-deletion</a> is enabled).
|
|---|
| 707 | Returns 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
|
|---|
| 711 | point to the item succeeding this item or to the preceding item if
|
|---|
| 712 | the 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 * 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
|
|---|
| 721 | will be undefined.
|
|---|
| 722 |
|
|---|
| 723 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="write"></a>QPtrList::write ( <a href="qdatastream.html">QDataStream</a> & s, <a href="qptrcollection.html#Item">QPtrCollection::Item</a> 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
|
|---|
| 727 | reference 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>
|
|---|
| 733 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
|---|
| 734 | Copyright © 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 © 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>
|
|---|