Compare commits

..

4 Commits

Author SHA1 Message Date
Matthias Clasen
b6d908b8aa selectionfiltermodel: Make constructor allow-none
We don't pay attention to item-type anymore, so
drop the item-type property and the _for_item_type()
constructor, and allow passing NULL to the regular
constructor.

We don't make this constructor transfer-full, since
the selection filter model is not a wrapping model
like the others. It is more like fork than a wrap.
2020-07-26 17:35:49 -04:00
Matthias Clasen
c659910a83 multiselection: Make constructor transfer full
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Also make the constructor return GtkMultiSelection *.

Update all callers.
2020-07-26 17:25:06 -04:00
Matthias Clasen
1af097455c singleselection: Make constructor transfer full
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Update all callers.
2020-07-26 17:16:15 -04:00
Matthias Clasen
6873f63987 noselection: Make constructor transfer full
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Update all callers.
2020-07-26 16:55:43 -04:00
22 changed files with 52 additions and 100 deletions

View File

@@ -462,7 +462,6 @@ do_listview_clocks (GtkWidget *do_widget)
{
GtkWidget *gridview, *sw;
GtkListItemFactory *factory;
GListModel *model;
GtkNoSelection *selection;
/* This is the normal window setup code every demo does */
@@ -489,12 +488,10 @@ do_listview_clocks (GtkWidget *do_widget)
gtk_scrollable_set_hscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
gtk_scrollable_set_vscroll_policy (GTK_SCROLLABLE (gridview), GTK_SCROLL_NATURAL);
model = create_clocks_model ();
selection = gtk_no_selection_new (model);
selection = gtk_no_selection_new (create_clocks_model ());
gtk_grid_view_set_model (GTK_GRID_VIEW (gridview), G_LIST_MODEL (selection));
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), gridview);
g_object_unref (selection);
g_object_unref (model);
}
if (!gtk_widget_get_visible (window))

View File

@@ -884,7 +884,7 @@ do_listview_colors (GtkWidget *do_widget)
sort_model = gtk_sort_list_model_new (gtk_color_list_new (0), NULL);
gtk_sort_list_model_set_incremental (sort_model, TRUE);
selection = GTK_MULTI_SELECTION (gtk_multi_selection_new (G_LIST_MODEL (sort_model)));
selection = gtk_multi_selection_new (G_LIST_MODEL (sort_model));
window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (window), "Colors");
@@ -970,7 +970,6 @@ do_listview_colors (GtkWidget *do_widget)
no_selection = G_LIST_MODEL (gtk_no_selection_new (selection_filter));
gtk_grid_view_set_model (GTK_GRID_VIEW (selection_view), no_selection);
g_object_unref (selection_filter);
g_object_unref (no_selection);
selection_info_toggle = gtk_toggle_button_new ();

View File

@@ -214,7 +214,6 @@ transform_settings_to_keys (GBinding *binding,
GtkSortListModel *sort_model;
GtkFilterListModel *filter_model;
GtkFilter *filter;
GtkNoSelection *selection_model;
char **keys;
guint i;
@@ -248,10 +247,7 @@ transform_settings_to_keys (GBinding *binding,
g_set_object (&current_filter, filter);
filter_model = gtk_filter_list_model_new (G_LIST_MODEL (sort_model), filter);
selection_model = gtk_no_selection_new (G_LIST_MODEL (filter_model));
g_object_unref (filter_model);
g_value_take_object (to_value, selection_model);
g_value_take_object (to_value, gtk_no_selection_new (G_LIST_MODEL (filter_model)));
return TRUE;
}
@@ -413,7 +409,6 @@ do_listview_settings (GtkWidget *do_widget)
columnview, NULL);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selection));
g_object_unref (selection);
g_object_unref (treemodel);
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"));

View File

@@ -281,7 +281,7 @@ GtkWidget *
create_weather_view (void)
{
GtkWidget *listview;
GListModel *model, *selection;
GListModel *selection;
GtkListItemFactory *factory;
factory = gtk_signal_list_item_factory_new ();
@@ -290,11 +290,9 @@ create_weather_view (void)
listview = gtk_list_view_new_with_factory (factory);
gtk_orientable_set_orientation (GTK_ORIENTABLE (listview), GTK_ORIENTATION_HORIZONTAL);
gtk_list_view_set_show_separators (GTK_LIST_VIEW (listview), TRUE);
model = create_weather_model ();
selection = G_LIST_MODEL (gtk_no_selection_new (model));
selection = G_LIST_MODEL (gtk_no_selection_new (create_weather_model ()));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), selection);
g_object_unref (selection);
g_object_unref (model);
return listview;
}

View File

@@ -226,7 +226,6 @@ do_listview_words (GtkWidget *do_widget)
g_signal_connect (filter_model, "notify::pending", G_CALLBACK (update_title_cb), progress);
update_title_cb (filter_model);
g_object_unref (filter_model);
}
if (!gtk_widget_get_visible (window))

View File

@@ -896,7 +896,7 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
listview = gtk_list_view_new ();
gtk_widget_set_size_request (listview, 140, -1);
model = G_LIST_MODEL (gtk_single_selection_new (G_LIST_MODEL (dialog->custom_paper_list)));
model = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (dialog->custom_paper_list))));
gtk_list_view_set_model (GTK_LIST_VIEW (listview), model);
g_signal_connect (model, "notify::selected", G_CALLBACK (selected_custom_paper_changed), dialog);
g_object_unref (model);

View File

@@ -668,7 +668,6 @@ gtk_drop_down_set_model (GtkDropDown *self,
filter_model = G_LIST_MODEL (gtk_filter_list_model_new (g_object_ref (model), NULL));
g_set_object (&self->filter_model, filter_model);
g_object_unref (filter_model);
update_filter (self);
@@ -677,7 +676,7 @@ gtk_drop_down_set_model (GtkDropDown *self,
gtk_list_view_set_model (GTK_LIST_VIEW (self->popup_list), selection);
g_object_unref (selection);
selection = G_LIST_MODEL (gtk_single_selection_new (model));
selection = G_LIST_MODEL (gtk_single_selection_new (g_object_ref (model)));
g_set_object (&self->selection, selection);
g_object_unref (selection);

View File

@@ -2130,7 +2130,7 @@ gtk_list_base_set_model (GtkListBase *self,
if (GTK_IS_SELECTION_MODEL (model))
selection_model = GTK_SELECTION_MODEL (g_object_ref (model));
else
selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (model));
selection_model = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (model)));
gtk_list_item_manager_set_model (priv->item_manager, selection_model);
gtk_list_base_set_anchor (self, 0, 0.0, GTK_PACK_START, 0.0, GTK_PACK_START);

View File

@@ -370,20 +370,27 @@ gtk_multi_selection_init (GtkMultiSelection *self)
/**
* gtk_multi_selection_new:
* @model: (transfer none): the #GListModel to manage
* @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
*
* Creates a new selection to handle @model.
*
* Returns: (transfer full) (type GtkMultiSelection): a new #GtkMultiSelection
* Returns: (transfer full): a new #GtkMultiSelection
**/
GListModel *
GtkMultiSelection *
gtk_multi_selection_new (GListModel *model)
{
GtkMultiSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_MULTI_SELECTION,
self = g_object_new (GTK_TYPE_MULTI_SELECTION,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**

View File

@@ -31,13 +31,13 @@ GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkMultiSelection, gtk_multi_selection, GTK, MULTI_SELECTION, GObject)
GDK_AVAILABLE_IN_ALL
GListModel * gtk_multi_selection_new (GListModel *model);
GtkMultiSelection * gtk_multi_selection_new (GListModel *model);
GDK_AVAILABLE_IN_ALL
GListModel * gtk_multi_selection_get_model (GtkMultiSelection *self);
GListModel * gtk_multi_selection_get_model (GtkMultiSelection *self);
GDK_AVAILABLE_IN_ALL
void gtk_multi_selection_set_model (GtkMultiSelection *self,
GListModel *model);
void gtk_multi_selection_set_model (GtkMultiSelection *self,
GListModel *model);
G_END_DECLS

View File

@@ -216,7 +216,7 @@ gtk_no_selection_init (GtkNoSelection *self)
/**
* gtk_no_selection_new:
* @model: (transfer none): the #GListModel to manage
* @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
*
* Creates a new selection to handle @model.
*
@@ -225,11 +225,18 @@ gtk_no_selection_init (GtkNoSelection *self)
GtkNoSelection *
gtk_no_selection_new (GListModel *model)
{
GtkNoSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_NO_SELECTION,
self = g_object_new (GTK_TYPE_NO_SELECTION,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**
@@ -253,8 +260,8 @@ gtk_no_selection_get_model (GtkNoSelection *self)
* @self: a #GtkNoSelection
* @model: (allow-none): A #GListModel to wrap
*
* Sets the model that @self should wrap. If @model is %NULL, this
* model will be empty.
* Sets the model that @self should wrap.
* If @model is %NULL, this model will be empty.
**/
void
gtk_no_selection_set_model (GtkNoSelection *self,

View File

@@ -837,7 +837,6 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
g_signal_connect (selection, "items-changed", G_CALLBACK (printer_added_cb), dialog);
g_signal_connect_swapped (selection, "notify::selected", G_CALLBACK (selected_printer_changed), dialog);
g_object_unref (selection);
g_object_unref (filtered);
gtk_print_load_custom_papers (dialog->custom_paper_list);

View File

@@ -37,7 +37,6 @@
enum {
PROP_0,
PROP_ITEM_TYPE,
PROP_MODEL,
NUM_PROPERTIES
};
@@ -46,7 +45,6 @@ struct _GtkSelectionFilterModel
{
GObject parent_instance;
GType item_type;
GtkSelectionModel *model;
GtkBitset *selection;
};
@@ -61,9 +59,7 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
static GType
gtk_selection_filter_model_get_item_type (GListModel *list)
{
GtkSelectionFilterModel *self = GTK_SELECTION_FILTER_MODEL (list);
return self->item_type;
return G_TYPE_OBJECT;
}
static guint
@@ -159,10 +155,6 @@ gtk_selection_filter_model_set_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
self->item_type = g_value_get_gtype (value);
break;
case PROP_MODEL:
gtk_selection_filter_model_set_model (self, g_value_get_object (value));
break;
@@ -183,10 +175,6 @@ gtk_selection_filter_model_get_property (GObject *object,
switch (prop_id)
{
case PROP_ITEM_TYPE:
g_value_set_gtype (value, self->item_type);
break;
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
@@ -229,18 +217,6 @@ gtk_selection_filter_model_class_init (GtkSelectionFilterModelClass *class)
gobject_class->get_property = gtk_selection_filter_model_get_property;
gobject_class->dispose = gtk_selection_filter_model_dispose;
/**
* GtkSelectionFilterModel:item-type:
*
* The #GType for elements of this object
*/
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type",
P_("Item type"),
P_("The type of elements of this object"),
G_TYPE_OBJECT,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkSelectionFilterModel:model:
*
@@ -263,7 +239,7 @@ gtk_selection_filter_model_init (GtkSelectionFilterModel *self)
/**
* gtk_selection_filter_model_new:
* @model: the selection model to filter
* @model: (allow-none) (transfer none): the selection model to filter, or %NULL
*
* Creates a new #GtkSelectionFilterModel that will include the
* selected items from the underlying selection model.
@@ -273,35 +249,8 @@ gtk_selection_filter_model_init (GtkSelectionFilterModel *self)
GtkSelectionFilterModel *
gtk_selection_filter_model_new (GtkSelectionModel *model)
{
GtkSelectionFilterModel *result;
g_return_val_if_fail (GTK_IS_SELECTION_MODEL (model), NULL);
result = g_object_new (GTK_TYPE_SELECTION_FILTER_MODEL,
"item-type", g_list_model_get_item_type (G_LIST_MODEL (model)),
"model", model,
NULL);
return result;
}
/**
* gtk_selection_filter_model_new_for_type:
* @item_type: the type of the items that will be returned
*
* Creates a new empty selection filter model set up to return items
* of type @item_type. It is up to the application to set a proper
* selection model to ensure the item type is matched.
*
* Returns: a new #GtkSelectionFilterModel
**/
GtkSelectionFilterModel *
gtk_selection_filter_model_new_for_type (GType item_type)
{
g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL);
return g_object_new (GTK_TYPE_SELECTION_FILTER_MODEL,
"item-type", item_type,
"model", model,
NULL);
}
@@ -325,8 +274,6 @@ gtk_selection_filter_model_set_model (GtkSelectionFilterModel *self,
g_return_if_fail (GTK_IS_SELECTION_FILTER_MODEL (self));
g_return_if_fail (model == NULL || GTK_IS_SELECTION_MODEL (model));
g_return_if_fail (model == NULL || g_type_is_a (g_list_model_get_item_type (G_LIST_MODEL (model)),
self->item_type));
if (self->model == model)
return;

View File

@@ -453,7 +453,7 @@ gtk_single_selection_init (GtkSingleSelection *self)
/**
* gtk_single_selection_new:
* @model: (transfer none): the #GListModel to manage
* @model: (allow-none) (transfer full): the #GListModel to manage, or %NULL
*
* Creates a new selection to handle @model.
*
@@ -462,11 +462,18 @@ gtk_single_selection_init (GtkSingleSelection *self)
GtkSingleSelection *
gtk_single_selection_new (GListModel *model)
{
GtkSingleSelection *self;
g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL);
return g_object_new (GTK_TYPE_SINGLE_SELECTION,
self = g_object_new (GTK_TYPE_SINGLE_SELECTION,
"model", model,
NULL);
/* consume the reference */
g_clear_object (&model);
return self;
}
/**

View File

@@ -400,7 +400,6 @@ constructed (GObject *object)
g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list)))));
model = G_LIST_MODEL (gtk_no_selection_new (sorted));
gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model);
g_object_unref (sorted);
g_object_unref (model);
}

View File

@@ -85,7 +85,7 @@ gtk_inspector_list_data_set_object (GtkInspectorListData *sl,
g_object_set (page, "visible", TRUE, NULL);
sl->object = G_LIST_MODEL (object);
selection = gtk_no_selection_new (sl->object);
selection = gtk_no_selection_new (g_object_ref (sl->object));
gtk_column_view_set_model (sl->view, G_LIST_MODEL (selection));
g_object_unref (selection);
}

View File

@@ -1304,7 +1304,7 @@ gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
create_model_for_object,
NULL,
NULL);
wt->priv->selection = gtk_single_selection_new (G_LIST_MODEL (wt->priv->tree_model));
wt->priv->selection = gtk_single_selection_new (g_object_ref (G_LIST_MODEL (wt->priv->tree_model)));
gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list),
G_LIST_MODEL (wt->priv->selection));
}

View File

@@ -633,7 +633,6 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl,
gtk_widget_show (GTK_WIDGET (pl));
g_object_unref (list);
g_object_unref (sorted);
return TRUE;
}

View File

@@ -1239,7 +1239,7 @@ gtk_inspector_recorder_init (GtkInspectorRecorder *recorder)
TRUE,
create_list_model_for_render_node_paintable,
NULL, NULL);
recorder->render_node_selection = gtk_single_selection_new (G_LIST_MODEL (recorder->render_node_model));
recorder->render_node_selection = gtk_single_selection_new (g_object_ref (G_LIST_MODEL (recorder->render_node_model)));
g_signal_connect (recorder->render_node_selection, "notify::selected-item", G_CALLBACK (render_node_list_selection_changed), recorder);
factory = gtk_signal_list_item_factory_new ();

View File

@@ -712,7 +712,6 @@ constructed (GObject *object)
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));
rl->selection = gtk_single_selection_new (sort_model);
g_object_unref (sort_model);
gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection));

View File

@@ -253,7 +253,7 @@ new_model (GListStore *store)
GtkSelectionModel *result;
GString *changes;
result = GTK_SELECTION_MODEL (gtk_multi_selection_new (G_LIST_MODEL (store)));
result = GTK_SELECTION_MODEL (gtk_multi_selection_new (g_object_ref (G_LIST_MODEL (store))));
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
@@ -615,6 +615,7 @@ test_selection_filter (void)
g_object_unref (store);
g_object_unref (selection);
g_object_unref (filter);
}
static void

View File

@@ -249,7 +249,7 @@ new_model (GListStore *store, gboolean autoselect, gboolean can_unselect)
GtkSelectionModel *result;
GString *changes;
result = GTK_SELECTION_MODEL (gtk_single_selection_new (G_LIST_MODEL (store)));
result = GTK_SELECTION_MODEL (gtk_single_selection_new (g_object_ref (G_LIST_MODEL (store))));
/* We want to return an empty selection unless autoselect is true,
* so undo the initial selection due to autoselect defaulting to TRUE.