liststore: Add "n-items" property

This commit is contained in:
Benjamin Otte 2022-06-08 18:19:01 +02:00
parent 9b55841d78
commit 6b62d63d36

View File

@ -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);
}