Clutter 0.8.2 Reference Manual | ||||
---|---|---|---|---|
ClutterModel; ClutterModelClass; void clutter_model_set_names (ClutterModel *model, guint n_columns, const gchar * const names[]); void clutter_model_set_types (ClutterModel *model, guint n_columns, GType *types); const gchar* clutter_model_get_column_name (ClutterModel *model, guint column); GType clutter_model_get_column_type (ClutterModel *model, guint column); guint clutter_model_get_n_columns (ClutterModel *model); guint clutter_model_get_n_rows (ClutterModel *model); void clutter_model_append (ClutterModel *model, ...); void clutter_model_appendv (ClutterModel *model, guint n_columns, guint *columns, GValue *values); void clutter_model_prepend (ClutterModel *model, ...); void clutter_model_prependv (ClutterModel *model, guint n_columns, guint *columns, GValue *values); void clutter_model_insert (ClutterModel *model, guint row, ...); void clutter_model_insertv (ClutterModel *model, guint row, guint n_columns, guint *columns, GValue *values); void clutter_model_insert_value (ClutterModel *model, guint row, guint column, const GValue *value); void clutter_model_remove (ClutterModel *model, guint row); gboolean (*ClutterModelForeachFunc) (ClutterModel *model, ClutterModelIter *iter, gpointer user_data); void clutter_model_foreach (ClutterModel *model, ClutterModelForeachFunc func, gpointer user_data); void clutter_model_set_sorting_column (ClutterModel *model, gint column); gint clutter_model_get_sorting_column (ClutterModel *model); gint (*ClutterModelSortFunc) (ClutterModel *model, const GValue *a, const GValue *b, gpointer user_data); void clutter_model_set_sort (ClutterModel *model, guint column, ClutterModelSortFunc func, gpointer user_data, GDestroyNotify notify); void clutter_model_resort (ClutterModel *model); gboolean (*ClutterModelFilterFunc) (ClutterModel *model, ClutterModelIter *iter, gpointer user_data); void clutter_model_set_filter (ClutterModel *model, ClutterModelFilterFunc func, gpointer user_data, GDestroyNotify notify); gboolean clutter_model_filter_iter (ClutterModel *model, ClutterModelIter *iter); gboolean clutter_model_filter_row (ClutterModel *model, guint row); ClutterModelIter* clutter_model_get_first_iter (ClutterModel *model); ClutterModelIter* clutter_model_get_last_iter (ClutterModel *model); ClutterModelIter* clutter_model_get_iter_at_row (ClutterModel *model, guint row);
"filter-changed" : Run Last "row-added" : Run Last "row-changed" : Run Last "row-removed" : Run Last "sort-changed" : Run Last
ClutterModel is a generic list model API which can be used to implement the model-view-controller architectural pattern in Clutter.
The ClutterModel 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 ClutterModelIter
pointing to the starting row, and calling clutter_model_iter_next()
or
clutter_model_iter_prev()
to move forward or backwards, repectively.
A valid ClutterModelIter 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); }
ClutterModel is an abstract class. Clutter provides a default model implementation called ClutterModelDefault which has been optimised for insertion and look up in sorted lists.
ClutterModel is available since Clutter 0.6
typedef struct _ClutterModel ClutterModel;
Base class for list models. The ClutterModel structure contains only private data and should be manipulated using the provided API.
Since 0.6
typedef struct { /* vtable */ guint (* get_n_rows) (ClutterModel *model); guint (* get_n_columns) (ClutterModel *model); const gchar * (* get_column_name) (ClutterModel *model, guint column); GType (* get_column_type) (ClutterModel *model, guint column); ClutterModelIter *(* insert_row) (ClutterModel *model, gint index_); void (* remove_row) (ClutterModel *model, guint row); ClutterModelIter *(* get_iter_at_row) (ClutterModel *model, guint row); void (* resort) (ClutterModel *model, ClutterModelSortFunc func, gpointer data); /* signals */ void (* row_added) (ClutterModel *model, ClutterModelIter *iter); void (* row_removed) (ClutterModel *model, ClutterModelIter *iter); void (* row_changed) (ClutterModel *model, ClutterModelIter *iter); void (* sort_changed) (ClutterModel *model); void (* filter_changed) (ClutterModel *model); } ClutterModelClass;
Class for ClutterModel instances.
|
virtual function for returning the number of rows of the model, not considering any filter function if present |
|
virtual function for retuning the number of columns of the model |
|
virtual function for returning the name of a column |
|
virtual function for returning the type of a column |
|
virtual function for inserting a row at the given index and returning an iterator pointing to it; if the index is a negative integer, the row should be appended to the model |
|
virtual function for removing a row at the given index |
|
virtual function for returning an iterator for the given row |
|
virtual function for sorting the model using the passed sorting function |
|
signal class handler for ClutterModel::row-added |
|
signal class handler for ClutterModel::row-removed |
|
signal class handler for ClutterModel::row-changed |
|
signal class handler for ClutterModel::sort-changed |
|
signal class handler for ClutterModel::filter-changed |
Since 0.6
void clutter_model_set_names (ClutterModel *model, guint n_columns, const gchar * const names[]);
Assigns a name to the columns of a ClutterModel.
This function is meant primarily for GObjects that inherit from ClutterModel, and should only be used when contructing a ClutterModel. It will not work after the initial creation of the ClutterModel.
|
a ClutterModel |
|
the number of column names |
|
an array of strings |
Since 0.6
void clutter_model_set_types (ClutterModel *model, guint n_columns, GType *types);
Sets the types of the columns inside a ClutterModel.
This function is meant primarily for GObjects that inherit from ClutterModel, and should only be used when contructing a ClutterModel. It will not work after the initial creation of the ClutterModel.
|
a ClutterModel |
|
number of columns for the model |
|
an array of GType types |
Since 0.6
const gchar* clutter_model_get_column_name (ClutterModel *model, guint column);
Retrieves the name of the column
|
ClutterModel |
|
the column number |
Returns : |
the name of the column. The model holds the returned string, and it should not be modified or freed |
Since 0.6
GType clutter_model_get_column_type (ClutterModel *model, guint column);
Retrieves the type of the column
.
|
ClutterModel |
|
the column number |
Returns : |
the type of the column. |
Since 0.6
guint clutter_model_get_n_columns (ClutterModel *model);
Retrieves the number of columns inside model
.
|
a ClutterModel |
Returns : |
the number of columns |
Since 0.6
guint clutter_model_get_n_rows (ClutterModel *model);
Retrieves the number of rows inside model
.
|
a ClutterModel |
Returns : |
The length of the model . If there is a filter set, then
the length of the filtered model is returned.
|
Since 0.6
void clutter_model_append (ClutterModel *model, ...);
Creates and appends a new row to the ClutterModel, setting the
row values upon creation. For example, to append a new row where
column 0 is type G_TYPE_INT
and column 1 is of type G_TYPE_STRING
:
ClutterModel *model; model = clutter_model_default_new (2, G_TYPE_INT, "Score", G_TYPE_STRING, "Team"); clutter_model_append (model, 0, 42, 1, "Team 1", -1);
|
a ClutterModel |
|
pairs of column number and value, terminated with -1 |
Since 0.6
void clutter_model_appendv (ClutterModel *model, guint n_columns, guint *columns, GValue *values);
Creates and appends a new row to the ClutterModel, setting the row
values for the given columns
upon creation.
|
a ClutterModel |
|
the number of columns and values |
|
a vector with the columns to set |
|
a vector with the values |
Since 0.6
void clutter_model_prepend (ClutterModel *model, ...);
Creates and prepends a new row to the ClutterModel, setting the row
values upon creation. For example, to prepend a new row where column 0
is type G_TYPE_INT
and column 1 is of type G_TYPE_STRING
:
ClutterModel *model; model = clutter_model_default_new (2, G_TYPE_INT, "Score", G_TYPE_STRING, "Team"); clutter_model_prepend (model, 0, 42, 1, "Team 1", -1);
|
a ClutterModel |
|
pairs of column number and value, terminated with -1 |
Since 0.6
void clutter_model_prependv (ClutterModel *model, guint n_columns, guint *columns, GValue *values);
Creates and prepends a new row to the ClutterModel, setting the row
values for the given columns
upon creation.
|
a ClutterModel |
|
the number of columns and values to set |
|
a vector containing the columns to set |
|
a vector containing the values for the cells |
Since 0.6
void clutter_model_insert (ClutterModel *model, guint row, ...);
Inserts a new row to the ClutterModel at row
, setting the row
values upon creation. For example, to insert a new row at index 100,
where column 0 is type G_TYPE_INT
and column 1 is of type
G_TYPE_STRING
:
ClutterModel *model; model = clutter_model_default_new (2, G_TYPE_INT, "Score", G_TYPE_STRING, "Team"); clutter_model_insert (model, 3, 0, 42, 1, "Team 1", -1);
|
a ClutterModel |
|
the position to insert the new row |
|
pairs of column number and value, terminated with -1 |
Since 0.6
void clutter_model_insertv (ClutterModel *model, guint row, guint n_columns, guint *columns, GValue *values);
Inserts data at row
into the ClutterModel, setting the row
values for the given columns
upon creation.
|
a ClutterModel |
|
row index |
|
the number of columns and values to set |
|
a vector containing the columns to set |
|
a vector containing the values for the cells |
Since 0.6
void clutter_model_insert_value (ClutterModel *model, guint row, guint column, const GValue *value);
Sets the data in the cell specified by iter
and column
. The type of
value
must be convertable to the type of the column. If the row does
not exist then it is created.
|
a ClutterModel |
|
position of the row to modify |
|
column to modify |
|
new value for the cell |
Since 0.6
void clutter_model_remove (ClutterModel *model, guint row);
Removes the row at the given position from the model.
|
a ClutterModel |
|
position of row to remove |
Since 0.6
gboolean (*ClutterModelForeachFunc) (ClutterModel *model, ClutterModelIter *iter, gpointer user_data);
Iterates on the content of a row in the model
|
a ClutterModel |
|
the iterator for the row |
|
data passed to clutter_model_foreach()
|
Returns : |
TRUE if the iteration should continue, FALSE otherwise
|
Since 0.6
void clutter_model_foreach (ClutterModel *model, ClutterModelForeachFunc func, gpointer user_data);
Calls func
for each row in the model.
|
a ClutterModel |
|
a ClutterModelForeachFunc |
|
user data to pass to func
|
Since 0.6
void clutter_model_set_sorting_column (ClutterModel *model, gint column);
Sets the model to sort by column
. If column
is a negative value
the sorting column will be unset.
|
a ClutterModel |
|
the column of the model to sort, or -1
|
Since 0.6
gint clutter_model_get_sorting_column (ClutterModel *model);
Retrieves the number of column used for sorting the model
.
|
a ClutterModel |
Returns : |
a column number, or -1 if the model is not sorted |
Since 0.6
gint (*ClutterModelSortFunc) (ClutterModel *model, const GValue *a, const GValue *b, gpointer user_data);
Compares the content of two rows in the model.
|
a ClutterModel |
|
a GValue representing the contents of the row |
|
a GValue representing the contents of the second row |
|
data passed to clutter_model_set_sort()
|
Returns : |
a positive integer if a is after b , a negative integer if
a is before b , or 0 if the rows are the same
|
Since 0.6
void clutter_model_set_sort (ClutterModel *model, guint column, ClutterModelSortFunc func, gpointer user_data, GDestroyNotify notify);
Sorts model
using the given sorting function.
|
a ClutterModel |
|
the column to sort on |
|
a ClutterModelSortFunc, or NULL |
|
user data to pass to func , or NULL
|
|
destroy notifier of user_data , or NULL
|
Since 0.6
void clutter_model_resort (ClutterModel *model);
Force a resort on the model
. This function should only be
used by subclasses of ClutterModel.
|
a ClutterModel |
Since 0.6
gboolean (*ClutterModelFilterFunc) (ClutterModel *model, ClutterModelIter *iter, gpointer user_data);
Filters the content of a row in the model.
|
a ClutterModel |
|
the iterator for the row |
|
data passed to clutter_model_set_filter()
|
Returns : |
If the row should be displayed, return TRUE
|
Since 0.6
void clutter_model_set_filter (ClutterModel *model, ClutterModelFilterFunc func, gpointer user_data, GDestroyNotify notify);
Filters the model
using the given filtering function.
|
a ClutterModel |
|
a ClutterModelFilterFunc, or NULL |
|
user data to pass to func , or NULL
|
|
destroy notifier of user_data , or NULL
|
Since 0.6
gboolean clutter_model_filter_iter (ClutterModel *model, ClutterModelIter *iter);
Checks whether the row pointer by iter
should be filtered or not using
the filtering function set on model
.
This function should be used only by subclasses of ClutterModel.
|
a ClutterModel |
|
the row to filter |
Returns : |
TRUE if the row should be displayed,
FALSE otherwise
|
Since 0.6
gboolean clutter_model_filter_row (ClutterModel *model, guint row);
Checks whether row
should be filtered or not using the
filtering function set on model
.
This function should be used only by subclasses of ClutterModel.
|
a ClutterModel |
|
the row to filter |
Returns : |
TRUE if the row should be displayed,
FALSE otherwise
|
Since 0.6
ClutterModelIter* clutter_model_get_first_iter (ClutterModel *model);
Retrieves a ClutterModelIter representing the first row in model
.
|
a ClutterModel |
Returns : |
A new ClutterModelIter. Call g_object_unref() when
done using it
|
Since 0.6
ClutterModelIter* clutter_model_get_last_iter (ClutterModel *model);
Retrieves a ClutterModelIter representing the last row in model
.
|
a ClutterModel |
Returns : |
A new ClutterModelIter. Call g_object_unref() when
done using it
|
Since 0.6
ClutterModelIter* clutter_model_get_iter_at_row (ClutterModel *model, guint row);
Retrieves a ClutterModelIter representing the row at the given index.
|
a ClutterModel |
|
position of the row to retrieve |
Returns : |
A new ClutterModelIter, or NULL if row was out of bounds.
When done using the iterator object, call g_object_unref() to deallocate
its resources
|
Since 0.6
"filter-changed"
signalvoid user_function (ClutterModel *model, gpointer user_data) : Run Last
The ::filter-changed signal is emitted when a new filter has been applied
|
the ClutterModel on which the signal is emitted |
|
user data set when the signal handler was connected. |
Since 0.6
"row-added"
signalvoid user_function (ClutterModel *model, ClutterModelIter *iter, gpointer user_data) : Run Last
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.
|
the ClutterModel on which the signal is emitted |
|
a ClutterModelIter pointing to the new row |
|
user data set when the signal handler was connected. |
Since 0.6
"row-changed"
signalvoid user_function (ClutterModel *model, ClutterModelIter *iter, gpointer user_data) : Run Last
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.
|
the ClutterModel on which the signal is emitted |
|
a ClutterModelIter pointing to the changed row |
|
user data set when the signal handler was connected. |
Since 0.6
"row-removed"
signalvoid user_function (ClutterModel *model, ClutterModelIter *iter, gpointer user_data) : Run Last
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.
|
the ClutterModel on which the signal is emitted |
|
a ClutterModelIter pointing to the removed row |
|
user data set when the signal handler was connected. |
Since 0.6
"sort-changed"
signalvoid user_function (ClutterModel *model, gpointer user_data) : Run Last
The ::sort-changed signal is emitted after the model has been sorted
|
the ClutterModel on which the signal is emitted |
|
user data set when the signal handler was connected. |
Since 0.6