From 67e336992f5f178fc8530e9753323c04ea906934 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 11 Jun 2022 04:52:34 +0200 Subject: propertylookuplistmodel: Add ::item-type and ::n-items With tests! --- gtk/gtkpropertylookuplistmodel.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'gtk') diff --git a/gtk/gtkpropertylookuplistmodel.c b/gtk/gtkpropertylookuplistmodel.c index 3d5038d87a..222383140e 100644 --- a/gtk/gtkpropertylookuplistmodel.c +++ b/gtk/gtkpropertylookuplistmodel.c @@ -39,6 +39,7 @@ enum { PROP_0, PROP_ITEM_TYPE, + PROP_N_ITEMS, PROP_OBJECT, PROP_PROPERTY, NUM_PROPERTIES @@ -184,6 +185,8 @@ gtk_property_lookup_list_model_notify_cb (GObject *object, if (removed > 0 || added > 0) g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added); + if (removed != added) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]); } static guint @@ -318,6 +321,10 @@ gtk_property_lookup_list_model_get_property (GObject *object, g_value_set_gtype (value, self->item_type); break; + case PROP_N_ITEMS: + g_value_set_uint (value, gtk_property_lookup_list_model_get_n_items (G_LIST_MODEL (self))); + break; + case PROP_OBJECT: g_value_set_object (value, gtk_property_lookup_list_model_get_object (self)); break; @@ -366,13 +373,25 @@ gtk_property_lookup_list_model_class_init (GtkPropertyLookupListModelClass *klas /** * GtkPropertyLookupListModel:item-type: * - * The `GType` for elements of this object + * The `GType` for elements of this object. See [method@Gio.ListModel.get_item_type]. */ properties[PROP_ITEM_TYPE] = g_param_spec_gtype ("item-type", NULL, NULL, G_TYPE_OBJECT, GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY); + /** + * GtkPropertyLookupListModel:n-items: + * + * The number of items. See [method@Gio.ListModel.get_n_items]. + * + * Since: 4.8 + **/ + properties[PROP_N_ITEMS] = + g_param_spec_uint ("n-items", NULL, NULL, + 0, G_MAXUINT, 0, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + /** * GtkPropertyLookupListModel:property: * @@ -456,6 +475,8 @@ gtk_property_lookup_list_model_set_object (GtkPropertyLookupListModel *self, g_assert (removed != 0 || added != 0); g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added); + if (removed != added) + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]); } gpointer -- cgit v1.2.1