summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2022-06-11 04:52:34 +0200
committerBenjamin Otte <otte@redhat.com>2022-06-11 08:25:18 +0200
commit67e336992f5f178fc8530e9753323c04ea906934 (patch)
tree8db64747c72a04ebf70cfc88b497bdd633c906ce /gtk
parente1845f5e90bb73320e911adb030831d9dfe8170f (diff)
downloadgtk+-67e336992f5f178fc8530e9753323c04ea906934.tar.gz
propertylookuplistmodel: Add ::item-type and ::n-items
With tests!
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkpropertylookuplistmodel.c23
1 files changed, 22 insertions, 1 deletions
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,7 +373,7 @@ 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,
@@ -374,6 +381,18 @@ gtk_property_lookup_list_model_class_init (GtkPropertyLookupListModelClass *klas
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:
*
* Name of the property used for lookups
@@ -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