From fc22b75a06e9ee0298e63694299680c6a9a6d598 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 26 Jul 2020 18:32:50 -0400 Subject: [PATCH] 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. --- gtk/gtkcolumnview.c | 23 +++++++++++++++++------ gtk/gtkcolumnview.h | 2 +- tests/testlistdnd.c | 6 +----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c index 590c7073d3..176481f2ba 100644 --- a/gtk/gtkcolumnview.c +++ b/gtk/gtkcolumnview.c @@ -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; } /** diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h index 0983ea2c39..e3dc777b65 100644 --- a/gtk/gtkcolumnview.h +++ b/gtk/gtkcolumnview.h @@ -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); diff --git a/tests/testlistdnd.c b/tests/testlistdnd.c index 338b522842..0f404f4221 100644 --- a/tests/testlistdnd.c +++ b/tests/testlistdnd.c @@ -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++) {