treelistmodel: Make constructor transfer full

Make gtk_tree_list_model_new() take the root model
as first argument, and make it transfer full, for
consistency with other wrapping list constructors.

Update all callers.

Still missing here: Make the model property writable,
and allow passing NULL in the constructor.
This commit is contained in:
Matthias Clasen 2020-07-26 16:38:53 -04:00
parent a46cfd3ff4
commit dd1c0c0b22
12 changed files with 27 additions and 40 deletions

View File

@ -398,8 +398,8 @@ do_listview_settings (GtkWidget *do_widget)
g_object_unref (actions); g_object_unref (actions);
model = create_settings_model (NULL, NULL); model = create_settings_model (NULL, NULL);
treemodel = gtk_tree_list_model_new (FALSE, treemodel = gtk_tree_list_model_new (model,
model, FALSE,
TRUE, TRUE,
create_settings_model, create_settings_model,
NULL, NULL,
@ -414,7 +414,6 @@ do_listview_settings (GtkWidget *do_widget)
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection)); gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
g_object_unref (selection); g_object_unref (selection);
g_object_unref (treemodel); g_object_unref (treemodel);
g_object_unref (model);
name_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "name_column")); name_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "name_column"));
sorter = gtk_string_sorter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name")); sorter = gtk_string_sorter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name"));

View File

@ -1136,8 +1136,8 @@ activate (GApplication *app)
g_signal_connect (search_bar, "notify::search-mode-enabled", G_CALLBACK (clear_search), NULL); g_signal_connect (search_bar, "notify::search-mode-enabled", G_CALLBACK (clear_search), NULL);
listmodel = create_demo_model (); listmodel = create_demo_model ();
treemodel = gtk_tree_list_model_new (FALSE, treemodel = gtk_tree_list_model_new (G_LIST_MODEL (listmodel),
G_LIST_MODEL (listmodel), FALSE,
TRUE, TRUE,
get_child_model, get_child_model,
NULL, NULL,

View File

@ -734,8 +734,8 @@ gtk_tree_list_model_init (GtkTreeListModel *self)
/** /**
* gtk_tree_list_model_new: * gtk_tree_list_model_new:
* @root: (transfer full): The #GListModel to use as root
* @passthrough: %TRUE to pass through items from the models * @passthrough: %TRUE to pass through items from the models
* @root: The #GListModel to use as root
* @autoexpand: %TRUE to set the autoexpand property and expand the @root model * @autoexpand: %TRUE to set the autoexpand property and expand the @root model
* @create_func: Function to call to create the #GListModel for the children * @create_func: Function to call to create the #GListModel for the children
* of an item * of an item
@ -747,8 +747,8 @@ gtk_tree_list_model_init (GtkTreeListModel *self)
* Returns: a newly created #GtkTreeListModel. * Returns: a newly created #GtkTreeListModel.
**/ **/
GtkTreeListModel * GtkTreeListModel *
gtk_tree_list_model_new (gboolean passthrough, gtk_tree_list_model_new (GListModel *root,
GListModel *root, gboolean passthrough,
gboolean autoexpand, gboolean autoexpand,
GtkTreeListModelCreateModelFunc create_func, GtkTreeListModelCreateModelFunc create_func,
gpointer user_data, gpointer user_data,
@ -768,7 +768,7 @@ gtk_tree_list_model_new (gboolean passthrough,
self->user_data = user_data; self->user_data = user_data;
self->user_destroy = user_destroy; self->user_destroy = user_destroy;
gtk_tree_list_model_init_node (self, &self->root_node, g_object_ref (root)); gtk_tree_list_model_init_node (self, &self->root_node, root);
return self; return self;
} }

View File

@ -58,8 +58,8 @@ G_DECLARE_FINAL_TYPE (GtkTreeListRow, gtk_tree_list_row, GTK, TREE_LIST_ROW, GOb
typedef GListModel * (* GtkTreeListModelCreateModelFunc) (gpointer item, gpointer user_data); typedef GListModel * (* GtkTreeListModelCreateModelFunc) (gpointer item, gpointer user_data);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GtkTreeListModel * gtk_tree_list_model_new (gboolean passthrough, GtkTreeListModel * gtk_tree_list_model_new (GListModel *root,
GListModel *root, gboolean passthrough,
gboolean autoexpand, gboolean autoexpand,
GtkTreeListModelCreateModelFunc create_func, GtkTreeListModelCreateModelFunc create_func,
gpointer user_data, gpointer user_data,

View File

@ -1298,18 +1298,13 @@ void
gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt, gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
GdkDisplay *display) GdkDisplay *display)
{ {
GListModel *root_model; wt->priv->tree_model = gtk_tree_list_model_new (create_root_model (display),
FALSE,
root_model = create_root_model (display);
wt->priv->tree_model = gtk_tree_list_model_new (FALSE,
root_model,
FALSE, FALSE,
create_model_for_object, create_model_for_object,
NULL, NULL,
NULL); NULL);
wt->priv->selection = gtk_single_selection_new (G_LIST_MODEL (wt->priv->tree_model)); wt->priv->selection = gtk_single_selection_new (G_LIST_MODEL (wt->priv->tree_model));
g_object_unref (root_model);
gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list), gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list),
G_LIST_MODEL (wt->priv->selection)); G_LIST_MODEL (wt->priv->selection));
} }

View File

@ -1234,8 +1234,8 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder)
NULL); NULL);
recorder->render_node_root_model = g_list_store_new (GDK_TYPE_PAINTABLE); recorder->render_node_root_model = g_list_store_new (GDK_TYPE_PAINTABLE);
recorder->render_node_model = gtk_tree_list_model_new (FALSE, recorder->render_node_model = gtk_tree_list_model_new (g_object_ref (G_LIST_MODEL (recorder->render_node_root_model)),
G_LIST_MODEL (recorder->render_node_root_model), FALSE,
TRUE, TRUE,
create_list_model_for_render_node_paintable, create_list_model_for_render_node_paintable,
NULL, NULL); NULL, NULL);

View File

@ -692,7 +692,6 @@ static void
constructed (GObject *object) constructed (GObject *object)
{ {
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object); GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
GListModel *root_model;
GListModel *sort_model; GListModel *sort_model;
GtkSorter *column_sorter; GtkSorter *column_sorter;
GtkSorter *sorter; GtkSorter *sorter;
@ -702,9 +701,8 @@ constructed (GObject *object)
g_signal_connect (rl->close_details_button, "clicked", g_signal_connect (rl->close_details_button, "clicked",
G_CALLBACK (close_details), rl); G_CALLBACK (close_details), rl);
root_model = load_resources (); rl->tree_model = gtk_tree_list_model_new (load_resources (),
rl->tree_model = gtk_tree_list_model_new (FALSE, FALSE,
root_model,
FALSE, FALSE,
create_model_for_object, create_model_for_object,
NULL, NULL,
@ -714,7 +712,6 @@ constructed (GObject *object)
sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter)); sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter));
sort_model = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (rl->tree_model)), sorter)); sort_model = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (rl->tree_model)), sorter));
rl->selection = gtk_single_selection_new (sort_model); rl->selection = gtk_single_selection_new (sort_model);
g_object_unref (root_model);
g_object_unref (sort_model); g_object_unref (sort_model);
gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection)); gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection));

View File

@ -746,12 +746,11 @@ main (int argc, char *argv[])
dirmodel = create_list_model_for_directory (root); dirmodel = create_list_model_for_directory (root);
g_object_unref (root); g_object_unref (root);
} }
tree = gtk_tree_list_model_new (FALSE, tree = gtk_tree_list_model_new (dirmodel,
dirmodel, FALSE,
TRUE, TRUE,
create_list_model_for_file_info, create_list_model_for_file_info,
NULL, NULL); NULL, NULL);
g_object_unref (dirmodel);
sorter = gtk_tree_list_row_sorter_new (g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (view)))); sorter = gtk_tree_list_row_sorter_new (g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (view))));
sort = gtk_sort_list_model_new (G_LIST_MODEL (tree), sorter); sort = gtk_sort_list_model_new (G_LIST_MODEL (tree), sorter);

View File

@ -191,8 +191,8 @@ create_child_model (gpointer item,
static GListModel * static GListModel *
create_tree_model (guint n, guint m) create_tree_model (guint n, guint m)
{ {
return G_LIST_MODEL (gtk_tree_list_model_new (FALSE, return G_LIST_MODEL (gtk_tree_list_model_new (create_model (0, n, m, TRUE),
create_model (0, n, m, TRUE), FALSE,
FALSE, FALSE,
create_child_model, create_child_model,
GUINT_TO_POINTER (m), NULL)); GUINT_TO_POINTER (m), NULL));

View File

@ -589,7 +589,6 @@ int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
GtkWidget *win, *vbox, *sw, *listview, *search_entry, *statusbar; GtkWidget *win, *vbox, *sw, *listview, *search_entry, *statusbar;
GListModel *dirmodel;
GtkTreeListModel *tree; GtkTreeListModel *tree;
GtkFilterListModel *filter; GtkFilterListModel *filter;
GtkFilter *custom_filter; GtkFilter *custom_filter;
@ -623,13 +622,11 @@ main (int argc, char *argv[])
root = g_file_new_for_commandline_arg (argv[1]); root = g_file_new_for_commandline_arg (argv[1]);
else else
root = g_file_new_for_path (g_get_current_dir ()); root = g_file_new_for_path (g_get_current_dir ());
dirmodel = create_list_model_for_directory (root); tree = gtk_tree_list_model_new (create_list_model_for_directory (root),
tree = gtk_tree_list_model_new (FALSE, FALSE,
dirmodel,
TRUE, TRUE,
create_list_model_for_file_info, create_list_model_for_file_info,
NULL, NULL); NULL, NULL);
g_object_unref (dirmodel);
g_object_unref (root); g_object_unref (root);
custom_filter = gtk_custom_filter_new (match_file, search_entry, NULL); custom_filter = gtk_custom_filter_new (match_file, search_entry, NULL);

View File

@ -170,7 +170,7 @@ new_model (guint size,
GtkTreeListModel *tree; GtkTreeListModel *tree;
GString *changes; GString *changes;
tree = gtk_tree_list_model_new (TRUE, G_LIST_MODEL (new_store (size, size, size)), expanded, create_sub_model_cb, NULL, NULL); tree = gtk_tree_list_model_new (G_LIST_MODEL (new_store (size, size, size)), TRUE, expanded, create_sub_model_cb, NULL, NULL);
changes = g_string_new (""); changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(tree), changes_quark, changes, free_changes); g_object_set_qdata_full (G_OBJECT(tree), changes_quark, changes, free_changes);
g_signal_connect (tree, "items-changed", G_CALLBACK (items_changed), changes); g_signal_connect (tree, "items-changed", G_CALLBACK (items_changed), changes);

View File

@ -158,8 +158,8 @@ new_child_model (gpointer item,
static GListModel * static GListModel *
new_model (guint size) new_model (guint size)
{ {
return G_LIST_MODEL (gtk_tree_list_model_new (FALSE, return G_LIST_MODEL (gtk_tree_list_model_new (G_LIST_MODEL (new_store (1, size, 1)),
G_LIST_MODEL (new_store (1, size, 1)), FALSE,
TRUE, TRUE,
new_child_model, new_child_model,
NULL, NULL)); NULL, NULL));