Sophie

Sophie

distrib > CentOS > 5 > x86_64 > by-pkgid > ac91357d6caede925de099a02fced14e > files > 4357

qt4-doc-4.2.1-1.el5_7.1.x86_64.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /tmp/qt-4.2.1-harald-1161357942206/qt-x11-opensource-src-4.2.1/doc/src/qiterator.qdoc -->
<head>
  <title>Qt 4.2: QMapIterator Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QMapIterator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
<p>The QMapIterator class provides a Java-style const iterator for <a href="qmap.html">QMap</a> and <a href="qmultimap.html">QMultiMap</a>. <a href="#details">More...</a></p>
<pre> #include &lt;QMapIterator&gt;</pre><ul>
<li><a href="qmapiterator-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qmapiterator.html#QMapIterator">QMapIterator</a></b> ( const QMap&lt;Key, T&gt; &amp; <i>map</i> )</li>
<li><div class="fn"/>bool <b><a href="qmapiterator.html#findNext">findNext</a></b> ( const T &amp; <i>value</i> )</li>
<li><div class="fn"/>bool <b><a href="qmapiterator.html#findPrevious">findPrevious</a></b> ( const T &amp; <i>value</i> )</li>
<li><div class="fn"/>bool <b><a href="qmapiterator.html#hasNext">hasNext</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qmapiterator.html#hasPrevious">hasPrevious</a></b> () const</li>
<li><div class="fn"/>const Key &amp; <b><a href="qmapiterator.html#key">key</a></b> () const</li>
<li><div class="fn"/>Item <b><a href="qmapiterator.html#next">next</a></b> ()</li>
<li><div class="fn"/>Item <b><a href="qmapiterator.html#peekNext">peekNext</a></b> () const</li>
<li><div class="fn"/>Item <b><a href="qmapiterator.html#peekPrevious">peekPrevious</a></b> () const</li>
<li><div class="fn"/>Item <b><a href="qmapiterator.html#previous">previous</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qmapiterator.html#toBack">toBack</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qmapiterator.html#toFront">toFront</a></b> ()</li>
<li><div class="fn"/>const T &amp; <b><a href="qmapiterator.html#value">value</a></b> () const</li>
<li><div class="fn"/>QMapIterator &amp; <b><a href="qmapiterator.html#operator-eq">operator=</a></b> ( const QMap&lt;Key, T&gt; &amp; <i>map</i> )</li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QMapIterator class provides a Java-style const iterator for <a href="qmap.html">QMap</a> and <a href="qmultimap.html">QMultiMap</a>.</p>
<p><a href="qmap.html">QMap</a> has both <a href="containers.html#java-style-iterators">Java-style iterators</a> and <a href="containers.html#stl-style-iterators">STL-style iterators</a>. The Java-style iterators are more high-level and easier to use than the STL-style iterators; on the other hand, they are slightly less efficient.</p>
<p>QMapIterator&lt;Key, T&gt; allows you to iterate over a <a href="qmap.html">QMap</a> (or a <a href="qmultimap.html">QMultiMap</a>). If you want to modify the map as you iterate over it, use <a href="qmutablemapiterator.html">QMutableMapIterator</a> instead.</p>
<p>The QMapIterator constructor takes a <a href="qmap.html">QMap</a> as argument. After construction, the iterator is located at the very beginning of the map (before the first item). Here's how to iterate over all the elements sequentially:</p>
<pre> QMap&lt;int, QWidget *&gt; map;
 ...
 QMapIterator&lt;QString, QWidget *&gt; i(map);
 while (i.hasNext()) {
     i.next();
     qDebug() &lt;&lt; i.key() &lt;&lt; &quot;: &quot; &lt;&lt; i.value();
 }</pre>
<p>The <a href="qmapiterator.html#next">next</a>() function returns the next item in the map and advances the iterator. The <a href="qmapiterator.html#key">key</a>() and <a href="qmapiterator.html#value">value</a>() functions return the key and value of the last item that was jumped over.</p>
<p>Unlike STL-style iterators, Java-style iterators point <i>between</i> items rather than directly <i>at</i> items. The first call to <a href="qmapiterator.html#next">next</a>() advances the iterator to the position between the first and second item, and returns the first item; the second call to <a href="qmapiterator.html#next">next</a>() advances the iterator to the position between the second and third item; and so on.</p>
<p align="center"><img src="images/javaiterators1.png" /></p><p>Here's how to iterate over the elements in reverse order:</p>
<pre> QMapIterator&lt;int, QWidget *&gt; i(map);
 i.toBack();
 while (i.hasPrevious()) {
     i.previous();
     qDebug() &lt;&lt; i.key() &lt;&lt; &quot;: &quot; &lt;&lt; i.value();
 }</pre>
<p>If you want to find all occurrences of a particular value, use <a href="qmapiterator.html#findNext">findNext</a>() or <a href="qmapiterator.html#findPrevious">findPrevious</a>() in a loop. For example:</p>
<pre> QMapIterator&lt;int, QWidget *&gt; i(map);
 while (i.findNext(widget)) {
     qDebug() &lt;&lt; &quot;Found widget &quot; &lt;&lt; widget &lt;&lt; &quot; under key &quot;
              &lt;&lt; i.key();
 }</pre>
<p>Multiple iterators can be used on the same map. If the map is modified while a QMapIterator is active, the QMapIterator will continue iterating over the original map, ignoring the modified copy.</p>
<p>See also <a href="qmutablemapiterator.html">QMutableMapIterator</a> and <a href="qmap-const-iterator.html">QMap::const_iterator</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QMapIterator"></a>QMapIterator::QMapIterator ( const <a href="qmap.html">QMap</a>&lt;Key, T&gt; &amp; <i>map</i> )</h3>
<p>Constructs an iterator for traversing <i>map</i>. The iterator is set to be at the front of the map (before the first item).</p>
<p>See also <a href="qmapiterator.html#operator-eq">operator=</a>().</p>
<h3 class="fn"><a name="findNext"></a>bool QMapIterator::findNext ( const T &amp; <i>value</i> )</h3>
<p>Searches for <i>value</i> starting from the current iterator position forward. Returns true if a (key, value) pair with value <i>value</i> is found; otherwise returns false.</p>
<p>After the call, if <i>value</i> was found, the iterator is positioned just after the matching item; otherwise, the iterator is positioned at the back of the container.</p>
<p>See also <a href="qmapiterator.html#findPrevious">findPrevious</a>().</p>
<h3 class="fn"><a name="findPrevious"></a>bool QMapIterator::findPrevious ( const T &amp; <i>value</i> )</h3>
<p>Searches for <i>value</i> starting from the current iterator position backward. Returns true if a (key, value) pair with value <i>value</i> is found; otherwise returns false.</p>
<p>After the call, if <i>value</i> was found, the iterator is positioned just before the matching item; otherwise, the iterator is positioned at the front of the container.</p>
<p>See also <a href="qmapiterator.html#findNext">findNext</a>().</p>
<h3 class="fn"><a name="hasNext"></a>bool QMapIterator::hasNext () const</h3>
<p>Returns true if there is at least one item ahead of the iterator, i.e. the iterator is <i>not</i> at the back of the container; otherwise returns false.</p>
<p>See also <a href="qmapiterator.html#hasPrevious">hasPrevious</a>() and <a href="qmapiterator.html#next">next</a>().</p>
<h3 class="fn"><a name="hasPrevious"></a>bool QMapIterator::hasPrevious () const</h3>
<p>Returns true if there is at least one item behind the iterator, i.e. the iterator is <i>not</i> at the front of the container; otherwise returns false.</p>
<p>See also <a href="qmapiterator.html#hasNext">hasNext</a>() and <a href="qmapiterator.html#previous">previous</a>().</p>
<h3 class="fn"><a name="key"></a>const Key &amp; QMapIterator::key () const</h3>
<p>Returns the key of the last item that was jumped over using one of the traversal functions (<a href="qmapiterator.html#next">next</a>(), <a href="qmapiterator.html#previous">previous</a>(), <a href="qmapiterator.html#findNext">findNext</a>(), <a href="qmapiterator.html#findPrevious">findPrevious</a>()).</p>
<p>After a call to <a href="qmapiterator.html#next">next</a>() or <a href="qmapiterator.html#findNext">findNext</a>(), key() is equivalent to <a href="qmapiterator.html#peekPrevious">peekPrevious</a>().key(). After a call to <a href="qmapiterator.html#previous">previous</a>() or <a href="qmapiterator.html#findPrevious">findPrevious</a>(), key() is equivalent to <a href="qmapiterator.html#peekNext">peekNext</a>().key().</p>
<p>See also <a href="qmapiterator.html#value">value</a>().</p>
<h3 class="fn"><a name="next"></a>Item QMapIterator::next ()</h3>
<p>Returns the next item and advances the iterator by one position.</p>
<p>Call <a href="qmapiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmapiterator.html#value">value</a>() to obtain the value.</p>
<p>Calling this function on an iterator located at the back of the container leads to undefined results.</p>
<p>See also <a href="qmapiterator.html#hasNext">hasNext</a>(), <a href="qmapiterator.html#peekNext">peekNext</a>(), and <a href="qmapiterator.html#previous">previous</a>().</p>
<h3 class="fn"><a name="peekNext"></a>Item QMapIterator::peekNext () const</h3>
<p>Returns the next item without moving the iterator.</p>
<p>Call <a href="qmapiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmapiterator.html#value">value</a>() to obtain the value.</p>
<p>Calling this function on an iterator located at the back of the container leads to undefined results.</p>
<p>See also <a href="qmapiterator.html#hasNext">hasNext</a>(), <a href="qmapiterator.html#next">next</a>(), and <a href="qmapiterator.html#peekPrevious">peekPrevious</a>().</p>
<h3 class="fn"><a name="peekPrevious"></a>Item QMapIterator::peekPrevious () const</h3>
<p>Returns the previous item without moving the iterator.</p>
<p>Call <a href="qmapiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmapiterator.html#value">value</a>() to obtain the value.</p>
<p>Calling this function on an iterator located at the front of the container leads to undefined results.</p>
<p>See also <a href="qmapiterator.html#hasPrevious">hasPrevious</a>(), <a href="qmapiterator.html#previous">previous</a>(), and <a href="qmapiterator.html#peekNext">peekNext</a>().</p>
<h3 class="fn"><a name="previous"></a>Item QMapIterator::previous ()</h3>
<p>Returns the previous item and moves the iterator back by one position.</p>
<p>Call <a href="qmapiterator.html#key">key</a>() on the return value to obtain the item's key, and <a href="qmapiterator.html#value">value</a>() to obtain the value.</p>
<p>Calling this function on an iterator located at the front of the container leads to undefined results.</p>
<p>See also <a href="qmapiterator.html#hasPrevious">hasPrevious</a>(), <a href="qmapiterator.html#peekPrevious">peekPrevious</a>(), and <a href="qmapiterator.html#next">next</a>().</p>
<h3 class="fn"><a name="toBack"></a>void QMapIterator::toBack ()</h3>
<p>Moves the iterator to the back of the container (after the last item).</p>
<p>See also <a href="qmapiterator.html#toFront">toFront</a>() and <a href="qmapiterator.html#previous">previous</a>().</p>
<h3 class="fn"><a name="toFront"></a>void QMapIterator::toFront ()</h3>
<p>Moves the iterator to the front of the container (before the first item).</p>
<p>See also <a href="qmapiterator.html#toBack">toBack</a>() and <a href="qmapiterator.html#next">next</a>().</p>
<h3 class="fn"><a name="value"></a>const T &amp; QMapIterator::value () const</h3>
<p>Returns the value of the last item that was jumped over using one of the traversal functions (<a href="qmapiterator.html#next">next</a>(), <a href="qmapiterator.html#previous">previous</a>(), <a href="qmapiterator.html#findNext">findNext</a>(), <a href="qmapiterator.html#findPrevious">findPrevious</a>()).</p>
<p>After a call to <a href="qmapiterator.html#next">next</a>() or <a href="qmapiterator.html#findNext">findNext</a>(), value() is equivalent to <a href="qmapiterator.html#peekPrevious">peekPrevious</a>().value(). After a call to <a href="qmapiterator.html#previous">previous</a>() or <a href="qmapiterator.html#findPrevious">findPrevious</a>(), value() is equivalent to <a href="qmapiterator.html#peekNext">peekNext</a>().value().</p>
<p>See also <a href="qmapiterator.html#key">key</a>().</p>
<h3 class="fn"><a name="operator-eq"></a>QMapIterator &amp; QMapIterator::operator= ( const <a href="qmap.html">QMap</a>&lt;Key, T&gt; &amp; <i>map</i> )</h3>
<p>Makes the iterator operate on <i>map</i>. The iterator is set to be at the front of the map (before the first item).</p>
<p>See also <a href="qmapiterator.html#toFront">toFront</a>() and <a href="qmapiterator.html#toBack">toBack</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2006 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.2.1</div></td>
</tr></table></div></address></body>
</html>