1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 A list-like data structure that can be used with the GtkTreeView
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GtkListStore object is a list model for use with a #GtkTreeView
10 widget. It implements the #GtkTreeModel interface, and consequentialy,
11 can use all of the methods available there. It also implements the
12 #GtkTreeSortable interface so it can be sorted by the view.
13 Finally, it also implements the tree <link linkend="gtktreednd">drag and
14 drop</link> interfaces.
18 The #GtkListStore can accept most GObject types as a column type, though
19 it can't accept all custom types. Internally, it will keep a copy of
20 data passed in (such as a string or a boxed pointer). Columns that
21 accept #GObject<!-- -->s are handled a little differently. The
22 #GtkListStore will keep a reference to the object instead of copying the
23 value. As a result, if the object is modified, it is up to the
24 application writer to call @gtk_tree_model_row_changed to emit the
25 "row_changed" signal. This most commonly affects lists with
26 #GdkPixbuf<!-- -->s stored.
30 <title>Creating a simple list store.</title>
40 GtkListStore *list_store;
45 list_store = gtk_list_store_new (N_COLUMNS,
50 for (i = 0; i < 10; i++)
54 some_data = get_some_data (i);
56 /* Add a new row to the model */
57 gtk_list_store_append (list_store, &iter);
58 gtk_list_store_set (list_store, &iter,
59 COLUMN_STRING, some_data,
61 COLUMN_BOOLEAN, FALSE,
64 /* As the store will keep a copy of the string internally, we
70 /* Modify a particular row */
71 path = gtk_tree_path_new_from_string ("4");
72 gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store),
75 gtk_tree_path_free (path);
76 gtk_list_store_set (list_store, &iter,
84 <title>Performance Considerations</title>
86 Internally, the #GtkListStore was implemented with a linked list with a
87 tail pointer prior to GTK+ 2.6. As a result, it was fast at data
88 insertion and deletion, and not fast at random data access. The
89 #GtkListStore sets the #GTK_TREE_MODEL_ITERS_PERSIST flag, which means
90 that #GtkTreeIter<!-- -->s can be cached while the row exists. Thus, if
91 access to a particular row is needed often and your code is expected to
92 run on older versions of GTK+, it is worth keeping the iter around.
94 <title>Atomic Operations</title>
96 It is important to note that only the methods
97 gtk_list_store_insert_with_values() and gtk_list_store_insert_with_valuesv()
98 are atomic, in the sense that the row is being appended to the store and the
99 values filled in in a single operation with regard to #GtkTreeModel signaling.
100 In contrast, using e.g. gtk_list_store_append() and then gtk_list_store_set()
101 will first create a row, which triggers the #GtkTreeModel::row-inserted signal
102 on #GtkListStore. The row, however, is still empty, and any signal handler
103 connecting to "row-inserted" on this particular store should be prepared
104 for the situation that the row might be empty. This is especially important
105 if you are wrapping the #GtkListStore inside a #GtkTreeModelFilter and are
106 using a #GtkTreeModelFilterVisibleFunc. Using any of the non-atomic operations
107 to append rows to the #GtkListStore will cause the
108 #GtkTreeModelFilterVisibleFunc to be visited with an empty row first; the
109 function must be prepared for that.
112 <refsect2 id="GtkListStore-BUILDER-UI">
113 <title>GtkListStore as GtkBuildable</title>
115 The GtkListStore implementation of the GtkBuildable interface allows
116 to specify the model columns with a <columns> element that may
117 contain multiple <column> elements, each specifying one model
118 column. The "type" attribute specifies the data type for the column.
121 Additionally, it is possible to specify content for the list store
122 in the UI definition, with the <data> element. It can contain
123 multiple <row> elements, each specifying to content for one
124 row of the list model. Inside a <row>, the <col> elements
125 specify the content for individual cells.
128 Note that it is probably more common to define your models
129 in the code, and one might consider it a layering violation
130 to specify the content of a list store in a UI definition,
131 <emphasis>data</emphasis>, not <emphasis>presentation</emphasis>,
132 and common wisdom is to separate the two, as far as possible.
133 <!-- FIXME a bit inconclusive -->
136 <title>A UI Definition fragment for a list store</title>
137 <programlisting><![CDATA[
138 <object class="GtkListStore">
140 <column type="gchararray"/>
141 <column type="gchararray"/>
142 <column type="gint"/>
146 <col id="0">John</col>
147 <col id="1">Doe</col>
151 <col id="0">Johan</col>
152 <col id="1">Dahlin</col>
161 <!-- ##### SECTION See_Also ##### -->
163 #GtkTreeModel, #GtkTreeStore
166 <!-- ##### SECTION Stability_Level ##### -->
169 <!-- ##### SECTION Image ##### -->
172 <!-- ##### STRUCT GtkListStore ##### -->
178 <!-- ##### FUNCTION gtk_list_store_new ##### -->
188 <!-- ##### FUNCTION gtk_list_store_newv ##### -->
198 <!-- ##### FUNCTION gtk_list_store_set_column_types ##### -->
208 <!-- ##### FUNCTION gtk_list_store_set ##### -->
218 <!-- ##### FUNCTION gtk_list_store_set_valist ##### -->
228 <!-- ##### FUNCTION gtk_list_store_set_value ##### -->
239 <!-- ##### FUNCTION gtk_list_store_set_valuesv ##### -->
251 <!-- ##### FUNCTION gtk_list_store_remove ##### -->
261 <!-- ##### FUNCTION gtk_list_store_insert ##### -->
271 <!-- ##### FUNCTION gtk_list_store_insert_before ##### -->
281 <!-- ##### FUNCTION gtk_list_store_insert_after ##### -->
291 <!-- ##### FUNCTION gtk_list_store_insert_with_values ##### -->
302 <!-- ##### FUNCTION gtk_list_store_insert_with_valuesv ##### -->
315 <!-- ##### FUNCTION gtk_list_store_prepend ##### -->
324 <!-- ##### FUNCTION gtk_list_store_append ##### -->
333 <!-- ##### FUNCTION gtk_list_store_clear ##### -->
341 <!-- ##### FUNCTION gtk_list_store_iter_is_valid ##### -->
351 <!-- ##### FUNCTION gtk_list_store_reorder ##### -->
360 <!-- ##### FUNCTION gtk_list_store_swap ##### -->
370 <!-- ##### FUNCTION gtk_list_store_move_before ##### -->
380 <!-- ##### FUNCTION gtk_list_store_move_after ##### -->