diff options
author | Benjamin Otte <otte@redhat.com> | 2020-07-04 21:47:48 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2020-07-05 02:59:21 +0200 |
commit | 508073072822b83dccf3bc5aa642f488c967de52 (patch) | |
tree | 1ab4dd2aaab1ae3a7d1a4485f5dc4d5e9ef26a48 /gtk | |
parent | f75a3a0e95b31c84f41acc741d6dfb2028dbe6a2 (diff) | |
download | gtk+-508073072822b83dccf3bc5aa642f488c967de52.tar.gz |
listmodels: Stop respecting item-type
Simplify all view model APIs and always return G_TYPE_OBJECT as the
item-type for every model.
It turns out nobody uses item-type anyway.
So instead of adding lots of APIs, forcing people to think about it and
trying to figure out how to handle filter or map models that modify item
types, just having an easy life is a better approach.
All the models need to be able to deal with any type of object going
through anyway.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkcustompaperunixdialog.c | 2 | ||||
-rw-r--r-- | gtk/gtkfilterlistmodel.c | 52 | ||||
-rw-r--r-- | gtk/gtkfilterlistmodel.h | 2 | ||||
-rw-r--r-- | gtk/gtkflattenlistmodel.c | 46 | ||||
-rw-r--r-- | gtk/gtkflattenlistmodel.h | 3 | ||||
-rw-r--r-- | gtk/gtkfontchooserwidget.c | 2 | ||||
-rw-r--r-- | gtk/gtkmaplistmodel.c | 37 | ||||
-rw-r--r-- | gtk/gtkmaplistmodel.h | 3 | ||||
-rw-r--r-- | gtk/gtkmultiselection.c | 4 | ||||
-rw-r--r-- | gtk/gtknoselection.c | 4 | ||||
-rw-r--r-- | gtk/gtkpagesetupunixdialog.c | 4 | ||||
-rw-r--r-- | gtk/gtkprintunixdialog.c | 4 | ||||
-rw-r--r-- | gtk/gtkshortcutcontroller.c | 20 | ||||
-rw-r--r-- | gtk/gtkshortcutmanager.c | 4 | ||||
-rw-r--r-- | gtk/gtksingleselection.c | 4 | ||||
-rw-r--r-- | gtk/gtkslicelistmodel.c | 50 | ||||
-rw-r--r-- | gtk/gtkslicelistmodel.h | 2 | ||||
-rw-r--r-- | gtk/gtksortlistmodel.c | 55 | ||||
-rw-r--r-- | gtk/gtksortlistmodel.h | 3 | ||||
-rw-r--r-- | gtk/gtktreelistmodel.c | 12 | ||||
-rw-r--r-- | gtk/inspector/controllers.c | 4 | ||||
-rw-r--r-- | gtk/inspector/object-tree.c | 14 |
22 files changed, 50 insertions, 281 deletions
diff --git a/gtk/gtkcustompaperunixdialog.c b/gtk/gtkcustompaperunixdialog.c index 608a637c88..75e471689c 100644 --- a/gtk/gtkcustompaperunixdialog.c +++ b/gtk/gtkcustompaperunixdialog.c @@ -321,7 +321,7 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog) g_list_store_append (printer_list_list, printer_list); g_object_unref (printer_list); - full_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (printer_list_list))); + full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list))); g_object_unref (printer_list_list); filter = gtk_custom_filter_new (match_func, NULL, NULL); diff --git a/gtk/gtkfilterlistmodel.c b/gtk/gtkfilterlistmodel.c index af29154fcb..12a456ca8a 100644 --- a/gtk/gtkfilterlistmodel.c +++ b/gtk/gtkfilterlistmodel.c @@ -40,7 +40,6 @@ enum { PROP_0, PROP_FILTER, - PROP_ITEM_TYPE, PROP_MODEL, NUM_PROPERTIES }; @@ -63,7 +62,6 @@ struct _GtkFilterListModel { GObject parent_instance; - GType item_type; GListModel *model; GtkFilter *filter; GtkFilterMatch strictness; @@ -194,9 +192,7 @@ gtk_filter_list_model_get_nth (GtkRbTree *tree, static GType gtk_filter_list_model_get_item_type (GListModel *list) { - GtkFilterListModel *self = GTK_FILTER_LIST_MODEL (list); - - return self->item_type; + return G_TYPE_OBJECT; } static guint @@ -364,10 +360,6 @@ gtk_filter_list_model_set_property (GObject *object, gtk_filter_list_model_set_filter (self, g_value_get_object (value)); break; - case PROP_ITEM_TYPE: - self->item_type = g_value_get_gtype (value); - break; - case PROP_MODEL: gtk_filter_list_model_set_model (self, g_value_get_object (value)); break; @@ -392,10 +384,6 @@ gtk_filter_list_model_get_property (GObject *object, g_value_set_object (value, self->filter); break; - case PROP_ITEM_TYPE: - g_value_set_gtype (value, self->item_type); - break; - case PROP_MODEL: g_value_set_object (value, self->model); break; @@ -663,18 +651,6 @@ gtk_filter_list_model_class_init (GtkFilterListModelClass *class) GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); /** - * GtkFilterListModel: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); - - /** * GtkFilterListModel:model: * * The model being filtered @@ -697,7 +673,7 @@ gtk_filter_list_model_init (GtkFilterListModel *self) /** * gtk_filter_list_model_new: - * @model: the model to sort + * @model: (allow-none): the model to sort * @filter: (allow-none): filter or %NULL to not filter items * * Creates a new #GtkFilterListModel that will filter @model using the given @@ -711,10 +687,10 @@ gtk_filter_list_model_new (GListModel *model, { GtkFilterListModel *result; - g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (filter == NULL || GTK_IS_FILTER (filter), NULL); result = g_object_new (GTK_TYPE_FILTER_LIST_MODEL, - "item-type", g_list_model_get_item_type (model), "model", model, "filter", filter, NULL); @@ -723,26 +699,6 @@ gtk_filter_list_model_new (GListModel *model, } /** - * gtk_filter_list_model_new_for_type: - * @item_type: the type of the items that will be returned - * - * Creates a new empty filter list model set up to return items of type @item_type. - * It is up to the application to set a proper filter and model to ensure - * the item type is matched. - * - * Returns: a new #GtkFilterListModel - **/ -GtkFilterListModel * -gtk_filter_list_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_FILTER_LIST_MODEL, - "item-type", item_type, - NULL); -} - -/** * gtk_filter_list_model_set_filter: * @self: a #GtkFilterListModel * @filter: (allow-none) (transfer none): filter to use or %NULL to not filter items diff --git a/gtk/gtkfilterlistmodel.h b/gtk/gtkfilterlistmodel.h index fcb8dfab5c..c496f302c5 100644 --- a/gtk/gtkfilterlistmodel.h +++ b/gtk/gtkfilterlistmodel.h @@ -39,8 +39,6 @@ G_DECLARE_FINAL_TYPE (GtkFilterListModel, gtk_filter_list_model, GTK, FILTER_LIS GDK_AVAILABLE_IN_ALL GtkFilterListModel * gtk_filter_list_model_new (GListModel *model, GtkFilter *filter); -GDK_AVAILABLE_IN_ALL -GtkFilterListModel * gtk_filter_list_model_new_for_type (GType item_type); GDK_AVAILABLE_IN_ALL void gtk_filter_list_model_set_filter (GtkFilterListModel *self, diff --git a/gtk/gtkflattenlistmodel.c b/gtk/gtkflattenlistmodel.c index 78ea061a53..fe681b265e 100644 --- a/gtk/gtkflattenlistmodel.c +++ b/gtk/gtkflattenlistmodel.c @@ -40,7 +40,6 @@ enum { PROP_0, - PROP_ITEM_TYPE, PROP_MODEL, NUM_PROPERTIES }; @@ -64,7 +63,6 @@ struct _GtkFlattenListModel { GObject parent_instance; - GType item_type; GListModel *model; GtkRbTree *items; /* NULL if model == NULL */ }; @@ -157,9 +155,7 @@ gtk_flatten_list_model_get_nth_model (GtkRbTree *tree, static GType gtk_flatten_list_model_get_item_type (GListModel *list) { - GtkFlattenListModel *self = GTK_FLATTEN_LIST_MODEL (list); - - return self->item_type; + return G_TYPE_OBJECT; } static guint @@ -299,7 +295,6 @@ gtk_flatten_list_model_add_items (GtkFlattenListModel *self, { node = gtk_rb_tree_insert_before (self->items, after); node->model = g_list_model_get_item (self->model, position + i); - g_warn_if_fail (g_type_is_a (g_list_model_get_item_type (node->model), self->item_type)); g_signal_connect (node->model, "items-changed", G_CALLBACK (gtk_flatten_list_model_items_changed_cb), @@ -321,10 +316,6 @@ gtk_flatten_list_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_flatten_list_model_set_model (self, g_value_get_object (value)); break; @@ -345,10 +336,6 @@ gtk_flatten_list_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; @@ -417,18 +404,6 @@ gtk_flatten_list_model_class_init (GtkFlattenListModelClass *class) gobject_class->dispose = gtk_flatten_list_model_dispose; /** - * GtkFlattenListModel: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); - - /** * GtkFlattenListModel:model: * * The model being flattened @@ -450,26 +425,20 @@ gtk_flatten_list_model_init (GtkFlattenListModel *self) /** * gtk_flatten_list_model_new: - * @item_type: The type of items in the to-be-flattened models - * @model: (nullable) (transfer none): the item to be flattened + * @model: (nullable) (transfer none): the model to be flattened * - * Creates a new #GtkFlattenListModel that flattens @list. The - * models returned by @model must conform to the given @item_type, - * either by having an identical type or a subtype. + * Creates a new #GtkFlattenListModel that flattens @list. * * Returns: a new #GtkFlattenListModel **/ GtkFlattenListModel * -gtk_flatten_list_model_new (GType item_type, - GListModel *model) +gtk_flatten_list_model_new (GListModel *model) { GtkFlattenListModel *result; - g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL); g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); result = g_object_new (GTK_TYPE_FLATTEN_LIST_MODEL, - "item-type", item_type, "model", model, NULL); @@ -481,8 +450,7 @@ gtk_flatten_list_model_new (GType item_type, * @self: a #GtkFlattenListModel * @model: (nullable) (transfer none): the new model or %NULL * - * Sets a new model to be flattened. The model must contain items of - * #GListModel that conform to the item type of @self. + * Sets a new model to be flattened. **/ void gtk_flatten_list_model_set_model (GtkFlattenListModel *self, @@ -492,10 +460,6 @@ gtk_flatten_list_model_set_model (GtkFlattenListModel *self, g_return_if_fail (GTK_IS_FLATTEN_LIST_MODEL (self)); g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model)); - if (model) - { - g_return_if_fail (g_type_is_a (g_list_model_get_item_type (model), G_TYPE_LIST_MODEL)); - } if (self->model == model) return; diff --git a/gtk/gtkflattenlistmodel.h b/gtk/gtkflattenlistmodel.h index ec1eaaa84e..c934674ff3 100644 --- a/gtk/gtkflattenlistmodel.h +++ b/gtk/gtkflattenlistmodel.h @@ -36,8 +36,7 @@ GDK_AVAILABLE_IN_ALL G_DECLARE_FINAL_TYPE (GtkFlattenListModel, gtk_flatten_list_model, GTK, FLATTEN_LIST_MODEL, GObject) GDK_AVAILABLE_IN_ALL -GtkFlattenListModel * gtk_flatten_list_model_new (GType item_type, - GListModel *model); +GtkFlattenListModel * gtk_flatten_list_model_new (GListModel *model); GDK_AVAILABLE_IN_ALL void gtk_flatten_list_model_set_model (GtkFlattenListModel *self, diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index 1d4cd53aa8..42101f29d3 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -784,7 +784,7 @@ update_fontlist (GtkFontChooserWidget *self) if ((self->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0) model = g_object_ref (G_LIST_MODEL (fontmap)); else - model = G_LIST_MODEL (gtk_flatten_list_model_new (PANGO_TYPE_FONT_FACE, G_LIST_MODEL (fontmap))); + model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (fontmap))); gtk_filter_list_model_set_model (self->filter_model, model); g_object_unref (model); } diff --git a/gtk/gtkmaplistmodel.c b/gtk/gtkmaplistmodel.c index b77906fcc9..ea43269c07 100644 --- a/gtk/gtkmaplistmodel.c +++ b/gtk/gtkmaplistmodel.c @@ -63,7 +63,6 @@ enum { PROP_0, PROP_HAS_MAP, - PROP_ITEM_TYPE, PROP_MODEL, NUM_PROPERTIES }; @@ -86,7 +85,6 @@ struct _GtkMapListModel { GObject parent_instance; - GType item_type; GListModel *model; GtkMapListModelMapFunc map_func; gpointer user_data; @@ -145,9 +143,7 @@ gtk_map_list_model_get_nth (GtkRbTree *tree, static GType gtk_map_list_model_get_item_type (GListModel *list) { - GtkMapListModel *self = GTK_MAP_LIST_MODEL (list); - - return self->item_type; + return G_TYPE_OBJECT; } static guint @@ -199,11 +195,6 @@ gtk_map_list_model_get_item (GListModel *list, } node->item = self->map_func (g_list_model_get_item (self->model, position), self->user_data); - if (!G_TYPE_CHECK_INSTANCE_TYPE (node->item, self->item_type)) - { - g_critical ("Map function returned a %s, but it is not a subtype of the model's type %s", - G_OBJECT_TYPE_NAME (node->item), g_type_name (self->item_type)); - } g_object_add_weak_pointer (node->item, &node->item); return node->item; @@ -293,10 +284,6 @@ gtk_map_list_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_map_list_model_set_model (self, g_value_get_object (value)); break; @@ -321,10 +308,6 @@ gtk_map_list_model_get_property (GObject *object, g_value_set_boolean (value, self->items != NULL); break; - case PROP_ITEM_TYPE: - g_value_set_gtype (value, self->item_type); - break; - case PROP_MODEL: g_value_set_object (value, self->model); break; @@ -383,18 +366,6 @@ gtk_map_list_model_class_init (GtkMapListModelClass *class) GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY); /** - * GtkMapListModel: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); - - /** * GtkMapListModel:model: * * The model being mapped @@ -441,7 +412,6 @@ gtk_map_list_model_augment (GtkRbTree *map, /** * gtk_map_list_model_new: - * @item_type: the #GType to use as the model's item type * @model: (allow-none): The model to map or %NULL for none * @map_func: (allow-none): map function or %NULL to not map items * @user_data: (closure): user data passed to @map_func @@ -452,19 +422,16 @@ gtk_map_list_model_augment (GtkRbTree *map, * Returns: a new #GtkMapListModel **/ GtkMapListModel * -gtk_map_list_model_new (GType item_type, - GListModel *model, +gtk_map_list_model_new (GListModel *model, GtkMapListModelMapFunc map_func, gpointer user_data, GDestroyNotify user_destroy) { GtkMapListModel *result; - g_return_val_if_fail (g_type_is_a (item_type, G_TYPE_OBJECT), NULL); g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); result = g_object_new (GTK_TYPE_MAP_LIST_MODEL, - "item-type", item_type, "model", model, NULL); diff --git a/gtk/gtkmaplistmodel.h b/gtk/gtkmaplistmodel.h index f0ddcc9524..85a39823ab 100644 --- a/gtk/gtkmaplistmodel.h +++ b/gtk/gtkmaplistmodel.h @@ -53,8 +53,7 @@ G_DECLARE_FINAL_TYPE (GtkMapListModel, gtk_map_list_model, GTK, MAP_LIST_MODEL, typedef gpointer (* GtkMapListModelMapFunc) (gpointer item, gpointer user_data); GDK_AVAILABLE_IN_ALL -GtkMapListModel * gtk_map_list_model_new (GType item_type, - GListModel *model, +GtkMapListModel * gtk_map_list_model_new (GListModel *model, GtkMapListModelMapFunc map_func, gpointer user_data, GDestroyNotify user_destroy); diff --git a/gtk/gtkmultiselection.c b/gtk/gtkmultiselection.c index e8bd0759ef..ad6d3857de 100644 --- a/gtk/gtkmultiselection.c +++ b/gtk/gtkmultiselection.c @@ -62,9 +62,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, }; static GType gtk_multi_selection_get_item_type (GListModel *list) { - GtkMultiSelection *self = GTK_MULTI_SELECTION (list); - - return g_list_model_get_item_type (self->model); + return G_TYPE_OBJECT; } static guint diff --git a/gtk/gtknoselection.c b/gtk/gtknoselection.c index 72ace9a5a5..652b148735 100644 --- a/gtk/gtknoselection.c +++ b/gtk/gtknoselection.c @@ -60,9 +60,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, }; static GType gtk_no_selection_get_item_type (GListModel *list) { - GtkNoSelection *self = GTK_NO_SELECTION (list); - - return g_list_model_get_item_type (self->model); + return G_TYPE_OBJECT; } static guint diff --git a/gtk/gtkpagesetupunixdialog.c b/gtk/gtkpagesetupunixdialog.c index 5e2679affd..2e353c0033 100644 --- a/gtk/gtkpagesetupunixdialog.c +++ b/gtk/gtkpagesetupunixdialog.c @@ -306,7 +306,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog) g_list_store_append (store, dialog->page_setup_list); g_list_store_append (store, dialog->custom_paper_list); g_list_store_append (store, dialog->manage_papers_list); - paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PAGE_SETUP, G_LIST_MODEL (store))); + paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store))); gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list); g_object_unref (store); g_object_unref (paper_size_list); @@ -321,7 +321,7 @@ gtk_page_setup_unix_dialog_init (GtkPageSetupUnixDialog *dialog) g_list_store_append (printer_list_list, printer_list); g_object_unref (printer_list); - full_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (printer_list_list))); + full_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (printer_list_list))); filter = gtk_custom_filter_new (match_func, NULL, NULL); dialog->printer_list = G_LIST_MODEL (gtk_filter_list_model_new (full_list, filter)); diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c index 37a9e58e6f..dab4548b49 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -806,7 +806,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog) g_list_store_append (store, dialog->page_setup_list); g_list_store_append (store, dialog->custom_paper_list); g_list_store_append (store, dialog->manage_papers_list); - paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PAGE_SETUP, G_LIST_MODEL (store))); + paper_size_list = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (store))); gtk_drop_down_set_model (GTK_DROP_DOWN (dialog->paper_size_combo), paper_size_list); g_object_unref (store); g_object_unref (paper_size_list); @@ -1056,7 +1056,7 @@ load_print_backends (GtkPrintUnixDialog *dialog) g_list_store_append (lists, gtk_print_backend_get_printers (backend)); } - model = G_LIST_MODEL (gtk_flatten_list_model_new (GTK_TYPE_PRINTER, G_LIST_MODEL (lists))); + model = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (lists))); g_object_unref (lists); diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c index 19c3d793dd..1b995f5098 100644 --- a/gtk/gtkshortcutcontroller.c +++ b/gtk/gtkshortcutcontroller.c @@ -110,7 +110,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, }; static GType gtk_shortcut_controller_list_model_get_item_type (GListModel *list) { - return GTK_TYPE_SHORTCUT; + return G_TYPE_OBJECT; } static guint @@ -198,12 +198,6 @@ gtk_shortcut_controller_set_property (GObject *object, case PROP_MODEL: { GListModel *model = g_value_get_object (value); - if (model && g_list_model_get_item_type (model) != GTK_TYPE_SHORTCUT) - { - g_warning ("Setting a model with type '%s' on a shortcut controller that requires 'GtkShortcut'", - g_type_name (g_list_model_get_item_type (model))); - model = NULL; - } if (model == NULL) { self->shortcuts = G_LIST_MODEL (g_list_store_new (GTK_TYPE_SHORTCUT)); @@ -309,6 +303,11 @@ gtk_shortcut_controller_run_controllers (GtkEventController *controller, index = (self->last_activated + 1 + i) % g_list_model_get_n_items (self->shortcuts); shortcut = g_list_model_get_item (self->shortcuts, index); + if (!GTK_IS_SHORTCUT (shortcut)) + { + g_object_unref (shortcut); + continue; + } switch (gtk_shortcut_trigger_trigger (gtk_shortcut_get_trigger (shortcut), event, enable_mnemonics)) { @@ -484,7 +483,8 @@ gtk_shortcut_controller_set_widget (GtkEventController *controller, for (i = 0, p = g_list_model_get_n_items (G_LIST_MODEL (controller)); i < p; i++) { GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i); - update_accel (shortcut, widget, TRUE); + if (GTK_IS_SHORTCUT (shortcut)) + update_accel (shortcut, widget, TRUE); g_object_unref (shortcut); } @@ -506,7 +506,8 @@ gtk_shortcut_controller_unset_widget (GtkEventController *controller) for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (controller)); i++) { GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i); - update_accel (shortcut, widget, FALSE); + if (GTK_IS_SHORTCUT (shortcut)) + update_accel (shortcut, widget, FALSE); g_object_unref (shortcut); } #endif @@ -697,7 +698,6 @@ GtkEventController * gtk_shortcut_controller_new_for_model (GListModel *model) { g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL); - g_return_val_if_fail (g_list_model_get_item_type (model) == GTK_TYPE_SHORTCUT, NULL); return g_object_new (GTK_TYPE_SHORTCUT_CONTROLLER, "model", model, diff --git a/gtk/gtkshortcutmanager.c b/gtk/gtkshortcutmanager.c index 9aa3577703..a6f2559b1d 100644 --- a/gtk/gtkshortcutmanager.c +++ b/gtk/gtkshortcutmanager.c @@ -49,7 +49,7 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget) GtkEventController *controller; store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER); - model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store)); + model = gtk_flatten_list_model_new (G_LIST_MODEL (store)); g_object_unref (store); g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-bubble", model, g_object_unref); controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model)); @@ -57,7 +57,7 @@ gtk_shortcut_manager_create_controllers (GtkWidget *widget) gtk_widget_add_controller (widget, controller); store = g_list_store_new (GTK_TYPE_SHORTCUT_CONTROLLER); - model = gtk_flatten_list_model_new (GTK_TYPE_SHORTCUT, G_LIST_MODEL (store)); + model = gtk_flatten_list_model_new (G_LIST_MODEL (store)); g_object_unref (store); g_object_set_data_full (G_OBJECT (widget), "gtk-shortcut-manager-capture", model, g_object_unref); controller = gtk_shortcut_controller_new_for_model (G_LIST_MODEL (model)); diff --git a/gtk/gtksingleselection.c b/gtk/gtksingleselection.c index bd35aed782..70f0beab27 100644 --- a/gtk/gtksingleselection.c +++ b/gtk/gtksingleselection.c @@ -72,9 +72,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, }; static GType gtk_single_selection_get_item_type (GListModel *list) { - GtkSingleSelection *self = GTK_SINGLE_SELECTION (list); - - return g_list_model_get_item_type (self->model); + return G_TYPE_OBJECT; } static guint diff --git a/gtk/gtkslicelistmodel.c b/gtk/gtkslicelistmodel.c index d002252fff..8d0273c037 100644 --- a/gtk/gtkslicelistmodel.c +++ b/gtk/gtkslicelistmodel.c @@ -41,7 +41,6 @@ enum { PROP_0, - PROP_ITEM_TYPE, PROP_MODEL, PROP_OFFSET, PROP_SIZE, @@ -52,7 +51,6 @@ struct _GtkSliceListModel { GObject parent_instance; - GType item_type; GListModel *model; guint offset; guint size; @@ -70,9 +68,7 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, }; static GType gtk_slice_list_model_get_item_type (GListModel *list) { - GtkSliceListModel *self = GTK_SLICE_LIST_MODEL (list); - - return self->item_type; + return G_TYPE_OBJECT; } static guint @@ -182,10 +178,6 @@ gtk_slice_list_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_slice_list_model_set_model (self, g_value_get_object (value)); break; @@ -214,10 +206,6 @@ gtk_slice_list_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; @@ -266,18 +254,6 @@ gtk_slice_list_model_class_init (GtkSliceListModelClass *class) gobject_class->dispose = gtk_slice_list_model_dispose; /** - * GtkSliceListModel: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); - - /** * GtkSliceListModel:model: * * Child model to take slice from @@ -324,7 +300,7 @@ gtk_slice_list_model_init (GtkSliceListModel *self) /** * gtk_slice_list_model_new: - * @model: (transfer none): The model to use + * @model: (transfer none) (allow-none): The model to use * @offset: the offset of the slice * @size: maximum size of the slice * @@ -338,10 +314,9 @@ gtk_slice_list_model_new (GListModel *model, guint offset, guint size) { - g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); return g_object_new (GTK_TYPE_SLICE_LIST_MODEL, - "item-type", g_list_model_get_item_type (model), "model", model, "offset", offset, "size", size, @@ -349,25 +324,6 @@ gtk_slice_list_model_new (GListModel *model, } /** - * gtk_slice_list_model_new_for_type: - * @item_type: the type of items - * - * Creates a new empty #GtkSliceListModel for the given @item_type that - * can be set up later. - * - * Returns: a new empty #GtkSliceListModel - **/ -GtkSliceListModel * -gtk_slice_list_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_SLICE_LIST_MODEL, - "item-type", item_type, - NULL); -} - -/** * gtk_slice_list_model_set_model: * @self: a #GtkSliceListModel * @model: (allow-none): The model to be sliced diff --git a/gtk/gtkslicelistmodel.h b/gtk/gtkslicelistmodel.h index 837e67ef7a..d1b0cd8edc 100644 --- a/gtk/gtkslicelistmodel.h +++ b/gtk/gtkslicelistmodel.h @@ -40,8 +40,6 @@ GDK_AVAILABLE_IN_ALL GtkSliceListModel * gtk_slice_list_model_new (GListModel *model, guint offset, guint size); -GDK_AVAILABLE_IN_ALL -GtkSliceListModel * gtk_slice_list_model_new_for_type (GType item_type); GDK_AVAILABLE_IN_ALL void gtk_slice_list_model_set_model (GtkSliceListModel *self, diff --git a/gtk/gtksortlistmodel.c b/gtk/gtksortlistmodel.c index 0406d1e86f..06e1c6f3b2 100644 --- a/gtk/gtksortlistmodel.c +++ b/gtk/gtksortlistmodel.c @@ -42,7 +42,6 @@ enum { PROP_0, - PROP_ITEM_TYPE, PROP_MODEL, PROP_SORTER, NUM_PROPERTIES @@ -54,7 +53,6 @@ struct _GtkSortListModel { GObject parent_instance; - GType item_type; GListModel *model; GtkSorter *sorter; @@ -89,9 +87,7 @@ gtk_sort_list_entry_free (gpointer data) static GType gtk_sort_list_model_get_item_type (GListModel *list) { - GtkSortListModel *self = GTK_SORT_LIST_MODEL (list); - - return self->item_type; + return G_TYPE_OBJECT; } static guint @@ -262,10 +258,6 @@ gtk_sort_list_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_sort_list_model_set_model (self, g_value_get_object (value)); break; @@ -290,10 +282,6 @@ gtk_sort_list_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; @@ -406,18 +394,6 @@ gtk_sort_list_model_class_init (GtkSortListModelClass *class) GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); /** - * GtkSortListModel:item-type: - * - * The #GType for items of this model - */ - properties[PROP_ITEM_TYPE] = - g_param_spec_gtype ("item-type", - P_("Item type"), - P_("The type of items of this list"), - G_TYPE_OBJECT, - GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY); - - /** * GtkSortListModel:model: * * The model being sorted @@ -439,7 +415,7 @@ gtk_sort_list_model_init (GtkSortListModel *self) /** * gtk_sort_list_model_new: - * @model: the model to sort + * @model: (allow-none): the model to sort * @sorter: (allow-none): the #GtkSorter to sort @model with * * Creates a new sort list model that uses the @sorter to sort @model. @@ -452,11 +428,10 @@ gtk_sort_list_model_new (GListModel *model, { GtkSortListModel *result; - g_return_val_if_fail (G_IS_LIST_MODEL (model), NULL); + g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL); g_return_val_if_fail (sorter == NULL || GTK_IS_SORTER (sorter), NULL); result = g_object_new (GTK_TYPE_SORT_LIST_MODEL, - "item-type", g_list_model_get_item_type (model), "model", model, "sorter", sorter, NULL); @@ -465,26 +440,6 @@ gtk_sort_list_model_new (GListModel *model, } /** - * gtk_sort_list_model_new_for_type: - * @item_type: the type of the items that will be returned - * - * Creates a new empty sort list model set up to return items of type @item_type. - * It is up to the application to set a proper sort function and model to ensure - * the item type is matched. - * - * Returns: a new #GtkSortListModel - **/ -GtkSortListModel * -gtk_sort_list_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_SORT_LIST_MODEL, - "item-type", item_type, - NULL); -} - -/** * gtk_sort_list_model_set_model: * @self: a #GtkSortListModel * @model: (allow-none): The model to be sorted @@ -500,10 +455,6 @@ gtk_sort_list_model_set_model (GtkSortListModel *self, g_return_if_fail (GTK_IS_SORT_LIST_MODEL (self)); g_return_if_fail (model == NULL || G_IS_LIST_MODEL (model)); - if (model) - { - g_return_if_fail (g_type_is_a (g_list_model_get_item_type (model), self->item_type)); - } if (self->model == model) return; diff --git a/gtk/gtksortlistmodel.h b/gtk/gtksortlistmodel.h index 3e009502e2..b78029af2f 100644 --- a/gtk/gtksortlistmodel.h +++ b/gtk/gtksortlistmodel.h @@ -41,9 +41,6 @@ GDK_AVAILABLE_IN_ALL GtkSortListModel * gtk_sort_list_model_new (GListModel *model, GtkSorter *sorter); GDK_AVAILABLE_IN_ALL -GtkSortListModel * gtk_sort_list_model_new_for_type (GType item_type); - -GDK_AVAILABLE_IN_ALL void gtk_sort_list_model_set_sorter (GtkSortListModel *self, GtkSorter *sorter); GDK_AVAILABLE_IN_ALL diff --git a/gtk/gtktreelistmodel.c b/gtk/gtktreelistmodel.c index 246d9f2eb7..4311acb9d3 100644 --- a/gtk/gtktreelistmodel.c +++ b/gtk/gtktreelistmodel.c @@ -533,16 +533,6 @@ gtk_tree_list_model_expand_node (GtkTreeListModel *self, if (model == NULL) return 0; - if (!g_type_is_a (g_list_model_get_item_type (model), g_list_model_get_item_type (self->root_node.model))) - { - g_critical ("The GtkTreeListModelCreateModelFunc for %p returned a model with item type \"%s\" " - "but \"%s\" is required.", - self, - g_type_name (g_list_model_get_item_type (model)), - g_type_name (g_list_model_get_item_type (self->root_node.model))); - return 0; - } - gtk_tree_list_model_init_node (self, node, model); tree_node_mark_dirty (node); @@ -576,7 +566,7 @@ gtk_tree_list_model_get_item_type (GListModel *list) GtkTreeListModel *self = GTK_TREE_LIST_MODEL (list); if (self->passthrough) - return g_list_model_get_item_type (self->root_node.model); + return G_TYPE_OBJECT; else return GTK_TYPE_TREE_LIST_ROW; } diff --git a/gtk/inspector/controllers.c b/gtk/inspector/controllers.c index d20bef493b..0eae1caafd 100644 --- a/gtk/inspector/controllers.c +++ b/gtk/inspector/controllers.c @@ -245,10 +245,10 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self, self->model = gtk_property_lookup_list_model_new (GTK_TYPE_WIDGET, "parent"); gtk_property_lookup_list_model_set_object (self->model, object); - map_model = gtk_map_list_model_new (G_TYPE_LIST_MODEL, G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL); + map_model = gtk_map_list_model_new (G_LIST_MODEL (self->model), map_to_controllers, NULL, NULL); g_object_unref (self->model); - flatten_model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, G_LIST_MODEL (map_model)); + flatten_model = gtk_flatten_list_model_new (G_LIST_MODEL (map_model)); sorter = gtk_custom_sorter_new (compare_controllers, NULL, NULL); sort_model = gtk_sort_list_model_new (G_LIST_MODEL (flatten_model), sorter); diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c index add6da624c..44d8cf0fc3 100644 --- a/gtk/inspector/object-tree.c +++ b/gtk/inspector/object-tree.c @@ -130,7 +130,7 @@ object_tree_widget_get_children (GObject *object) g_list_store_append (list, sublist); g_object_unref (sublist); - flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list)); + flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list)); g_object_unref (list); return G_LIST_MODEL (flatten); @@ -225,7 +225,7 @@ list_model_for_properties (GObject *object, g_object_unref (tmp); } - result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (concat))); + result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (concat))); g_object_unref (concat); return result; } @@ -330,7 +330,7 @@ object_tree_tree_view_get_children (GObject *object) g_object_unref (selection); g_list_store_append (result_list, columns); g_object_unref (columns); - result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list)); + result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list)); g_object_unref (result_list); return G_LIST_MODEL (result); @@ -353,7 +353,7 @@ object_tree_column_view_get_children (GObject *object) g_list_store_append (result_list, sublist); g_object_unref (sublist); - result = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list)); + result = gtk_flatten_list_model_new (G_LIST_MODEL (result_list)); g_object_unref (result_list); return G_LIST_MODEL (result); @@ -640,7 +640,7 @@ object_get_children (GObject *object) if (result_list) { - result = G_LIST_MODEL (gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (result_list))); + result = G_LIST_MODEL (gtk_flatten_list_model_new (G_LIST_MODEL (result_list))); g_object_unref (result_list); } @@ -1179,7 +1179,7 @@ create_root_model (GdkDisplay *display) g_list_store_append (list, special); g_object_unref (special); - filter = gtk_filter_list_model_new_for_type (G_TYPE_OBJECT); + filter = gtk_filter_list_model_new (NULL, NULL); custom_filter = gtk_custom_filter_new (toplevel_filter_func, display, NULL); gtk_filter_list_model_set_filter (filter, custom_filter); @@ -1187,7 +1187,7 @@ create_root_model (GdkDisplay *display) g_list_store_append (list, filter); g_object_unref (filter); - flatten = gtk_flatten_list_model_new (G_TYPE_OBJECT, G_LIST_MODEL (list)); + flatten = gtk_flatten_list_model_new (G_LIST_MODEL (list)); g_object_unref (list); return G_LIST_MODEL (flatten); } |