diff --git a/ChangeLog b/ChangeLog index b7d5db185..78ed072d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-12-10 Emmanuele Bassi + + * clutter/clutter-model.h: + * clutter/clutter-model.c: + (clutter_model_append_value), + (clutter_model_prepend_value), + (clutter_model_insert_value): Add a _value() variant for the + insertion methods, for use of the language bindings. + + (clutter_model_append), + (clutter_model_prepend), + (clutter_model_insert): Do not return a boolean: insertion should + never fail unless for a programming error, in which case we have + plenty of warnings. + 2007-12-10 Emmanuele Bassi * clutter/clutter-behaviour-ellipse.c: diff --git a/clutter/clutter-model.c b/clutter/clutter-model.c index 7b655bf1b..f9de40602 100644 --- a/clutter/clutter-model.c +++ b/clutter/clutter-model.c @@ -677,21 +677,68 @@ clutter_model_new_row (ClutterModel *model) return row; } +/** + * clutter_model_append_value: + * @model: a #ClutterModel + * @column: the column to set + * @value: the value of the cell + * + * Creates and appends a new row to the #ClutterModel, setting the row + * value for the given @column upon creation. + * + * Since 0.6 + */ +void +clutter_model_append_value (ClutterModel *model, + guint column, + const GValue *value) +{ + ClutterModelPrivate *priv; + ClutterModelIter *iter; + GSequenceIter *seq_iter; + GValueArray *row; + + g_return_if_fail (CLUTTER_IS_MODEL (model)); + + priv = model->priv; + + row = clutter_model_new_row (model); + seq_iter = g_sequence_append (priv->sequence, row); + + iter = g_object_new (CLUTTER_TYPE_MODEL_ITER, + "model", model, + "iter", seq_iter, + NULL); + + clutter_model_iter_set_value (iter, column, value); + + if (priv->sort_column == column) + _model_sort (model); + + g_signal_emit (model, model_signals[ROW_ADDED], 0, iter); + g_object_unref (iter); +} + /** * clutter_model_append: * @model: a #ClutterModel * @Varargs: pairs of column number and value, terminated with -1 * - * Creates and appends a new row to the #ClutterModel, setting the rows 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, you would write - * clutter_model_append (model, 0, 100, 1, "foo", -1);. + * 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: * - * Return value: #TRUE if a new row was successfully added. + * + * ClutterModel *model; + * model = clutter_model_new (2, + * G_TYPE_INT, "My integers", + * G_TYPE_STRING, "My strings"); + * clutter_model_append (model, 0, 42, 1, "string", -1); + * * * Since 0.6 */ -gboolean +void clutter_model_append (ClutterModel *model, ...) { @@ -701,7 +748,7 @@ clutter_model_append (ClutterModel *model, GValueArray *row; va_list args; - g_return_val_if_fail (CLUTTER_IS_MODEL (model), FALSE); + g_return_if_fail (CLUTTER_IS_MODEL (model)); priv = model->priv; row = clutter_model_new_row (model); @@ -719,25 +766,70 @@ clutter_model_append (ClutterModel *model, /*FIXME: Sort the model if necessary */ g_signal_emit (model, model_signals[ROW_ADDED], 0, iter); g_object_unref (iter); - return TRUE; } +/** + * clutter_model_prepend_value: + * @model: a #ClutterModel + * @column: column to set + * @value: new value for the cell + * + * Creates and prepends a new row to the #ClutterModel, setting the row + * value for the given @column upon creation. + * + * Since 0.6 + */ +void +clutter_model_prepend_value (ClutterModel *model, + guint column, + const GValue *value) +{ + ClutterModelPrivate *priv; + ClutterModelIter *iter; + GSequenceIter *seq_iter; + GValueArray *row; + + g_return_if_fail (CLUTTER_IS_MODEL (model)); + + priv = model->priv; + + row = clutter_model_new_row (model); + seq_iter = g_sequence_prepend (priv->sequence, row); + + iter = g_object_new (CLUTTER_TYPE_MODEL_ITER, + "model", model, + "iter", seq_iter, + NULL); + + clutter_model_iter_set_value (iter, column, value); + + if (priv->sort_column == column) + _model_sort (model); + + g_signal_emit (model, model_signals[ROW_ADDED], 0, iter); + g_object_unref (iter); +} /** * clutter_model_prepend: * @model: a #ClutterModel * @Varargs: pairs of column number and value, terminated with -1 * - * Creates and prepends a new row to the #ClutterModel, setting the rows 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, you would write - * clutter_model_prepend (model, 0, 100, 1, "string", -1);. + * 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: * - * Return value: #TRUE if a new row was successfully added. + * + * ClutterModel *model; + * model = clutter_model_new (2, + * G_TYPE_INT, "My integers", + * G_TYPE_STRING, "My strings"); + * clutter_model_prepend (model, 0, 42, 1, "string", -1); + * * * Since 0.6 */ -gboolean +void clutter_model_prepend (ClutterModel *model, ...) { @@ -747,7 +839,8 @@ clutter_model_prepend (ClutterModel *model, GValueArray *row; va_list args; - g_return_val_if_fail (CLUTTER_IS_MODEL (model), FALSE); + g_return_if_fail (CLUTTER_IS_MODEL (model)); + priv = model->priv; row = clutter_model_new_row (model); @@ -764,7 +857,6 @@ clutter_model_prepend (ClutterModel *model, /*FIXME: Sort the model if necessary */ g_signal_emit (model, model_signals[ROW_ADDED], 0, iter); g_object_unref (iter); - return TRUE; } @@ -774,17 +866,22 @@ clutter_model_prepend (ClutterModel *model, * @row: the position to insert the new row * @Varargs: pairs of column number and value, terminated with -1 * - * Inserts a new row to the #ClutterModel at @row, setting the rows 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, you would write - * clutter_model_insert (model, 100, 0, 100, 1, "string", -1); - * . + * 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: * - * Return value: #TRUE if a new row was successfully added. + * + * ClutterModel *model; + * model = clutter_model_new (2, + * G_TYPE_INT, "My integers", + * G_TYPE_STRING, "My strings"); + * clutter_model_insert (model, 100, 0, 42, 1, "string", -1); + * * * Since 0.6 */ -gboolean +void clutter_model_insert (ClutterModel *model, guint row, ...) @@ -795,7 +892,8 @@ clutter_model_insert (ClutterModel *model, GSequenceIter *seq_iter; va_list args; - g_return_val_if_fail (CLUTTER_IS_MODEL (model), FALSE); + g_return_if_fail (CLUTTER_IS_MODEL (model)); + priv = model->priv; row_array = clutter_model_new_row (model); @@ -816,7 +914,6 @@ clutter_model_insert (ClutterModel *model, g_signal_emit (model, model_signals[ROW_ADDED], 0, iter); g_object_unref (iter); - return TRUE; } /** @@ -829,11 +926,9 @@ clutter_model_insert (ClutterModel *model, * Sets the data in the cell specified by @iter and @column. The type of * @value must be convertable to the type of the column. * - * Return value: #TRUE if the @value was successfully inserted. - * * Since 0.6 */ -gboolean +void clutter_model_insert_value (ClutterModel *model, guint row, guint column, @@ -843,7 +938,8 @@ clutter_model_insert_value (ClutterModel *model, ClutterModelIter *iter; GSequenceIter *seq_iter; - g_return_val_if_fail (CLUTTER_IS_MODEL (model), FALSE); + g_return_if_fail (CLUTTER_IS_MODEL (model)); + priv = model->priv; seq_iter = g_sequence_get_iter_at_pos (priv->sequence, row); @@ -852,6 +948,7 @@ clutter_model_insert_value (ClutterModel *model, "model", model, "iter", seq_iter, NULL); + clutter_model_iter_set_value (iter, column, value); if (priv->sort_column == column) @@ -859,7 +956,6 @@ clutter_model_insert_value (ClutterModel *model, g_signal_emit (model, model_signals[ROW_CHANGED], 0, iter); g_object_unref (iter); - return TRUE; } static void diff --git a/clutter/clutter-model.h b/clutter/clutter-model.h index 4873cadbd..73879adc3 100644 --- a/clutter/clutter-model.h +++ b/clutter/clutter-model.h @@ -181,14 +181,20 @@ void clutter_model_set_names (ClutterModel *model, guint n_columns, const gchar * const names[]); -gboolean clutter_model_append (ClutterModel *model, +void clutter_model_append (ClutterModel *model, ...); -gboolean clutter_model_prepend (ClutterModel *model, +void clutter_model_append_value (ClutterModel *model, + guint column, + const GValue *value); +void clutter_model_prepend (ClutterModel *model, ...); -gboolean clutter_model_insert (ClutterModel *model, +void clutter_model_prepend_value (ClutterModel *model, + guint column, + const GValue *value); +void clutter_model_insert (ClutterModel *model, guint row, ...); -gboolean clutter_model_insert_value (ClutterModel *model, +void clutter_model_insert_value (ClutterModel *model, guint row, guint column, const GValue *value); diff --git a/doc/reference/ChangeLog b/doc/reference/ChangeLog index b9607bedf..2e5f12265 100644 --- a/doc/reference/ChangeLog +++ b/doc/reference/ChangeLog @@ -1,3 +1,7 @@ +2007-12-10 Emmanuele Bassi + + * clutter-sections.txt: Add the new ClutterModel API. + 2007-12-10 Emmanuele Bassi * clutter-docs.sgml: Add ClutterShader... diff --git a/doc/reference/clutter-sections.txt b/doc/reference/clutter-sections.txt index 4b7ce5448..8f674429f 100644 --- a/doc/reference/clutter-sections.txt +++ b/doc/reference/clutter-sections.txt @@ -1148,7 +1148,9 @@ clutter_model_newv clutter_model_set_names clutter_model_set_types clutter_model_append +clutter_model_append_value clutter_model_prepend +clutter_model_prepend_value clutter_model_insert clutter_model_insert_value clutter_model_remove