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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
<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>Chapter 10. ListView, GridView, ColumnView</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="index.html" title="Programming with gtkmm 4">
<link rel="prev" href="sec-multi-item-containers.html" title="Multiple-item Containers">
<link rel="next" href="sec-listmodel-selectionmodel.html" title="The Selection Model">
</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">Chapter 10. ListView, GridView, ColumnView</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-multi-item-containers.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-listmodel-selectionmodel.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="chapter-listmodel"></a>Chapter 10. ListView, GridView, ColumnView</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="section"><a href="chapter-listmodel.html#sec-listmodel-datamodel">The Data Model</a></span></li>
<li><span class="section"><a href="sec-listmodel-selectionmodel.html">The Selection Model</a></span></li>
<li><span class="section"><a href="sec-listmodel-factory.html">The Factory</a></span></li>
<li><span class="section"><a href="sec-listmodel-view.html">The View</a></span></li>
<li><span class="section"><a href="sec-listmodel-sorting.html">Sorting</a></span></li>
<li><span class="section"><a href="sec-listmodel-filtering.html">Filtering</a></span></li>
<li><span class="section"><a href="sec-listmodel-trees.html">Displaying Trees</a></span></li>
</ul>
</div>
<p>
Lists are intended to be used whenever developers want to display many objects
in roughly the same way. They are perfectly fine to be used for very short lists
of only 2 or 3 items, but generally scale fine to thousands of items.
</p>
<p>
Lists are meant to be used with changing data, both with the items themselves
changing as well as the list adding and removing items. Of course, they work just
as well with static data.
</p>
<p>
The <a class="ulink" href="https://docs.gtk.org/gtk4/section-list-widget.html" target="_top">List Widget Overview</a>
chapter in the GTK documentation contains more information about list widgets.
</p>
<p>
Some examples are shown in this chapter. There are more examples in the
<a class="ulink" href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/listmodelviews/" target="_top">listmodelviews directory</a>
in <span class="application">gtkmm-documentation</span>'s examples.</p>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-listmodel-datamodel"></a>The Data Model</h2></div></div></div>
<p>
The data model is a class that implements the <code class="classname">Gio::ListModel</code>
interface. Examples of such classes are <code class="classname">Gio::ListStore</code>
(not to be confused with the deprecated <code class="classname">Gtk::ListStore</code>),
<code class="classname">Gtk:StringList</code>, <code class="classname">Gtk:DirectoryList</code>
and <code class="classname">Pango::FontMap</code>.
</p>
<p>
The elements in a model are called <span class="emphasis"><em>items</em></span>.
All items are instances of a subclass of <code class="classname">Glib::Object</code>.
For instance, you might have a <code class="classname">ColumnView</code> with one integer
and one text column, like so:
</p>
<pre class="programlisting"><code class="code">class ModelColumns : public Glib::Object
{
public:
int m_col_id;
Glib::ustring m_col_name;
static Glib::RefPtr<ModelColumns> create(
int col_id, const Glib::ustring& col_name)
{
return Glib::make_refptr_for_instance<ModelColumns>(
new ModelColumns(col_id, col_name));
}
protected:
ModelColumns(int col_id, const Glib::ustring& col_name)
: m_col_id(col_id), m_col_name(col_name)
{}
};
Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
</code></pre>
<p>
Every item in a model has a position which is the unsigned integer that describes
where in the model the item is located. The first item in a model is at position 0.
The position of an item can of course change as other items are added to or removed
from the model.
</p>
<p><a class="ulink" href="https://gnome.pages.gitlab.gnome.org/glibmm/classGio_1_1ListStore.html" target="_top">Gio::ListStore Reference</a></p>
<p><a class="ulink" href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1StringList.html" target="_top">StringList Reference</a></p>
<p><a class="ulink" href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1DirectoryList.html" target="_top">DirectoryList Reference</a></p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-multi-item-containers.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-listmodel-selectionmodel.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Multiple-item Containers </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 Model</td>
</tr>
</table>
</div>
</body>
</html>
|