Debian Codegraph @

clutter/deprecated/clutter-model.c

raw
1 /*
2 * Clutter.
3 *
4 * An OpenGL based 'interactive canvas' library.
5 *
6 * Authored By Matthew Allum <[email protected]>
7 * Neil Jagdish Patel <[email protected]>
8 * Emmanuele Bassi <[email protected]>
9 *
10 * Copyright (C) 2006 OpenedHand
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * NB: Inspiration for column storage taken from GtkListStore
26 */
27
28 /**
29 * SECTION:clutter-model
30 * @short_description: A generic model implementation
31 *
32 * #ClutterModel is a generic list model API which can be used to implement
33 * the model-view-controller architectural pattern in Clutter.
34 *
35 * The #ClutterModel class is a list model which can accept most GObject
36 * types as a column type.
37 *
38 * ## Creating a simple ClutterModel
39 *
40 * The example below shows how to create a simple list model.
41 *
42 * |[<!-- language="C" -->
43 * enum
44 * {
45 * COLUMN_INT,
46 * COLUMN_STRING,
47 *
48 * N_COLUMNS
49 * };
50 *
51 * {
52 * ClutterModel *model;
53 * gint i;
54 *
55 * model = clutter_list_model_new (N_COLUMNS,
56 * // column type, title
57 * G_TYPE_INT, "my integers",
58 * G_TYPE_STRING, "my strings");
59 * for (i = 0; i < 10; i++)
60 * {
61 * gchar *string = g_strdup_printf ("String %d", i);
62 * clutter_model_append (model,
63 * COLUMN_INT, i,
64 * COLUMN_STRING, string,
65 * -1);
66 * g_free (string);
67 * }
68 *
69 *
70 * }
71 * ]|
72 *
73 * ## Iterating through a ClutterModel
74 *
75 * Iterating through the model consists of retrieving a new #ClutterModelIter
76 * pointing to the starting row, and calling clutter_model_iter_next() or
77 * clutter_model_iter_prev() to move forward or backwards, repectively.
78 *
79 * A valid #ClutterModelIter represents the position between two rows in the
80 * model. For example, the "first" iterator represents the gap immediately
81 * before the first row, and the "last" iterator represents the gap immediately
82 * after the last row. In an empty sequence, the first and last iterators are
83 * the same.
84 *
85 * |[<!-- language="C" -->
86 * enum
87 * {
88 * COLUMN_INT,
89 * COLUMN_STRING.
90 *
91 * N_COLUMNS
92 * };
93 *
94 * {
95 * ClutterModel *model;
96 * ClutterModelIter *iter = NULL;
97 *
98 * // fill the model
99 * model = populate_model ();
100 *
101 * // get the iterator for the first row in the model
102 * iter = clutter_model_get_first_iter (model);
103 * while (!clutter_model_iter_is_last (iter))
104 * {
105 * print_row (iter);
106 *
107 * iter = clutter_model_iter_next (iter);
108 * }
109 *
110 * // Make sure to unref the iter
111 * g_object_unref (iter);
112 * }
113 * ]|
114 *
115 * #ClutterModel is an abstract class. Clutter provides a list model
116 * implementation called #ClutterListModel which has been optimised
117 * for insertion and look up in sorted lists.
118 *
119 * #ClutterModel is available since Clutter 0.6
120 *
121 * ## ClutterModel custom properties for ClutterScript
122 *
123 * #ClutterModel defines a custom property "columns" for #ClutterScript
124 * which allows defining the column names and types. It also defines a custom
125 * "rows" property which allows filling the #ClutterModel with some
126 * data.
127 *
128 * The definition below will create a #ClutterListModel with three
129 * columns: the first one with name "Name" and containing strings; the
130 * second one with name "Score" and containing integers; the third one with
131 * name "Icon" and containing #ClutterTextures. The model is filled
132 * with three rows. A row can be defined either with an array that holds
133 * all columns of a row, or an object that holds "column-name" :
134 * "column-value" pairs.
135 *
136 * |[
137 * {
138 * "type" : "ClutterListModel",
139 * "id" : "teams-model",
140 * "columns" : [
141 * [ "Name", "gchararray" ],
142 * [ "Score", "gint" ],
143 * [ "Icon", "ClutterTexture" ]
144 * ],
145 * "rows" : [
146 * [ "Team 1", 42, { "type" : "ClutterTexture", "filename" : "team1.png" } ],
147 * [ "Team 2", 23, "team2-icon-script-id" ],
148 * { "Name" : "Team 3", "Icon" : "team3-icon-script-id" }
149 * ]
150 * }
151 *
152 * Deprecated: 1.24: You should implement the #GListModel interface on your
153 * own storage data type instead.
154 */
155
156 #ifdef HAVE_CONFIG_H
157 #include "config.h"
158 #endif
159
160 #include <string.h>
161 #include <glib-object.h>
162 #include <gobject/gvaluecollector.h>
163
164 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
165
166 #include "clutter-model.h"
167 #include "clutter-model-private.h"
168
169 #include "clutter-marshal.h"
170 #include "clutter-private.h"
171 #include "clutter-debug.h"
172 #include "clutter-scriptable.h"
173 #include "clutter-script-private.h"
174
175 enum
176 {
177 PROP_0,
178
179 PROP_FILTER_SET
180 };
181
182 enum
183 {
184 ROW_ADDED,
185 ROW_REMOVED,
186 ROW_CHANGED,
187
188 SORT_CHANGED,
189 FILTER_CHANGED,
190
191 LAST_SIGNAL
192 };
193
194 static guint model_signals[LAST_SIGNAL] = { 0, };
195
196 struct _ClutterModelPrivate
197 {
198 GType *column_types;
199 gchar **column_names;
200
201 /* we use an integer here because we want to be able to use -1 as a
202 * guard value, to allow calling set_names() and set_types() from
203 * sub-classes of ClutterModel. see bug:
204 *
205 * http://bugzilla.openedhand.com/show_bug.cgi?id=2032
206 *
207 * for a reference.
208 */
209 gint n_columns;
210
211 ClutterModelFilterFunc filter_func;
212 gpointer filter_data;
213 GDestroyNotify filter_notify;
214
215 gint sort_column;
216 ClutterModelSortFunc sort_func;
217 gpointer sort_data;
218 GDestroyNotify sort_notify;
219 };
220
221 static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
222
223 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (ClutterModel, clutter_model, G_TYPE_OBJECT,
224 G_ADD_PRIVATE (ClutterModel)
225 G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
226 clutter_scriptable_iface_init))
227
228 static GType
229 clutter_model_real_get_column_type (ClutterModel *model,
230 guint column)
231 {
232 ClutterModelPrivate *priv = model->priv;
233
234 if (column >= clutter_model_get_n_columns (model))
235 return G_TYPE_INVALID;
236
237 return priv->column_types[column];
238 }
239
240 static const gchar *
241 clutter_model_real_get_column_name (ClutterModel *model,
242 guint column)
243 {
244 ClutterModelPrivate *priv = model->priv;
245
246 if (column >= clutter_model_get_n_columns (model))
247 return NULL;
248
249 if (priv->column_names && priv->column_names[column])
250 return priv->column_names[column];
251
252 return g_type_name (priv->column_types[column]);
253 }
254
255 static guint
256 clutter_model_real_get_n_columns (ClutterModel *model)
257 {
258 ClutterModelPrivate *priv = model->priv;
259
260 if (priv->n_columns < 0)
261 return 0;
262
263 return priv->n_columns;
264 }
265
266 static guint
267 clutter_model_real_get_n_rows (ClutterModel *model)
268 {
269 ClutterModelIter *iter;
270 guint row_count;
271
272 g_return_val_if_fail (CLUTTER_IS_MODEL (model), 0);
273
274 iter = clutter_model_get_first_iter (model);
275 if (iter == NULL)
276 return 0;
277
278 row_count = 0;
279 while (!clutter_model_iter_is_last (iter))
280 {
281 if (clutter_model_filter_iter (model, iter))
282 row_count += 1;
283
284 iter = clutter_model_iter_next (iter);
285 }
286
287 g_object_unref (iter);
288
289 return row_count;
290 }
291
292 static void
293 clutter_model_finalize (GObject *object)
294 {
295 ClutterModelPrivate *priv = CLUTTER_MODEL (object)->priv;
296 gint i;
297
298 if (priv->sort_notify)
299 priv->sort_notify (priv->sort_data);
300
301 if (priv->filter_notify)
302 priv->filter_notify (priv->filter_data);
303
304 g_free (priv->column_types);
305
306 if (priv->column_names != NULL)
307 {
308 /* the column_names vector might have holes in it, so we need
309 * to use the columns number to clear up everything
310 */
311 for (i = 0; i < priv->n_columns; i++)
312 g_free (priv->column_names[i]);
313
314 g_free (priv->column_names);
315 }
316
317 G_OBJECT_CLASS (clutter_model_parent_class)->finalize (object);
318 }
319
320 static void
321 clutter_model_get_property (GObject *gobject,
322 guint prop_id,
323 GValue *value,
324 GParamSpec *pspec)
325 {
326 ClutterModelPrivate *priv = CLUTTER_MODEL (gobject)->priv;
327
328 switch (prop_id)
329 {
330 case PROP_FILTER_SET:
331 g_value_set_boolean (value, priv->filter_func != NULL);
332 break;
333
334 default:
335 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
336 break;
337 }
338 }
339
340 static void
341 clutter_model_class_init (ClutterModelClass *klass)
342 {
343 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
344 GParamSpec *pspec;
345
346 gobject_class->get_property = clutter_model_get_property;
347 gobject_class->finalize = clutter_model_finalize;
348
349 klass->get_column_name = clutter_model_real_get_column_name;
350 klass->get_column_type = clutter_model_real_get_column_type;
351 klass->get_n_columns = clutter_model_real_get_n_columns;
352 klass->get_n_rows = clutter_model_real_get_n_rows;
353
354 /**
355 * ClutterModel:filter-set:
356 *
357 * Whether the #ClutterModel has a filter set
358 *
359 * This property is set to %TRUE if a filter function has been
360 * set using clutter_model_set_filter()
361 *
362 * Since: 1.0
363 *
364 * Deprecated: 1.24: Use #GListModel instead
365 */
366 pspec = g_param_spec_boolean ("filter-set",
367 "Filter Set",
368 "Whether the model has a filter",
369 FALSE,
370 CLUTTER_PARAM_READABLE);
371 g_object_class_install_property (gobject_class, PROP_FILTER_SET, pspec);
372
373 /**
374 * ClutterModel::row-added:
375 * @model: the #ClutterModel on which the signal is emitted
376 * @iter: a #ClutterModelIter pointing to the new row
377 *
378 * The ::row-added signal is emitted when a new row has been added.
379 * The data on the row has already been set when the ::row-added signal
380 * has been emitted.
381 *
382 * Since: 0.6
383 *
384 * Deprecated: 1.24: Use #GListModel instead
385 */
386 model_signals[ROW_ADDED] =
387 g_signal_new ("row-added",
388 G_TYPE_FROM_CLASS (gobject_class),
389 G_SIGNAL_RUN_LAST,
390 G_STRUCT_OFFSET (ClutterModelClass, row_added),
391 NULL, NULL,
392 _clutter_marshal_VOID__OBJECT,
393 G_TYPE_NONE, 1,
394 CLUTTER_TYPE_MODEL_ITER);
395 /**
396 * ClutterModel::row-removed:
397 * @model: the #ClutterModel on which the signal is emitted
398 * @iter: a #ClutterModelIter pointing to the removed row
399 *
400 * The ::row-removed signal is emitted when a row has been removed.
401 * The data on the row pointed by the passed iterator is still valid
402 * when the ::row-removed signal has been emitted.
403 *
404 * Since: 0.6
405 *
406 * Deprecated: 1.24: Use #GListModel instead
407 */
408 model_signals[ROW_REMOVED] =
409 g_signal_new ("row-removed",
410 G_TYPE_FROM_CLASS (gobject_class),
411 G_SIGNAL_RUN_LAST,
412 G_STRUCT_OFFSET (ClutterModelClass, row_removed),
413 NULL, NULL,
414 _clutter_marshal_VOID__OBJECT,
415 G_TYPE_NONE, 1,
416 CLUTTER_TYPE_MODEL_ITER);
417 /**
418 * ClutterModel::row-changed:
419 * @model: the #ClutterModel on which the signal is emitted
420 * @iter: a #ClutterModelIter pointing to the changed row
421 *
422 * The ::row-removed signal is emitted when a row has been changed.
423 * The data on the row has already been updated when the ::row-changed
424 * signal has been emitted.
425 *
426 * Since: 0.6
427 *
428 * Deprecated: 1.24: Use #GListModel instead
429 */
430 model_signals[ROW_CHANGED] =
431 g_signal_new ("row-changed",
432 G_TYPE_FROM_CLASS (gobject_class),
433 G_SIGNAL_RUN_LAST,
434 G_STRUCT_OFFSET (ClutterModelClass, row_changed),
435 NULL, NULL,
436 _clutter_marshal_VOID__OBJECT,
437 G_TYPE_NONE, 1,
438 CLUTTER_TYPE_MODEL_ITER);
439 /**
440 * ClutterModel::sort-changed:
441 * @model: the #ClutterModel on which the signal is emitted
442 *
443 * The ::sort-changed signal is emitted after the model has been sorted
444 *
445 * Since: 0.6
446 *
447 * Deprecated: 1.24: Use #GListModel instead
448 */
449 model_signals[SORT_CHANGED] =
450 g_signal_new ("sort-changed",
451 G_TYPE_FROM_CLASS (gobject_class),
452 G_SIGNAL_RUN_LAST,
453 G_STRUCT_OFFSET (ClutterModelClass, sort_changed),
454 NULL, NULL,
455 _clutter_marshal_VOID__VOID,
456 G_TYPE_NONE, 0);
457 /**
458 * ClutterModel::filter-changed:
459 * @model: the #ClutterModel on which the signal is emitted
460 *
461 * The ::filter-changed signal is emitted when a new filter has been applied
462 *
463 * Since: 0.6
464 *
465 * Deprecated: 1.24: Use #GListModel instead
466 */
467 model_signals[FILTER_CHANGED] =
468 g_signal_new ("filter-changed",
469 G_TYPE_FROM_CLASS (gobject_class),
470 G_SIGNAL_RUN_LAST,
471 G_STRUCT_OFFSET (ClutterModelClass, filter_changed),
472 NULL, NULL,
473 _clutter_marshal_VOID__VOID,
474 G_TYPE_NONE, 0);
475 }
476
477 static void
478 clutter_model_init (ClutterModel *self)
479 {
480 ClutterModelPrivate *priv;
481
482 self->priv = priv = clutter_model_get_instance_private (self);
483
484 priv->n_columns = -1;
485 priv->column_types = NULL;
486 priv->column_names = NULL;
487
488 priv->filter_func = NULL;
489 priv->filter_data = NULL;
490 priv->filter_notify = NULL;
491
492 priv->sort_column = -1;
493 priv->sort_func = NULL;
494 priv->sort_data = NULL;
495 priv->sort_notify = NULL;
496 }
497
498 /* XXX - is this whitelist really necessary? we accept every fundamental
499 * type.
500 */
501 gboolean
502 _clutter_model_check_type (GType gtype)
503 {
504 gint i = 0;
505 static const GType type_list[] =
506 {
507 G_TYPE_BOOLEAN,
508 G_TYPE_CHAR,
509 G_TYPE_UCHAR,
510 G_TYPE_INT,
511 G_TYPE_UINT,
512 G_TYPE_LONG,
513 G_TYPE_ULONG,
514 G_TYPE_INT64,
515 G_TYPE_UINT64,
516 G_TYPE_ENUM,
517 G_TYPE_FLAGS,
518 G_TYPE_FLOAT,
519 G_TYPE_DOUBLE,
520 G_TYPE_STRING,
521 G_TYPE_POINTER,
522 G_TYPE_BOXED,
523 G_TYPE_OBJECT,
524 G_TYPE_INVALID
525 };
526
527 if (! G_TYPE_IS_VALUE_TYPE (gtype))
528 return FALSE;
529
530 while (type_list[i] != G_TYPE_INVALID)
531 {
532 if (g_type_is_a (gtype, type_list[i]))
533 return TRUE;
534 i++;
535 }
536 return FALSE;
537 }
538
539
540 typedef struct {
541 gchar *name;
542 GType type;
543 } ColumnInfo;
544
545 static gboolean
546 clutter_model_parse_custom_node (ClutterScriptable *scriptable,
547 ClutterScript *script,
548 GValue *value,
549 const gchar *name,
550 JsonNode *node)
551 {
552 if (strcmp (name, "columns") == 0)
553 {
554 GSList *columns = NULL;
555 GList *elements, *l;
556
557 if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY)
558 return FALSE;
559
560 elements = json_array_get_elements (json_node_get_array (node));
561
562 for (l = elements; l != NULL; l = l->next)
563 {
564 JsonNode *child_node = l->data;
565 JsonArray *array = json_node_get_array (child_node);
566 ColumnInfo *cinfo;
567 const gchar *column_name;
568 const gchar *type_name;
569
570 if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY ||
571 json_array_get_length (array) != 2)
572 {
573 g_warning ("A column must be an array of "
574 "[\"column-name\", \"GType-name\"] pairs");
575 return FALSE;
576 }
577
578 column_name = json_array_get_string_element (array, 0);
579 type_name = json_array_get_string_element (array, 1);
580
581 cinfo = g_slice_new0 (ColumnInfo);
582 cinfo->name = g_strdup (column_name);
583 cinfo->type = clutter_script_get_type_from_name (script, type_name);
584
585 columns = g_slist_prepend (columns, cinfo);
586 }
587
588 g_list_free (elements);
589
590 g_value_init (value, G_TYPE_POINTER);
591 g_value_set_pointer (value, g_slist_reverse (columns));
592
593 return TRUE;
594 }
595 else if (strcmp (name, "rows") == 0)
596 {
597 GSList *rows = NULL;
598 GList *elements, *l;
599
600 if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY)
601 return FALSE;
602
603 /*
604 * at this point we have no information about the column types, so
605 * we just copy the json elements and resolve them in the
606 * set_custom_property method
607 */
608 elements = json_array_get_elements (json_node_get_array (node));
609 for (l = elements; l != NULL; l = l->next)
610 rows = g_slist_prepend (rows, json_node_copy (l->data));
611 g_list_free (elements);
612
613 g_value_init (value, G_TYPE_POINTER);
614 g_value_set_pointer (value, g_slist_reverse (rows));
615
616 return TRUE;
617 }
618 return FALSE;
619 }
620
621 static void
622 clutter_model_set_custom_property (ClutterScriptable *scriptable,
623 ClutterScript *script,
624 const gchar *name,
625 const GValue *value)
626 {
627 if (strcmp (name, "columns") == 0)
628 {
629 ClutterModel *model = CLUTTER_MODEL (scriptable);
630 GSList *columns, *l;
631 guint n_columns;
632 gint i;
633
634 columns = g_value_get_pointer (value);
635 n_columns = g_slist_length (columns);
636
637 _clutter_model_set_n_columns (model, n_columns, TRUE, TRUE);
638
639 for (i = 0, l = columns; l != NULL; l = l->next, i++)
640 {
641 ColumnInfo *cinfo = l->data;
642
643 _clutter_model_set_column_name (model, i, cinfo->name);
644 _clutter_model_set_column_type (model, i, cinfo->type);
645
646 g_free (cinfo->name);
647 g_slice_free (ColumnInfo, cinfo);
648 }
649
650 g_slist_free (columns);
651 }
652 else if (strcmp (name, "rows") == 0)
653 {
654 ClutterModel *model = CLUTTER_MODEL (scriptable);
655 GSList *rows, *l;
656 guint n_columns, row = 0;
657
658 rows = g_value_get_pointer (value);
659 n_columns = clutter_model_get_n_columns (model);
660
661 for (l = rows; l; l = l->next)
662 {
663 JsonNode *node = l->data;
664 guint *columns = NULL, i, n_values = 0;
665 GValue *values = NULL;
666
667 if (JSON_NODE_TYPE (node) == JSON_NODE_ARRAY)
668 {
669 JsonArray *array = json_node_get_array (node);
670
671 if (json_array_get_length (array) != n_columns)
672 {
673 g_warning ("Row %d contains the wrong count of columns",
674 g_slist_position (rows, l) + 1);
675 row += 1;
676 continue;
677 }
678
679 /* array more requires all columns */
680 n_values = n_columns;
681
682 columns = g_new (guint, n_values);
683 values = g_new0 (GValue, n_values);
684
685 for (i = 0; i < n_values; i++)
686 {
687 GType column_type;
688 const gchar *column_name;
689
690 column_type = clutter_model_get_column_type (model, i);
691 column_name = clutter_model_get_column_name (model, i);
692
693 columns[i] = i;
694 g_value_init (&values[i], column_type);
695
696 _clutter_script_parse_node (script, &values[i], column_name,
697 json_array_get_element (array, i),
698 NULL);
699 }
700 }
701 else if (JSON_NODE_TYPE (node) == JSON_NODE_OBJECT)
702 {
703 JsonObject *object = json_node_get_object (node);
704 GList *members, *m;
705 guint column = 0;
706
707 /* object mode does not require all columns */
708 n_values = json_object_get_size (object);
709
710 columns = g_new (guint, n_values);
711 values = g_new0 (GValue, n_values);
712
713 members = json_object_get_members (object);
714 for (m = members; m; m = m->next)
715 {
716 const gchar *mname = m->data;
717
718 for (i = 0; i < clutter_model_get_n_columns (model); i++)
719 {
720 const gchar *cname;
721
722 cname = clutter_model_get_column_name (model, i);
723 if (strcmp (mname, cname) == 0)
724 {
725 JsonNode *member;
726 GType col_type;
727 const gchar *col_name;
728
729 member = json_object_get_member (object, mname);
730
731 col_type = clutter_model_get_column_type (model, i);
732 col_name = clutter_model_get_column_name (model, i);
733
734 columns[column] = i;
735 g_value_init (&values[column], col_type);
736
737 _clutter_script_parse_node (script, &values[column],
738 col_name, member,
739 NULL);
740 break;
741 }
742 }
743
744 column += 1;
745 }
746 }
747 else
748 {
749 row += 1;
750 continue;
751 }
752
753 clutter_model_insertv (model, row, n_values, columns, values);
754
755 g_free (values);
756 g_free (columns);
757 json_node_free (node);
758
759 row += 1;
760 }
761 g_slist_free (rows);
762 }
763 }
764
765
766 static void
767 clutter_scriptable_iface_init (ClutterScriptableIface *iface)
768 {
769 iface->parse_custom_node = clutter_model_parse_custom_node;
770 iface->set_custom_property = clutter_model_set_custom_property;
771 }
772
773 /**
774 * clutter_model_resort:
775 * @model: a #ClutterModel
776 *
777 * Force a resort on the @model. This function should only be
778 * used by subclasses of #ClutterModel.
779 *
780 * Since: 0.6
781 *
782 * Deprecated: 1.24: Use #GListModel instead
783 */
784 void
785 clutter_model_resort (ClutterModel *model)
786 {
787 ClutterModelPrivate *priv;
788 ClutterModelClass *klass;
789
790 g_return_if_fail (CLUTTER_IS_MODEL (model));
791 priv = model->priv;
792
793 klass = CLUTTER_MODEL_GET_CLASS (model);
794
795 if (klass->resort)
796 klass->resort (model, priv->sort_func, priv->sort_data);
797 }
798
799 /**
800 * clutter_model_filter_row:
801 * @model: a #ClutterModel
802 * @row: the row to filter
803 *
804 * Checks whether @row should be filtered or not using the
805 * filtering function set on @model.
806 *
807 * This function should be used only by subclasses of #ClutterModel.
808 *
809 * Return value: %TRUE if the row should be displayed,
810 * %FALSE otherwise
811 *
812 * Since: 0.6
813 *
814 * Deprecated: 1.24: Use #GListModel instead
815 */
816 gboolean
817 clutter_model_filter_row (ClutterModel *model,
818 guint row)
819 {
820 ClutterModelPrivate *priv;
821 ClutterModelIter *iter;
822 gboolean res = TRUE;
823
824 g_return_val_if_fail (CLUTTER_IS_MODEL (model), TRUE);
825
826 priv = model->priv;
827
828 if (!priv->filter_func)
829 return TRUE;
830
831 iter = clutter_model_get_iter_at_row (model, row);
832 if (iter == NULL)
833 return FALSE;
834
835 res = priv->filter_func (model, iter, priv->filter_data);
836
837 g_object_unref (iter);
838
839 return res;
840 }
841
842 /**
843 * clutter_model_filter_iter:
844 * @model: a #ClutterModel
845 * @iter: the row to filter
846 *
847 * Checks whether the row pointer by @iter should be filtered or not using
848 * the filtering function set on @model.
849 *
850 * This function should be used only by subclasses of #ClutterModel.
851 *
852 * Return value: %TRUE if the row should be displayed,
853 * %FALSE otherwise
854 *
855 * Since: 0.6
856 *
857 * Deprecated: 1.24: Use #GListModel instead
858 */
859 gboolean
860 clutter_model_filter_iter (ClutterModel *model,
861 ClutterModelIter *iter)
862 {
863 ClutterModelPrivate *priv;
864
865 g_return_val_if_fail (CLUTTER_IS_MODEL (model), TRUE);
866 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), TRUE);
867
868 priv = model->priv;
869
870 if (!priv->filter_func)
871 return TRUE;
872
873 return priv->filter_func (model, iter, priv->filter_data);
874 }
875
876 /*< private >
877 * clutter_model_set_n_columns:
878 * @model: a #ClutterModel
879 * @n_columns: number of columns
880 * @set_types: set the columns type
881 * @set_names: set the columns name
882 *
883 * Sets the number of columns in @model to @n_columns. If @set_types
884 * or @set_names are %TRUE, initialises the columns type and name
885 * arrays as well.
886 *
887 * This function can only be called once.
888 *
889 * Deprecated: 1.24: Use #GListModel instead
890 */
891 void
892 _clutter_model_set_n_columns (ClutterModel *model,
893 gint n_columns,
894 gboolean set_types,
895 gboolean set_names)
896 {
897 ClutterModelPrivate *priv = model->priv;
898
899 if (priv->n_columns > 0 && priv->n_columns != n_columns)
900 return;
901
902 priv->n_columns = n_columns;
903
904 if (set_types && !priv->column_types)
905 priv->column_types = g_new0 (GType, n_columns);
906
907 if (set_names && !priv->column_names)
908 priv->column_names = g_new0 (gchar*, n_columns);
909 }
910
911 /*< private >
912 * _clutter_model_set_column_type:
913 * @model: a #ClutterModel
914 * @column: column index
915 * @gtype: type of the column
916 *
917 * Sets the type of @column inside @model
918 */
919 void
920 _clutter_model_set_column_type (ClutterModel *model,
921 gint column,
922 GType gtype)
923 {
924 ClutterModelPrivate *priv = model->priv;
925
926 priv->column_types[column] = gtype;
927 }
928
929 /*< private >
930 * _clutter_model_set_column_name:
931 * @model: a #ClutterModel
932 * @column: column index
933 * @name: name of the column, or %NULL
934 *
935 * Sets the name of @column inside @model
936 */
937 void
938 _clutter_model_set_column_name (ClutterModel *model,
939 gint column,
940 const gchar *name)
941 {
942 ClutterModelPrivate *priv = model->priv;
943
944 priv->column_names[column] = g_strdup (name);
945 }
946
947 /**
948 * clutter_model_set_types:
949 * @model: a #ClutterModel
950 * @n_columns: number of columns for the model
951 * @types: (array length=n_columns): an array of #GType types
952 *
953 * Sets the types of the columns inside a #ClutterModel.
954 *
955 * This function is meant primarily for #GObjects that inherit from
956 * #ClutterModel, and should only be used when contructing a #ClutterModel.
957 * It will not work after the initial creation of the #ClutterModel.
958 *
959 * Since: 0.6
960 *
961 * Deprecated: 1.24: Use #GListModel instead
962 */
963 void
964 clutter_model_set_types (ClutterModel *model,
965 guint n_columns,
966 GType *types)
967 {
968 ClutterModelPrivate *priv;
969 gint i;
970
971 g_return_if_fail (CLUTTER_IS_MODEL (model));
972 g_return_if_fail (n_columns > 0);
973
974 priv = model->priv;
975
976 g_return_if_fail (priv->n_columns < 0 || priv->n_columns == n_columns);
977 g_return_if_fail (priv->column_types == NULL);
978
979 _clutter_model_set_n_columns (model, n_columns, TRUE, FALSE);
980
981 for (i = 0; i < n_columns; i++)
982 {
983 if (!_clutter_model_check_type (types[i]))
984 {
985 g_warning ("%s: Invalid type %s\n", G_STRLOC, g_type_name (types[i]));
986 return;
987 }
988
989 _clutter_model_set_column_type (model, i, types[i]);
990 }
991 }
992
993 /**
994 * clutter_model_set_names:
995 * @model: a #ClutterModel
996 * @n_columns: the number of column names
997 * @names: (array length=n_columns): an array of strings
998 *
999 * Assigns a name to the columns of a #ClutterModel.
1000 *
1001 * This function is meant primarily for #GObjects that inherit from
1002 * #ClutterModel, and should only be used when contructing a #ClutterModel.
1003 * It will not work after the initial creation of the #ClutterModel.
1004 *
1005 * Since: 0.6
1006 *
1007 * Deprecated: 1.24: Use #GListModel instead
1008 */
1009 void
1010 clutter_model_set_names (ClutterModel *model,
1011 guint n_columns,
1012 const gchar * const names[])
1013 {
1014 ClutterModelPrivate *priv;
1015 gint i;
1016
1017 g_return_if_fail (CLUTTER_IS_MODEL (model));
1018 g_return_if_fail (n_columns > 0);
1019
1020 priv = model->priv;
1021
1022 g_return_if_fail (priv->n_columns < 0 || priv->n_columns == n_columns);
1023 g_return_if_fail (priv->column_names == NULL);
1024
1025 _clutter_model_set_n_columns (model, n_columns, FALSE, TRUE);
1026
1027 for (i = 0; i < n_columns; i++)
1028 _clutter_model_set_column_name (model, i, names[i]);
1029 }
1030
1031 /**
1032 * clutter_model_get_n_columns:
1033 * @model: a #ClutterModel
1034 *
1035 * Retrieves the number of columns inside @model.
1036 *
1037 * Return value: the number of columns
1038 *
1039 * Since: 0.6
1040 *
1041 * Deprecated: 1.24: Use #GListModel instead
1042 */
1043 guint
1044 clutter_model_get_n_columns (ClutterModel *model)
1045 {
1046 g_return_val_if_fail (CLUTTER_IS_MODEL (model), 0);
1047
1048 return CLUTTER_MODEL_GET_CLASS (model)->get_n_columns (model);
1049 }
1050
1051 /**
1052 * clutter_model_appendv:
1053 * @model: a #ClutterModel
1054 * @n_columns: the number of columns and values
1055 * @columns: (array length=n_columns): a vector with the columns to set
1056 * @values: (array length=n_columns): a vector with the values
1057 *
1058 * Creates and appends a new row to the #ClutterModel, setting the row
1059 * values for the given @columns upon creation.
1060 *
1061 * Since: 0.6
1062 *
1063 * Deprecated: 1.24: Use #GListModel instead
1064 */
1065 void
1066 clutter_model_appendv (ClutterModel *model,
1067 guint n_columns,
1068 guint *columns,
1069 GValue *values)
1070 {
1071 ClutterModelPrivate *priv;
1072 ClutterModelIter *iter;
1073 gint i;
1074 gboolean resort = FALSE;
1075
1076 g_return_if_fail (CLUTTER_IS_MODEL (model));
1077 g_return_if_fail (n_columns <= clutter_model_get_n_columns (model));
1078 g_return_if_fail (columns != NULL);
1079 g_return_if_fail (values != NULL);
1080
1081 priv = model->priv;
1082
1083 iter = CLUTTER_MODEL_GET_CLASS (model)->insert_row (model, -1);
1084 g_assert (CLUTTER_IS_MODEL_ITER (iter));
1085
1086 for (i = 0; i < n_columns; i++)
1087 {
1088 if (priv->sort_column == columns[i])
1089 resort = TRUE;
1090
1091 clutter_model_iter_set_value (iter, columns[i], &values[i]);
1092 }
1093
1094 g_signal_emit (model, model_signals[ROW_ADDED], 0, iter);
1095
1096 if (resort)
1097 clutter_model_resort (model);
1098
1099 g_object_unref (iter);
1100 }
1101
1102 /* forward declaration */
1103 static void clutter_model_iter_set_internal_valist (ClutterModelIter *iter,
1104 va_list args);
1105
1106 /**
1107 * clutter_model_append:
1108 * @model: a #ClutterModel
1109 * @...: pairs of column number and value, terminated with -1
1110 *
1111 * Creates and appends a new row to the #ClutterModel, setting the
1112 * row values upon creation. For example, to append a new row where
1113 * column 0 is type %G_TYPE_INT and column 1 is of type %G_TYPE_STRING:
1114 *
1115 * <informalexample><programlisting>
1116 * ClutterModel *model;
1117 * model = clutter_model_default_new (2,
1118 * G_TYPE_INT, "Score",
1119 * G_TYPE_STRING, "Team");
1120 * clutter_model_append (model, 0, 42, 1, "Team #1", -1);
1121 * </programlisting></informalexample>
1122 *
1123 * Since: 0.6
1124 *
1125 * Deprecated: 1.24: Use #GListModel instead
1126 */
1127 void
1128 clutter_model_append (ClutterModel *model,
1129 ...)
1130 {
1131 ClutterModelIter *iter;
1132 va_list args;
1133
1134 g_return_if_fail (CLUTTER_IS_MODEL (model));
1135
1136 iter = CLUTTER_MODEL_GET_CLASS (model)->insert_row (model, -1);
1137 g_assert (CLUTTER_IS_MODEL_ITER (iter));
1138
1139 /* do not emit the ::row-changed signal */
1140 va_start (args, model);
1141 clutter_model_iter_set_internal_valist (iter, args);
1142 va_end (args);
1143
1144 g_signal_emit (model, model_signals[ROW_ADDED], 0, iter);
1145
1146 g_object_unref (iter);
1147 }
1148
1149 /**
1150 * clutter_model_prependv:
1151 * @model: a #ClutterModel
1152 * @n_columns: the number of columns and values to set
1153 * @columns: (array length=n_columns): a vector containing the columns to set
1154 * @values: (array length=n_columns): a vector containing the values for the cells
1155 *
1156 * Creates and prepends a new row to the #ClutterModel, setting the row
1157 * values for the given @columns upon creation.
1158 *
1159 * Since: 0.6
1160 *
1161 * Deprecated: 1.24: Use #GListModel instead
1162 */
1163 void
1164 clutter_model_prependv (ClutterModel *model,
1165 guint n_columns,
1166 guint *columns,
1167 GValue *values)
1168 {
1169 ClutterModelPrivate *priv;
1170 ClutterModelIter *iter;
1171 gint i;
1172 gboolean resort = FALSE;
1173
1174 g_return_if_fail (CLUTTER_IS_MODEL (model));
1175 g_return_if_fail (n_columns <= clutter_model_get_n_columns (model));
1176 g_return_if_fail (columns != NULL);
1177 g_return_if_fail (values != NULL);
1178
1179 priv = model->priv;
1180
1181 iter = CLUTTER_MODEL_GET_CLASS (model)->insert_row (model, 0);
1182 g_assert (CLUTTER_IS_MODEL_ITER (iter));
1183
1184 for (i = 0; i < n_columns; i++)
1185 {
1186 if (priv->sort_column == columns[i])
1187 resort = TRUE;
1188
1189 clutter_model_iter_set_value (iter, columns[i], &values[i]);
1190 }
1191
1192 g_signal_emit (model, model_signals[ROW_ADDED], 0, iter);
1193
1194 if (resort)
1195 clutter_model_resort (model);
1196
1197 g_object_unref (iter);
1198 }
1199
1200 /**
1201 * clutter_model_prepend:
1202 * @model: a #ClutterModel
1203 * @...: pairs of column number and value, terminated with -1
1204 *
1205 * Creates and prepends a new row to the #ClutterModel, setting the row
1206 * values upon creation. For example, to prepend a new row where column 0
1207 * is type %G_TYPE_INT and column 1 is of type %G_TYPE_STRING:
1208 *
1209 * <informalexample><programlisting>
1210 * ClutterModel *model;
1211 * model = clutter_model_default_new (2,
1212 * G_TYPE_INT, "Score",
1213 * G_TYPE_STRING, "Team");
1214 * clutter_model_prepend (model, 0, 42, 1, "Team #1", -1);
1215 * </programlisting></informalexample>
1216 *
1217 * Since: 0.6
1218 *
1219 * Deprecated: 1.24: Use #GListModel instead
1220 */
1221 void
1222 clutter_model_prepend (ClutterModel *model,
1223 ...)
1224 {
1225 ClutterModelIter *iter;
1226 va_list args;
1227
1228 g_return_if_fail (CLUTTER_IS_MODEL (model));
1229
1230 iter = CLUTTER_MODEL_GET_CLASS (model)->insert_row (model, 0);
1231 g_assert (CLUTTER_IS_MODEL_ITER (iter));
1232
1233 va_start (args, model);
1234 clutter_model_iter_set_internal_valist (iter, args);
1235 va_end (args);
1236
1237 g_signal_emit (model, model_signals[ROW_ADDED], 0, iter);
1238
1239 g_object_unref (iter);
1240 }
1241
1242
1243 /**
1244 * clutter_model_insert:
1245 * @model: a #ClutterModel
1246 * @row: the position to insert the new row
1247 * @...: pairs of column number and value, terminated with -1
1248 *
1249 * Inserts a new row to the #ClutterModel at @row, setting the row
1250 * values upon creation. For example, to insert a new row at index 100,
1251 * where column 0 is type %G_TYPE_INT and column 1 is of type
1252 * %G_TYPE_STRING:
1253 *
1254 * <informalexample><programlisting>
1255 * ClutterModel *model;
1256 * model = clutter_model_default_new (2,
1257 * G_TYPE_INT, "Score",
1258 * G_TYPE_STRING, "Team");
1259 * clutter_model_insert (model, 3, 0, 42, 1, "Team #1", -1);
1260 * </programlisting></informalexample>
1261 *
1262 * Since: 0.6
1263 *
1264 * Deprecated: 1.24: Use #GListModel instead
1265 */
1266 void
1267 clutter_model_insert (ClutterModel *model,
1268 guint row,
1269 ...)
1270 {
1271 ClutterModelIter *iter;
1272 va_list args;
1273
1274 g_return_if_fail (CLUTTER_IS_MODEL (model));
1275
1276 iter = CLUTTER_MODEL_GET_CLASS (model)->insert_row (model, row);
1277 g_assert (CLUTTER_IS_MODEL_ITER (iter));
1278
1279 /* set_valist() will call clutter_model_resort() if one of the
1280 * passed columns matches the model sorting column index
1281 */
1282 va_start (args, row);
1283 clutter_model_iter_set_internal_valist (iter, args);
1284 va_end (args);
1285
1286 g_signal_emit (model, model_signals[ROW_ADDED], 0, iter);
1287
1288 g_object_unref (iter);
1289 }
1290
1291 /**
1292 * clutter_model_insertv:
1293 * @model: a #ClutterModel
1294 * @row: row index
1295 * @n_columns: the number of columns and values to set
1296 * @columns: (array length=n_columns): a vector containing the columns to set
1297 * @values: (array length=n_columns): a vector containing the values for the cells
1298 *
1299 * Inserts data at @row into the #ClutterModel, setting the row
1300 * values for the given @columns upon creation.
1301 *
1302 * Since: 0.6
1303 *
1304 * Deprecated: 1.24: Use #GListModel instead
1305 */
1306 void
1307 clutter_model_insertv (ClutterModel *model,
1308 guint row,
1309 guint n_columns,
1310 guint *columns,
1311 GValue *values)
1312 {
1313 ClutterModelPrivate *priv;
1314 ClutterModelIter *iter;
1315 gint i;
1316 gboolean resort = FALSE;
1317
1318 g_return_if_fail (CLUTTER_IS_MODEL (model));
1319 g_return_if_fail (n_columns <= clutter_model_get_n_columns (model));
1320 g_return_if_fail (columns != NULL);
1321 g_return_if_fail (values != NULL);
1322
1323 priv = model->priv;
1324
1325 iter = CLUTTER_MODEL_GET_CLASS (model)->insert_row (model, row);
1326 g_assert (CLUTTER_IS_MODEL_ITER (iter));
1327
1328 for (i = 0; i < n_columns; i++)
1329 {
1330 if (priv->sort_column == columns[i])
1331 resort = TRUE;
1332
1333 clutter_model_iter_set_value (iter, columns[i], &values[i]);
1334 }
1335
1336 g_signal_emit (model, model_signals[ROW_ADDED], 0, iter);
1337
1338 if (resort)
1339 clutter_model_resort (model);
1340
1341 g_object_unref (iter);
1342 }
1343
1344 /**
1345 * clutter_model_insert_value:
1346 * @model: a #ClutterModel
1347 * @row: position of the row to modify
1348 * @column: column to modify
1349 * @value: new value for the cell
1350 *
1351 * Sets the data in the cell specified by @iter and @column. The type of
1352 * @value must be convertable to the type of the column. If the row does
1353 * not exist then it is created.
1354 *
1355 * Since: 0.6
1356 *
1357 * Deprecated: 1.24: Use #GListModel instead
1358 */
1359 void
1360 clutter_model_insert_value (ClutterModel *model,
1361 guint row,
1362 guint column,
1363 const GValue *value)
1364 {
1365 ClutterModelPrivate *priv;
1366 ClutterModelClass *klass;
1367 ClutterModelIter *iter;
1368 gboolean added = FALSE;
1369
1370 g_return_if_fail (CLUTTER_IS_MODEL (model));
1371
1372 priv = model->priv;
1373 klass = CLUTTER_MODEL_GET_CLASS (model);
1374
1375 iter = klass->get_iter_at_row (model, row);
1376 if (!iter)
1377 {
1378 iter = klass->insert_row (model, row);
1379 added = TRUE;
1380 }
1381
1382 g_assert (CLUTTER_IS_MODEL_ITER (iter));
1383
1384 clutter_model_iter_set_value (iter, column, value);
1385
1386 if (added)
1387 g_signal_emit (model, model_signals[ROW_ADDED], 0, iter);
1388
1389 if (priv->sort_column == column)
1390 clutter_model_resort (model);
1391
1392 g_object_unref (iter);
1393 }
1394
1395 /**
1396 * clutter_model_remove:
1397 * @model: a #ClutterModel
1398 * @row: position of row to remove
1399 *
1400 * Removes the row at the given position from the model.
1401 *
1402 * Since: 0.6
1403 *
1404 * Deprecated: 1.24: Use #GListModel instead
1405 */
1406 void
1407 clutter_model_remove (ClutterModel *model,
1408 guint row)
1409 {
1410 ClutterModelClass *klass;
1411
1412 g_return_if_fail (CLUTTER_IS_MODEL (model));
1413
1414 klass = CLUTTER_MODEL_GET_CLASS (model);
1415 if (klass->remove_row)
1416 klass->remove_row (model, row);
1417 }
1418
1419 /**
1420 * clutter_model_get_column_name:
1421 * @model: #ClutterModel
1422 * @column: the column number
1423 *
1424 * Retrieves the name of the @column
1425 *
1426 * Return value: the name of the column. The model holds the returned
1427 * string, and it should not be modified or freed
1428 *
1429 * Since: 0.6
1430 *
1431 * Deprecated: 1.24: Use #GListModel instead
1432 */
1433 const gchar *
1434 clutter_model_get_column_name (ClutterModel *model,
1435 guint column)
1436 {
1437 ClutterModelClass *klass;
1438
1439 g_return_val_if_fail (CLUTTER_IS_MODEL (model), NULL);
1440
1441 if (column >= clutter_model_get_n_columns (model))
1442 {
1443 g_warning ("%s: Invalid column id value %d\n", G_STRLOC, column);
1444 return NULL;
1445 }
1446
1447 klass = CLUTTER_MODEL_GET_CLASS (model);
1448 if (klass->get_column_name)
1449 return klass->get_column_name (model, column);
1450
1451 return NULL;
1452 }
1453
1454 /**
1455 * clutter_model_get_column_type:
1456 * @model: #ClutterModel
1457 * @column: the column number
1458 *
1459 * Retrieves the type of the @column.
1460 *
1461 * Return value: the type of the column.
1462 *
1463 * Since: 0.6
1464 *
1465 * Deprecated: 1.24: Use #GListModel instead
1466 */
1467 GType
1468 clutter_model_get_column_type (ClutterModel *model,
1469 guint column)
1470 {
1471 ClutterModelClass *klass;
1472
1473 g_return_val_if_fail (CLUTTER_IS_MODEL (model), G_TYPE_INVALID);
1474
1475 if (column >= clutter_model_get_n_columns (model))
1476 {
1477 g_warning ("%s: Invalid column id value %d\n", G_STRLOC, column);
1478 return G_TYPE_INVALID;
1479 }
1480
1481 klass = CLUTTER_MODEL_GET_CLASS (model);
1482 if (klass->get_column_type)
1483 return klass->get_column_type (model, column);
1484
1485 return G_TYPE_INVALID;
1486 }
1487
1488 /**
1489 * clutter_model_get_iter_at_row:
1490 * @model: a #ClutterModel
1491 * @row: position of the row to retrieve
1492 *
1493 * Retrieves a #ClutterModelIter representing the row at the given index.
1494 *
1495 * If a filter function has been set using clutter_model_set_filter()
1496 * then the @model implementation will return the first non filtered
1497 * row.
1498 *
1499 * Return value: (transfer full): A new #ClutterModelIter, or %NULL if @row was
1500 * out of bounds. When done using the iterator object, call g_object_unref()
1501 * to deallocate its resources
1502 *
1503 * Since: 0.6
1504 *
1505 * Deprecated: 1.24: Use #GListModel instead
1506 */
1507 ClutterModelIter *
1508 clutter_model_get_iter_at_row (ClutterModel *model,
1509 guint row)
1510 {
1511 ClutterModelClass *klass;
1512
1513 g_return_val_if_fail (CLUTTER_IS_MODEL (model), NULL);
1514
1515 klass = CLUTTER_MODEL_GET_CLASS (model);
1516 if (klass->get_iter_at_row)
1517 return klass->get_iter_at_row (model, row);
1518
1519 return NULL;
1520 }
1521
1522
1523 /**
1524 * clutter_model_get_first_iter:
1525 * @model: a #ClutterModel
1526 *
1527 * Retrieves a #ClutterModelIter representing the first non-filtered
1528 * row in @model.
1529 *
1530 * Return value: (transfer full): A new #ClutterModelIter.
1531 * Call g_object_unref() when done using it
1532 *
1533 * Since: 0.6
1534 *
1535 * Deprecated: 1.24: Use #GListModel instead
1536 */
1537 ClutterModelIter *
1538 clutter_model_get_first_iter (ClutterModel *model)
1539 {
1540 ClutterModelIter *retval;
1541
1542 g_return_val_if_fail (CLUTTER_IS_MODEL (model), NULL);
1543
1544 retval = clutter_model_get_iter_at_row (model, 0);
1545 if (retval != NULL)
1546 {
1547 g_assert (clutter_model_filter_iter (model, retval) != FALSE);
1548 g_assert (clutter_model_iter_get_row (retval) == 0);
1549 }
1550
1551 return retval;
1552 }
1553
1554 /**
1555 * clutter_model_get_last_iter:
1556 * @model: a #ClutterModel
1557 *
1558 * Retrieves a #ClutterModelIter representing the last non-filtered
1559 * row in @model.
1560 *
1561 * Return value: (transfer full): A new #ClutterModelIter.
1562 * Call g_object_unref() when done using it
1563 *
1564 * Since: 0.6
1565 *
1566 * Deprecated: 1.24: Use #GListModel instead
1567 */
1568 ClutterModelIter *
1569 clutter_model_get_last_iter (ClutterModel *model)
1570 {
1571 ClutterModelIter *retval;
1572 guint length;
1573
1574 g_return_val_if_fail (CLUTTER_IS_MODEL (model), NULL);
1575
1576 length = clutter_model_get_n_rows (model);
1577 retval = clutter_model_get_iter_at_row (model, length - 1);
1578 if (retval != NULL)
1579 g_assert (clutter_model_filter_iter (model, retval) != FALSE);
1580
1581 return retval;
1582 }
1583
1584 /**
1585 * clutter_model_get_n_rows:
1586 * @model: a #ClutterModel
1587 *
1588 * Retrieves the number of rows inside @model, eventually taking
1589 * into account any filtering function set using clutter_model_set_filter().
1590 *
1591 * Return value: The length of the @model. If there is a filter set, then
1592 * the length of the filtered @model is returned.
1593 *
1594 * Since: 0.6
1595 *
1596 * Deprecated: 1.24: Use #GListModel instead
1597 */
1598 guint
1599 clutter_model_get_n_rows (ClutterModel *model)
1600 {
1601 g_return_val_if_fail (CLUTTER_IS_MODEL (model), 0);
1602
1603 return CLUTTER_MODEL_GET_CLASS (model)->get_n_rows (model);
1604 }
1605
1606 /**
1607 * clutter_model_set_sorting_column:
1608 * @model: a #ClutterModel
1609 * @column: the column of the @model to sort, or -1
1610 *
1611 * Sets the model to sort by @column. If @column is a negative value
1612 * the sorting column will be unset.
1613 *
1614 * Since: 0.6
1615 *
1616 * Deprecated: 1.24: Use #GListModel instead
1617 */
1618 void
1619 clutter_model_set_sorting_column (ClutterModel *model,
1620 gint column)
1621 {
1622 ClutterModelPrivate *priv;
1623
1624 g_return_if_fail (CLUTTER_IS_MODEL (model));
1625 priv = model->priv;
1626
1627 /* The extra comparison for >= 0 is because column gets promoted to
1628 unsigned in the second comparison */
1629 if (column >= 0 && column >= clutter_model_get_n_columns (model))
1630 {
1631 g_warning ("%s: Invalid column id value %d\n", G_STRLOC, column);
1632 return;
1633 }
1634
1635 priv->sort_column = column;
1636
1637 if (priv->sort_column >= 0)
1638 clutter_model_resort (model);
1639
1640 g_signal_emit (model, model_signals[SORT_CHANGED], 0);
1641 }
1642
1643 /**
1644 * clutter_model_get_sorting_column:
1645 * @model: a #ClutterModel
1646 *
1647 * Retrieves the number of column used for sorting the @model.
1648 *
1649 * Return value: a column number, or -1 if the model is not sorted
1650 *
1651 * Since: 0.6
1652 *
1653 * Deprecated: 1.24: Use #GListModel instead
1654 */
1655 gint
1656 clutter_model_get_sorting_column (ClutterModel *model)
1657 {
1658 g_return_val_if_fail (CLUTTER_IS_MODEL (model), -1);
1659
1660 return model->priv->sort_column;
1661 }
1662
1663 /**
1664 * clutter_model_foreach:
1665 * @model: a #ClutterModel
1666 * @func: (scope call): a #ClutterModelForeachFunc
1667 * @user_data: user data to pass to @func
1668 *
1669 * Calls @func for each row in the model.
1670 *
1671 * Since: 0.6
1672 *
1673 * Deprecated: 1.24: Use #GListModel instead
1674 */
1675 void
1676 clutter_model_foreach (ClutterModel *model,
1677 ClutterModelForeachFunc func,
1678 gpointer user_data)
1679 {
1680 ClutterModelIter *iter;
1681
1682 g_return_if_fail (CLUTTER_IS_MODEL (model));
1683
1684 iter = clutter_model_get_first_iter (model);
1685 if (!iter)
1686 return;
1687
1688 while (!clutter_model_iter_is_last (iter))
1689 {
1690 if (clutter_model_filter_iter (model, iter))
1691 {
1692 if (!func (model, iter, user_data))
1693 break;
1694 }
1695
1696 iter = clutter_model_iter_next (iter);
1697 }
1698
1699 g_object_unref (iter);
1700 }
1701
1702 /**
1703 * clutter_model_set_sort:
1704 * @model: a #ClutterModel
1705 * @column: the column to sort on
1706 * @func: (allow-none): a #ClutterModelSortFunc, or #NULL
1707 * @user_data: user data to pass to @func, or #NULL
1708 * @notify: destroy notifier of @user_data, or #NULL
1709 *
1710 * Sorts @model using the given sorting function.
1711 *
1712 * Since: 0.6
1713 *
1714 * Deprecated: 1.24: Use #GListModel instead
1715 */
1716 void
1717 clutter_model_set_sort (ClutterModel *model,
1718 gint column,
1719 ClutterModelSortFunc func,
1720 gpointer user_data,
1721 GDestroyNotify notify)
1722 {
1723 ClutterModelPrivate *priv;
1724
1725 g_return_if_fail (CLUTTER_IS_MODEL (model));
1726 g_return_if_fail ((func != NULL && column >= 0) ||
1727 (func == NULL && column == -1));
1728
1729 priv = model->priv;
1730
1731 if (priv->sort_notify)
1732 priv->sort_notify (priv->sort_data);
1733
1734 priv->sort_func = func;
1735 priv->sort_data = user_data;
1736 priv->sort_notify = notify;
1737
1738 /* This takes care of calling _model_sort & emitting the signal*/
1739 clutter_model_set_sorting_column (model, column);
1740 }
1741
1742 /**
1743 * clutter_model_set_filter:
1744 * @model: a #ClutterModel
1745 * @func: (allow-none): a #ClutterModelFilterFunc, or #NULL
1746 * @user_data: user data to pass to @func, or #NULL
1747 * @notify: destroy notifier of @user_data, or #NULL
1748 *
1749 * Filters the @model using the given filtering function.
1750 *
1751 * Since: 0.6
1752 *
1753 * Deprecated: 1.24: Use #GListModel instead
1754 */
1755 void
1756 clutter_model_set_filter (ClutterModel *model,
1757 ClutterModelFilterFunc func,
1758 gpointer user_data,
1759 GDestroyNotify notify)
1760 {
1761 ClutterModelPrivate *priv;
1762
1763 g_return_if_fail (CLUTTER_IS_MODEL (model));
1764 priv = model->priv;
1765
1766 if (priv->filter_notify)
1767 priv->filter_notify (priv->filter_data);
1768
1769 priv->filter_func = func;
1770 priv->filter_data = user_data;
1771 priv->filter_notify = notify;
1772
1773 g_signal_emit (model, model_signals[FILTER_CHANGED], 0);
1774 g_object_notify (G_OBJECT (model), "filter-set");
1775 }
1776
1777 /**
1778 * clutter_model_get_filter_set:
1779 * @model: a #ClutterModel
1780 *
1781 * Returns whether the @model has a filter in place, set
1782 * using clutter_model_set_filter()
1783 *
1784 * Return value: %TRUE if a filter is set
1785 *
1786 * Since: 1.0
1787 *
1788 * Deprecated: 1.24: Use #GListModel instead
1789 */
1790 gboolean
1791 clutter_model_get_filter_set (ClutterModel *model)
1792 {
1793 g_return_val_if_fail (CLUTTER_IS_MODEL (model), FALSE);
1794
1795 return model->priv->filter_func != NULL;
1796 }
1797
1798 /*
1799 * ClutterModelIter Object
1800 */
1801
1802 /**
1803 * SECTION:clutter-model-iter
1804 * @short_description: Iterates through a model
1805 *
1806 * #ClutterModelIter is an object used for iterating through all the rows
1807 * of a #ClutterModel. It allows setting and getting values on the row
1808 * which is currently pointing at.
1809 *
1810 * A #ClutterModelIter represents a position between two elements
1811 * of the sequence. For example, the iterator returned by
1812 * clutter_model_get_first_iter() represents the gap immediately before
1813 * the first row of the #ClutterModel, and the iterator returned by
1814 * clutter_model_get_last_iter() represents the gap immediately after the
1815 * last row.
1816 *
1817 * A #ClutterModelIter can only be created by a #ClutterModel implementation
1818 * and it is valid as long as the model does not change.
1819 *
1820 * #ClutterModelIter is available since Clutter 0.6
1821 *
1822 * Deprecated: 1.24: Use #GListModel instead
1823 */
1824
1825 struct _ClutterModelIterPrivate
1826 {
1827 ClutterModel *model;
1828
1829 gint row;
1830 };
1831
1832 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterModelIter, clutter_model_iter, G_TYPE_OBJECT)
1833
1834 enum
1835 {
1836 ITER_PROP_0,
1837
1838 ITER_PROP_MODEL,
1839 ITER_PROP_ROW
1840 };
1841
1842 static ClutterModel *
1843 clutter_model_iter_real_get_model (ClutterModelIter *iter)
1844 {
1845 return iter->priv->model;
1846 }
1847
1848 static guint
1849 clutter_model_iter_real_get_row (ClutterModelIter *iter)
1850 {
1851 return iter->priv->row;
1852 }
1853
1854 /* private function */
1855 void
1856 _clutter_model_iter_set_row (ClutterModelIter *iter,
1857 guint row)
1858 {
1859 iter->priv->row = row;
1860 }
1861
1862 static void
1863 clutter_model_iter_get_value_unimplemented (ClutterModelIter *iter,
1864 guint column,
1865 GValue *value)
1866 {
1867 g_warning ("%s: Iterator of type '%s' does not implement the "
1868 "ClutterModelIter::get_value() virtual function",
1869 G_STRLOC,
1870 g_type_name (G_OBJECT_TYPE (iter)));
1871 }
1872
1873 static void
1874 clutter_model_iter_set_value_unimplemented (ClutterModelIter *iter,
1875 guint column,
1876 const GValue *value)
1877 {
1878 g_warning ("%s: Iterator of type '%s' does not implement the "
1879 "ClutterModelIter::set_value() virtual function",
1880 G_STRLOC,
1881 g_type_name (G_OBJECT_TYPE (iter)));
1882 }
1883
1884 static gboolean
1885 clutter_model_iter_is_first_unimplemented (ClutterModelIter *iter)
1886 {
1887 g_warning ("%s: Iterator of type '%s' does not implement the "
1888 "ClutterModelIter::is_first() virtual function",
1889 G_STRLOC,
1890 g_type_name (G_OBJECT_TYPE (iter)));
1891 return FALSE;
1892 }
1893
1894 static gboolean
1895 clutter_model_iter_is_last_unimplemented (ClutterModelIter *iter)
1896 {
1897 g_warning ("%s: Iterator of type '%s' does not implement the "
1898 "ClutterModelIter::is_last() virtual function",
1899 G_STRLOC,
1900 g_type_name (G_OBJECT_TYPE (iter)));
1901 return FALSE;
1902 }
1903
1904 static ClutterModelIter *
1905 clutter_model_iter_next_unimplemented (ClutterModelIter *iter)
1906 {
1907 g_warning ("%s: Iterator of type '%s' does not implement the "
1908 "ClutterModelIter::next() virtual function",
1909 G_STRLOC,
1910 g_type_name (G_OBJECT_TYPE (iter)));
1911 return NULL;
1912 }
1913
1914 static ClutterModelIter *
1915 clutter_model_iter_prev_unimplemented (ClutterModelIter *iter)
1916 {
1917 g_warning ("%s: Iterator of type '%s' does not implement the "
1918 "ClutterModelIter::prev() virtual function",
1919 G_STRLOC,
1920 g_type_name (G_OBJECT_TYPE (iter)));
1921 return NULL;
1922 }
1923
1924 static ClutterModelIter *
1925 clutter_model_iter_copy_unimplemented (ClutterModelIter *iter)
1926 {
1927 g_warning ("%s: Iterator of type '%s' does not implement the "
1928 "ClutterModelIter::copy() virtual function",
1929 G_STRLOC,
1930 g_type_name (G_OBJECT_TYPE (iter)));
1931 return NULL;
1932 }
1933
1934 static void
1935 clutter_model_iter_get_property (GObject *object,
1936 guint prop_id,
1937 GValue *value,
1938 GParamSpec *pspec)
1939 {
1940 ClutterModelIter *iter = CLUTTER_MODEL_ITER (object);
1941 ClutterModelIterPrivate *priv = iter->priv;
1942
1943 switch (prop_id)
1944 {
1945 case ITER_PROP_MODEL:
1946 g_value_set_object (value, priv->model);
1947 break;
1948 case ITER_PROP_ROW:
1949 g_value_set_uint (value, priv->row);
1950 break;
1951 default:
1952 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1953 break;
1954 }
1955 }
1956
1957 static void
1958 clutter_model_iter_set_property (GObject *object,
1959 guint prop_id,
1960 const GValue *value,
1961 GParamSpec *pspec)
1962 {
1963 ClutterModelIter *iter = CLUTTER_MODEL_ITER (object);
1964 ClutterModelIterPrivate *priv = iter->priv;
1965
1966 switch (prop_id)
1967 {
1968 case ITER_PROP_MODEL:
1969 priv->model = g_value_get_object (value);
1970 break;
1971 case ITER_PROP_ROW:
1972 priv->row = g_value_get_uint (value);
1973 break;
1974 default:
1975 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1976 break;
1977 }
1978 }
1979
1980 static void
1981 clutter_model_iter_class_init (ClutterModelIterClass *klass)
1982 {
1983 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1984 GParamSpec *pspec;
1985
1986 gobject_class->get_property = clutter_model_iter_get_property;
1987 gobject_class->set_property = clutter_model_iter_set_property;
1988
1989 klass->get_model = clutter_model_iter_real_get_model;
1990 klass->get_row = clutter_model_iter_real_get_row;
1991 klass->is_first = clutter_model_iter_is_first_unimplemented;
1992 klass->is_last = clutter_model_iter_is_last_unimplemented;
1993 klass->next = clutter_model_iter_next_unimplemented;
1994 klass->prev = clutter_model_iter_prev_unimplemented;
1995 klass->get_value = clutter_model_iter_get_value_unimplemented;
1996 klass->set_value = clutter_model_iter_set_value_unimplemented;
1997 klass->copy = clutter_model_iter_copy_unimplemented;
1998
1999 /* Properties */
2000
2001 /**
2002 * ClutterModelIter:model:
2003 *
2004 * A reference to the #ClutterModel that this iter belongs to.
2005 *
2006 * Since: 0.6
2007 *
2008 * Deprecated: 1.24: Use #GListModel instead
2009 */
2010 pspec = g_param_spec_object ("model",
2011 "Model",
2012 "The model to which the iterator belongs to",
2013 CLUTTER_TYPE_MODEL,
2014 CLUTTER_PARAM_READWRITE);
2015 g_object_class_install_property (gobject_class, ITER_PROP_MODEL, pspec);
2016
2017 /**
2018 * ClutterModelIter:row:
2019 *
2020 * The row number to which this iter points to.
2021 *
2022 * Since: 0.6
2023 *
2024 * Deprecated: 1.24: Use #GListModel instead
2025 */
2026 pspec = g_param_spec_uint ("row",
2027 "Row",
2028 "The row to which the iterator points to",
2029 0, G_MAXUINT, 0,
2030 CLUTTER_PARAM_READWRITE);
2031 g_object_class_install_property (gobject_class, ITER_PROP_ROW, pspec);
2032 }
2033
2034 static void
2035 clutter_model_iter_init (ClutterModelIter *self)
2036 {
2037 self->priv = clutter_model_iter_get_instance_private (self);
2038 }
2039
2040 /*
2041 * Public functions
2042 */
2043
2044 static inline void
2045 clutter_model_iter_set_value_internal (ClutterModelIter *iter,
2046 guint column,
2047 const GValue *value)
2048 {
2049 CLUTTER_MODEL_ITER_GET_CLASS (iter)->set_value (iter, column, value);
2050 }
2051
2052 static void
2053 clutter_model_iter_set_internal_valist (ClutterModelIter *iter,
2054 va_list args)
2055 {
2056 ClutterModelIterPrivate *priv = iter->priv;
2057 ClutterModel *model = priv->model;
2058 guint column = 0;
2059 gboolean sort = FALSE;
2060
2061 g_assert (CLUTTER_IS_MODEL (model));
2062
2063 column = va_arg (args, gint);
2064
2065 while (column != -1)
2066 {
2067 GValue value = G_VALUE_INIT;
2068 gchar *error = NULL;
2069 GType col_type;
2070
2071 if (column >= clutter_model_get_n_columns (model))
2072 {
2073 g_warning ("%s: Invalid column number %d added to iter "
2074 "(remember to end you list of columns with a -1)",
2075 G_STRLOC, column);
2076 break;
2077 }
2078
2079 col_type = clutter_model_get_column_type (model, column);
2080
2081 G_VALUE_COLLECT_INIT (&value, col_type, args, 0, &error);
2082 if (error)
2083 {
2084 g_warning ("%s: %s", G_STRLOC, error);
2085 g_free (error);
2086
2087 /* Leak value as it might not be in a sane state */
2088 break;
2089 }
2090
2091 clutter_model_iter_set_value_internal (iter, column, &value);
2092
2093 g_value_unset (&value);
2094
2095 if (column == clutter_model_get_sorting_column (model))
2096 sort = TRUE;
2097
2098 column = va_arg (args, gint);
2099 }
2100
2101 if (sort)
2102 clutter_model_resort (model);
2103 }
2104
2105 static void inline
2106 clutter_model_iter_emit_row_changed (ClutterModelIter *iter)
2107 {
2108 ClutterModelIterPrivate *priv = iter->priv;
2109 ClutterModel *model = priv->model;
2110
2111 g_assert (CLUTTER_IS_MODEL (model));
2112
2113 g_signal_emit (model, model_signals[ROW_CHANGED], 0, iter);
2114 }
2115
2116 /**
2117 * clutter_model_iter_set_valist:
2118 * @iter: a #ClutterModelIter
2119 * @args: va_list of column/value pairs, terminiated by -1
2120 *
2121 * See clutter_model_iter_set(); this version takes a va_list for language
2122 * bindings.
2123 *
2124 * Since: 0.6
2125 *
2126 * Deprecated: 1.24: Use #GListModel instead
2127 */
2128 void
2129 clutter_model_iter_set_valist (ClutterModelIter *iter,
2130 va_list args)
2131 {
2132 g_return_if_fail (CLUTTER_IS_MODEL_ITER (iter));
2133
2134 clutter_model_iter_set_internal_valist (iter, args);
2135 clutter_model_iter_emit_row_changed (iter);
2136 }
2137
2138 /**
2139 * clutter_model_iter_get:
2140 * @iter: a #ClutterModelIter
2141 * @...: a list of column/return location pairs, terminated by -1
2142 *
2143 * Gets the value of one or more cells in the row referenced by @iter. The
2144 * variable argument list should contain integer column numbers, each column
2145 * column number followed by a place to store the value being retrieved. The
2146 * list is terminated by a -1.
2147 *
2148 * For example, to get a value from column 0 with type %G_TYPE_STRING use:
2149 * <informalexample><programlisting>
2150 * clutter_model_iter_get (iter, 0, &place_string_here, -1);
2151 * </programlisting></informalexample>
2152 *
2153 * where place_string_here is a gchar* to be filled with the string. If
2154 * appropriate, the returned values have to be freed or unreferenced.
2155 *
2156 * Since: 0.6
2157 *
2158 * Deprecated: 1.24: Use #GListModel instead
2159 */
2160 void
2161 clutter_model_iter_get (ClutterModelIter *iter,
2162 ...)
2163 {
2164 va_list args;
2165
2166 g_return_if_fail (CLUTTER_IS_MODEL_ITER (iter));
2167
2168 va_start (args, iter);
2169 clutter_model_iter_get_valist (iter, args);
2170 va_end (args);
2171 }
2172
2173 static inline void
2174 clutter_model_iter_get_value_internal (ClutterModelIter *iter,
2175 guint column,
2176 GValue *value)
2177 {
2178 CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_value (iter, column, value);
2179 }
2180
2181 /**
2182 * clutter_model_iter_get_value:
2183 * @iter: a #ClutterModelIter
2184 * @column: column number to retrieve the value from
2185 * @value: (out): an empty #GValue to set
2186 *
2187 * Sets an initializes @value to that at @column. When done with @value,
2188 * g_value_unset() needs to be called to free any allocated memory.
2189 *
2190 * Since: 0.6
2191 *
2192 * Deprecated: 1.24: Use #GListModel instead
2193 */
2194 void
2195 clutter_model_iter_get_value (ClutterModelIter *iter,
2196 guint column,
2197 GValue *value)
2198 {
2199 ClutterModel *model;
2200
2201 g_return_if_fail (CLUTTER_IS_MODEL_ITER (iter));
2202
2203 model = iter->priv->model;
2204
2205 if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
2206 g_value_init (value, clutter_model_get_column_type (model, column));
2207
2208 CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_value (iter, column, value);
2209 }
2210
2211 /**
2212 * clutter_model_iter_get_valist:
2213 * @iter: a #ClutterModelIter
2214 * @args: a list of column/return location pairs, terminated by -1
2215 *
2216 * See clutter_model_iter_get(). This version takes a va_list for language
2217 * bindings.
2218 *
2219 * Since: 0.6
2220 *
2221 * Deprecated: 1.24: Use #GListModel instead
2222 */
2223 void
2224 clutter_model_iter_get_valist (ClutterModelIter *iter,
2225 va_list args)
2226 {
2227 ClutterModelIterPrivate *priv;
2228 ClutterModel *model;
2229 guint column = 0;
2230
2231 g_return_if_fail (CLUTTER_IS_MODEL_ITER (iter));
2232
2233 priv = iter->priv;
2234 model = priv->model;
2235 g_assert (CLUTTER_IS_MODEL (model));
2236
2237 column = va_arg (args, gint);
2238
2239 while (column != -1)
2240 {
2241 GValue value = G_VALUE_INIT;
2242 gchar *error = NULL;
2243 GType col_type;
2244
2245 if (column >= clutter_model_get_n_columns (model))
2246 {
2247 g_warning ("%s: Invalid column number %d added to iter "
2248 "(remember to end you list of columns with a -1)",
2249 G_STRLOC, column);
2250 break;
2251 }
2252
2253 col_type = clutter_model_get_column_type (model, column);
2254 g_value_init (&value, col_type);
2255
2256 clutter_model_iter_get_value_internal (iter, column, &value);
2257
2258 G_VALUE_LCOPY (&value, args, 0, &error);
2259 if (error)
2260 {
2261 g_warning ("%s: %s", G_STRLOC, error);
2262 g_free (error);
2263
2264 /* Leak value as it might not be in a sane state */
2265 break;
2266 }
2267
2268 g_value_unset (&value);
2269
2270 column = va_arg (args, gint);
2271 }
2272 }
2273
2274 /**
2275 * clutter_model_iter_set:
2276 * @iter: a #ClutterModelIter
2277 * @...: a list of column/return location pairs, terminated by -1
2278 *
2279 * Sets the value of one or more cells in the row referenced by @iter. The
2280 * variable argument list should contain integer column numbers, each column
2281 * column number followed by the value to be set. The list is terminated by a
2282 * -1.
2283 *
2284 * For example, to set column 0 with type %G_TYPE_STRING, use:
2285 * <informalexample><programlisting>
2286 * clutter_model_iter_set (iter, 0, "foo", -1);
2287 * </programlisting></informalexample>
2288 *
2289 * Since: 0.6
2290 *
2291 * Deprecated: 1.24: Use #GListModel instead
2292 */
2293 void
2294 clutter_model_iter_set (ClutterModelIter *iter,
2295 ...)
2296 {
2297 va_list args;
2298
2299 g_return_if_fail (CLUTTER_IS_MODEL_ITER (iter));
2300
2301 va_start (args, iter);
2302 clutter_model_iter_set_internal_valist (iter, args);
2303 clutter_model_iter_emit_row_changed (iter);
2304 va_end (args);
2305 }
2306
2307 /**
2308 * clutter_model_iter_set_value:
2309 * @iter: a #ClutterModelIter
2310 * @column: column number to retrieve the value from
2311 * @value: new value for the cell
2312 *
2313 * Sets the data in the cell specified by @iter and @column. The type of
2314 * @value must be convertable to the type of the column.
2315 *
2316 * Since: 0.6
2317 *
2318 * Deprecated: 1.24: Use #GListModel instead
2319 */
2320 void
2321 clutter_model_iter_set_value (ClutterModelIter *iter,
2322 guint column,
2323 const GValue *value)
2324 {
2325 g_return_if_fail (CLUTTER_IS_MODEL_ITER (iter));
2326
2327 clutter_model_iter_set_value_internal (iter, column, value);
2328 clutter_model_iter_emit_row_changed (iter);
2329 }
2330
2331 /**
2332 * clutter_model_iter_is_first:
2333 * @iter: a #ClutterModelIter
2334 *
2335 * Gets whether the current iterator is at the beginning of the model
2336 * to which it belongs.
2337 *
2338 * Return value: #TRUE if @iter is the first iter in the filtered model
2339 *
2340 * Since: 0.6
2341 *
2342 * Deprecated: 1.24: Use #GListModel instead
2343 */
2344 gboolean
2345 clutter_model_iter_is_first (ClutterModelIter *iter)
2346 {
2347 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), FALSE);
2348
2349 return CLUTTER_MODEL_ITER_GET_CLASS (iter)->is_first (iter);
2350 }
2351
2352 /**
2353 * clutter_model_iter_is_last:
2354 * @iter: a #ClutterModelIter
2355 *
2356 * Gets whether the iterator is at the end of the model to which it
2357 * belongs.
2358 *
2359 * Return value: #TRUE if @iter is the last iter in the filtered model.
2360 *
2361 * Since: 0.6
2362 *
2363 * Deprecated: 1.24: Use #GListModel instead
2364 */
2365 gboolean
2366 clutter_model_iter_is_last (ClutterModelIter *iter)
2367 {
2368 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), FALSE);
2369
2370 return CLUTTER_MODEL_ITER_GET_CLASS (iter)->is_last (iter);
2371 }
2372
2373 /**
2374 * clutter_model_iter_next:
2375 * @iter: a #ClutterModelIter
2376 *
2377 * Updates the @iter to point at the next position in the model.
2378 * The model implementation should take into account the presence of
2379 * a filter function.
2380 *
2381 * Return value: (transfer none): The passed iterator, updated to point at the next
2382 * row in the model.
2383 *
2384 * Since: 0.6
2385 *
2386 * Deprecated: 1.24: Use #GListModel instead
2387 */
2388 ClutterModelIter *
2389 clutter_model_iter_next (ClutterModelIter *iter)
2390 {
2391 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
2392
2393 return CLUTTER_MODEL_ITER_GET_CLASS (iter)->next (iter);
2394 }
2395
2396 /**
2397 * clutter_model_iter_prev:
2398 * @iter: a #ClutterModelIter
2399 *
2400 * Sets the @iter to point at the previous position in the model.
2401 * The model implementation should take into account the presence of
2402 * a filter function.
2403 *
2404 * Return value: (transfer none): The passed iterator, updated to point at the previous
2405 * row in the model.
2406 *
2407 * Since: 0.6
2408 *
2409 * Deprecated: 1.24: Use #GListModel instead
2410 */
2411 ClutterModelIter *
2412 clutter_model_iter_prev (ClutterModelIter *iter)
2413 {
2414 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
2415
2416 return CLUTTER_MODEL_ITER_GET_CLASS (iter)->prev (iter);
2417 }
2418
2419 /**
2420 * clutter_model_iter_get_model:
2421 * @iter: a #ClutterModelIter
2422 *
2423 * Retrieves a pointer to the #ClutterModel that this iter is part of.
2424 *
2425 * Return value: (transfer none): a pointer to a #ClutterModel.
2426 *
2427 * Since: 0.6
2428 *
2429 * Deprecated: 1.24: Use #GListModel instead
2430 */
2431 ClutterModel *
2432 clutter_model_iter_get_model (ClutterModelIter *iter)
2433 {
2434 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
2435
2436 return CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_model (iter);
2437 }
2438
2439 /**
2440 * clutter_model_iter_get_row:
2441 * @iter: a #ClutterModelIter
2442 *
2443 * Retrieves the position of the row that the @iter points to.
2444 *
2445 * Return value: the position of the @iter in the model
2446 *
2447 * Since: 0.6
2448 *
2449 * Deprecated: 1.24: Use #GListModel instead
2450 */
2451 guint
2452 clutter_model_iter_get_row (ClutterModelIter *iter)
2453 {
2454 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), 0);
2455
2456 return CLUTTER_MODEL_ITER_GET_CLASS (iter)->get_row (iter);
2457 }
2458
2459 /**
2460 * clutter_model_iter_copy:
2461 * @iter: a #ClutterModelIter
2462 *
2463 * Copies the passed iterator.
2464 *
2465 * Return value: (transfer full): a copy of the iterator, or %NULL
2466 *
2467 * Since: 0.8
2468 *
2469 * Deprecated: 1.24: Use #GListModel instead
2470 */
2471 ClutterModelIter *
2472 clutter_model_iter_copy (ClutterModelIter *iter)
2473 {
2474 g_return_val_if_fail (CLUTTER_IS_MODEL_ITER (iter), NULL);
2475
2476 return CLUTTER_MODEL_ITER_GET_CLASS (iter)->copy (iter);
2477 }