columnview: Revise the constructor

Make gtk_column_view_new take a model as first argument,
and make it allow-none and transfer full.

Update all callers.
This commit is contained in:
Matthias Clasen 2020-07-26 18:32:50 -04:00
parent 43000abeff
commit fc22b75a06
3 changed files with 19 additions and 12 deletions

View File

@ -1179,19 +1179,30 @@ gtk_column_view_init (GtkColumnView *self)
/**
* gtk_column_view_new:
* @model: (allow-none) (transfer full): the list model to use, or %NULL
*
* Creates a new empty #GtkColumnView.
* Creates a new #GtkColumnView.
*
* You most likely want to call gtk_column_view_set_factory() to
* set up a way to map its items to widgets and gtk_column_view_set_model()
* to set a model to provide items next.
* You most likely want to call gtk_column_view_append_column() to
* add columns next.
*
* Returns: a new #GtkColumnView
**/
GtkWidget *
gtk_column_view_new (void)
gtk_column_view_new (GListModel *model)
{
return g_object_new (GTK_TYPE_COLUMN_VIEW, NULL);
GtkWidget *result;
g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_COLUMN_VIEW,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return result;
}
/**

View File

@ -51,7 +51,7 @@ GDK_AVAILABLE_IN_ALL
GType gtk_column_view_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_column_view_new (void);
GtkWidget * gtk_column_view_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_column_view_get_columns (GtkColumnView *self);

View File

@ -381,11 +381,7 @@ main (int argc, char *argv[])
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_stack_add_titled (GTK_STACK (stack), sw, "column", "GtkColumnView");
cv = gtk_column_view_new ();
model = create_model (0, 400, 1, FALSE);
gtk_column_view_set_model (GTK_COLUMN_VIEW (cv), model);
g_object_unref (model);
cv = gtk_column_view_new (create_model (0, 400, 1, FALSE));
for (guint i = 0; i < 20; i++)
{