1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
hljs.configure({languages: ['cpp']});
hljs.highlightAll();
</script><title>Iterating over Model Rows</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="chapter-treeview.html" title="Chapter 11. The TreeView widget">
<link rel="prev" href="sec-treeview.html" title="The View">
<link rel="next" href="sec-treeview-selection.html" title="The Selection">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Iterating over Model Rows</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-treeview.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Chapter 11. The TreeView widget</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-treeview-selection.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-iterating-over-model-rows"></a>Iterating over Model Rows</h2></div></div></div>
<p>
<code class="classname">Gtk::TreeModel</code> provides a C++ Standard Library-style container of its
children, via the <code class="methodname">children()</code> method. You can use the
familiar <code class="methodname">begin()</code> and <code class="methodname">end()</code> methods
iterator incrementing, like so:
</p>
<pre class="programlisting"><code class="code">auto children = refModel->children();
for (auto iter = children.begin(), end = children.end(); iter != end; ++iter)
{
auto row = *iter;
//Do something with the row - see above for set/get.
}</code></pre>
<p>
If you always want to iterate across the entire range, much more succinct syntax
is possible using C++'s range-based <code class="literal">for</code> loop:
</p>
<pre class="programlisting"><code class="code">for (auto row: refModel->children())
{
//Do something with the row - see above for set/get.
}</code></pre>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="treeview-row-children"></a>Row children</h3></div></div></div>
<p>
When using a <code class="classname">Gtk::TreeStore</code>, the rows can have child
rows, which can have their own children in turn. Use
<code class="methodname">Gtk::TreeModel::Row::children()</code> to get the container of child <code class="classname">Row</code>s:
</p>
<pre class="programlisting"><code class="code">Gtk::TreeModel::Children children = row.children();</code></pre>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-treeview.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-treeview.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-treeview-selection.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">The View </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> The Selection</td>
</tr>
</table>
</div>
</body>
</html>
|