[glib/wip/otte/liststore-properties: 1/3] liststore: Add "n-items" property
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/otte/liststore-properties: 1/3] liststore: Add "n-items" property
- Date: Thu, 9 Jun 2022 15:08:55 +0000 (UTC)
commit 6b62d63d36a107a7465c4f578ba2892b4747fa87
Author: Benjamin Otte <otte redhat com>
Date: Wed Jun 8 18:19:01 2022 +0200
liststore: Add "n-items" property
gio/gliststore.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/gio/gliststore.c b/gio/gliststore.c
index 555b4f310f..e7dbbd38fe 100644
--- a/gio/gliststore.c
+++ b/gio/gliststore.c
@@ -64,6 +64,7 @@ enum
{
PROP_0,
PROP_ITEM_TYPE,
+ PROP_N_ITEMS,
N_PROPERTIES
};
@@ -89,6 +90,8 @@ g_list_store_items_changed (GListStore *store,
}
g_list_model_items_changed (G_LIST_MODEL (store), position, removed, added);
+ if (removed != added)
+ g_object_notify_by_pspec (G_OBJECT (store), properties[PROP_N_ITEMS]);
}
static void
@@ -115,6 +118,10 @@ g_list_store_get_property (GObject *object,
g_value_set_gtype (value, store->item_type);
break;
+ case PROP_N_ITEMS:
+ g_value_set_uint (value, g_sequence_get_length (store->items));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -157,10 +164,21 @@ g_list_store_class_init (GListStoreClass *klass)
*
* Since: 2.44
**/
- properties[PROP_ITEM_TYPE] =
+ properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", "", "", G_TYPE_OBJECT,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * GListStore:n-items:
+ *
+ * The number of items contained in this list store.
+ *
+ * Since: 2.74
+ **/
+ properties[PROP_N_ITEMS] =
+ g_param_spec_uint ("n-items", "", "", 0, G_MAXUINT, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]