summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2022-06-11 04:49:17 +0200
committerBenjamin Otte <otte@redhat.com>2022-06-11 08:25:16 +0200
commit3fca865625c3ebdde07bd277fd5696d798a9f5f1 (patch)
tree3d5a741fcb8b8df8957c4f296c5a9f37a1523639 /gtk
parentbf8b26aa27016195b2f25b588aaa34919544b904 (diff)
downloadgtk+-3fca865625c3ebdde07bd277fd5696d798a9f5f1.tar.gz
slicelistmodel: Add ::item-type and ::n-items
With tests!
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkslicelistmodel.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/gtk/gtkslicelistmodel.c b/gtk/gtkslicelistmodel.c
index 3af75754ed..1d83f44f47 100644
--- a/gtk/gtkslicelistmodel.c
+++ b/gtk/gtkslicelistmodel.c
@@ -38,7 +38,9 @@
enum {
PROP_0,
+ PROP_ITEM_TYPE,
PROP_MODEL,
+ PROP_N_ITEMS,
PROP_OFFSET,
PROP_SIZE,
NUM_PROPERTIES
@@ -162,6 +164,8 @@ gtk_slice_list_model_items_changed_cb (GListModel *model,
n_before = CLAMP (n_before, self->offset, self->offset + self->size) - self->offset;
g_list_model_items_changed (G_LIST_MODEL (self), skip, n_before - skip, n_after - skip);
+ if (n_before != n_after)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
}
@@ -203,10 +207,18 @@ gtk_slice_list_model_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_ITEM_TYPE:
+ g_value_set_gtype (value, gtk_slice_list_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_slice_list_model_get_n_items (G_LIST_MODEL (self)));
+ break;
+
case PROP_OFFSET:
g_value_set_uint (value, self->offset);
break;
@@ -251,6 +263,18 @@ gtk_slice_list_model_class_init (GtkSliceListModelClass *class)
gobject_class->dispose = gtk_slice_list_model_dispose;
/**
+ * GtkSliceListModel:item-type:
+ *
+ * The type of items. See [method@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);
+
+ /**
* GtkSliceListModel:model: (attributes org.gtk.Property.get=gtk_slice_list_model_get_model org.gtk.Property.set=gtk_slice_list_model_set_model)
*
* Child model to take slice from.
@@ -261,6 +285,18 @@ gtk_slice_list_model_class_init (GtkSliceListModelClass *class)
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
+ * GtkSliceListModel: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);
+
+ /**
* GtkSliceListModel:offset: (attributes org.gtk.Property.get=gtk_slice_list_model_get_offset org.gtk.Property.set=gtk_slice_list_model_set_offset)
*
* Offset of slice.
@@ -360,6 +396,8 @@ gtk_slice_list_model_set_model (GtkSliceListModel *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]);
}
@@ -409,6 +447,8 @@ gtk_slice_list_model_set_offset (GtkSliceListModel *self,
if (before > 0 || after > 0)
g_list_model_items_changed (G_LIST_MODEL (self), 0, before, after);
+ if (before != after)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_OFFSET]);
}
@@ -458,9 +498,15 @@ gtk_slice_list_model_set_size (GtkSliceListModel *self,
after = g_list_model_get_n_items (G_LIST_MODEL (self));
if (before > after)
- g_list_model_items_changed (G_LIST_MODEL (self), after, before - after, 0);
+ {
+ g_list_model_items_changed (G_LIST_MODEL (self), after, before - after, 0);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
+ }
else if (before < after)
- g_list_model_items_changed (G_LIST_MODEL (self), before, 0, after - before);
+ {
+ g_list_model_items_changed (G_LIST_MODEL (self), before, 0, after - before);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
+ }
/* else nothing */
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SIZE]);