Next: , Previous: ClutterModelIter, Up: Top


28 ClutterModel

A generic model implementation

28.1 Overview

<clutter-model> is a generic list model API which can be used to implement the model-view-controller architectural pattern in Clutter.

The <clutter-model> class is a list model which can accept most GObject types as a column type.

Creating a simple clutter model:

     
     enum
     {
       COLUMN_INT,
       COLUMN_STRING,
     
       N_COLUMNS
     };
     
     {
       ClutterModel *model;
       gint i;
     
       model = clutter_model_default_new (N_COLUMNS,
                                          /* column type, column title */
                                          G_TYPE_INT,     "my integers",
                                          G_TYPE_STRING,  "my strings");
       for (i = 0; i < 10; i++)
         {
           gchar *string = g_strdup_printf ("String %d", i);
           clutter_model_append (model,
                                 COLUMN_INT, i,
                                 COLUMN_STRING, string,
                                 -1);
           g_free (string);
         }
     
     
     }

Iterating through the model consists of retrieving a new <clutter-model-iter> pointing to the starting row, and calling clutter-model-iter-next or clutter-model-iter-prev to move forward or backwards, repectively.

A valid <clutter-model-iter> represents the position between two rows in the model. For example, the "first" iterator represents the gap immediately before the first row, and the "last" iterator represents the gap immediately after the last row. In an empty sequence, the first and last iterators are the same.

Iterating a <"">

     
     enum
     {
       COLUMN_INT,
       COLUMN_STRING.
     
       N_COLUMNS
     };
     
     {
       ClutterModel *model;
       ClutterModelIter *iter = NULL;
     
       /*  Fill the model */
       model = populate_model ();
     
       /* Get the first iter */
       iter = clutter_model_get_first_iter (model);
       while (!clutter_model_iter_is_last (iter))
         {
           print_row (iter);
     
           iter = clutter_model_iter_next (iter);
         }
     
       /* Make sure to unref the iter */
       g_object_unref (iter);
     }

<clutter-model> is an abstract class. Clutter provides a default model implementation called <clutter-model-default> which has been optimised for insertion and look up in sorted lists.

<clutter-model> is available since Clutter 0.6

28.2 Usage

— Class: <clutter-model>

Derives from <gobject>.

This class defines no direct slots.

— Signal on <clutter-model>: row-added (arg0 <clutter-model-iter>)

The ::row-added signal is emitted when a new row has been added. The data on the row has already been set when the ::row-added signal has been emitted.

Since 0.6

— Signal on <clutter-model>: row-removed (arg0 <clutter-model-iter>)

The ::row-removed signal is emitted when a row has been removed. The data on the row pointed by the passed iterator is still valid when the ::row-removed signal has been emitted.

Since 0.6

— Signal on <clutter-model>: row-changed (arg0 <clutter-model-iter>)

The ::row-removed signal is emitted when a row has been changed. The data on the row has already been updated when the ::row-changed signal has been emitted.

Since 0.6

— Signal on <clutter-model>: sort-changed

The ::sort-changed signal is emitted after the model has been sorted

Since 0.6

— Signal on <clutter-model>: filter-changed

The ::filter-changed signal is emitted when a new filter has been applied

Since 0.6