[gtk/wip/otte/listmodels: 6/18] selectionfiltermodel: Add ::item-type and ::n-items
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listmodels: 6/18] selectionfiltermodel: Add ::item-type and ::n-items
- Date: Sat, 11 Jun 2022 05:35:51 +0000 (UTC)
commit 3e88a0a90adc9e42ef2107673626f5e056d948ab
Author: Benjamin Otte <otte redhat com>
Date: Sat Jun 11 04:51:41 2022 +0200
selectionfiltermodel: Add ::item-type and ::n-items
gtk/gtkselectionfiltermodel.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
---
diff --git a/gtk/gtkselectionfiltermodel.c b/gtk/gtkselectionfiltermodel.c
index 3745721d82..dc7a48fab6 100644
--- a/gtk/gtkselectionfiltermodel.c
+++ b/gtk/gtkselectionfiltermodel.c
@@ -34,7 +34,10 @@
enum {
PROP_0,
+ PROP_ITEM_TYPE,
PROP_MODEL,
+ PROP_N_ITEMS,
+
NUM_PROPERTIES
};
@@ -127,6 +130,8 @@ selection_filter_model_items_changed (GtkSelectionFilterModel *self,
if (sel_removed > 0 || sel_added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), sel_position, sel_removed, sel_added);
+ if (sel_removed != sel_added)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
@@ -178,10 +183,18 @@ gtk_selection_filter_model_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_ITEM_TYPE:
+ g_value_set_gtype (value, gtk_selection_filter_model_get_item_type (G_LIST_MODEL (self)));
+ break;
+
case PROP_MODEL:
g_value_set_object (value, self->model);
break;
+ case PROP_N_ITEMS:
+ g_value_set_uint (value, gtk_selection_filter_model_get_n_items (G_LIST_MODEL (self)));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -220,6 +233,18 @@ gtk_selection_filter_model_class_init (GtkSelectionFilterModelClass *class)
gobject_class->get_property = gtk_selection_filter_model_get_property;
gobject_class->dispose = gtk_selection_filter_model_dispose;
+ /**
+ * GtkSelectionFilterModel:item-type:
+ *
+ * The type of items. See [func@Gio.ListModel.get_item_type].
+ *
+ * Since: 4.8
+ **/
+ properties[PROP_ITEM_TYPE] =
+ g_param_spec_gtype ("item-type", NULL, NULL,
+ G_TYPE_OBJECT,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
/**
* GtkSelectionFilterModel:model: (attributes org.gtk.Property.get=gtk_selection_filter_model_get_model
org.gtk.Property.set=gtk_selection_filter_model_set_model)
*
@@ -230,6 +255,18 @@ gtk_selection_filter_model_class_init (GtkSelectionFilterModelClass *class)
GTK_TYPE_SELECTION_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GtkSelectionFilterModel:n-items:
+ *
+ * The number of items. See [func@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);
+
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@@ -300,6 +337,8 @@ gtk_selection_filter_model_set_model (GtkSelectionFilterModel *self,
if (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]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]