enum {
PROP_0,
PROP_ITEM_TYPE,
+ PROP_N_ITEMS,
PROP_OBJECT,
PROP_PROPERTY,
NUM_PROPERTIES
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
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;
/**
* 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,
G_TYPE_OBJECT,
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:
*
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
}
}
+static void
+notify_n_items (GObject *object,
+ GParamSpec *pspec,
+ GString *changes)
+{
+ g_string_append_c (changes, '*');
+}
+
static void
free_changes (gpointer data)
{
changes = g_string_new ("");
g_object_set_qdata_full (G_OBJECT(result), changes_quark, changes, free_changes);
g_signal_connect (result, "items-changed", G_CALLBACK (items_changed), changes);
+ g_signal_connect (result, "notify::n-items", G_CALLBACK (notify_n_items), changes);
return result;
}
model = new_model (FALSE);
gtk_property_lookup_list_model_set_object (model, widget);
assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow");
- assert_changes (model, "+0");
+ assert_changes (model, "+0*");
g_object_unref (model);
model = new_model (FALSE);
assert_model (model, "");
gtk_property_lookup_list_model_set_object (model, widget);
assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow");
- assert_changes (model, "0+4");
+ assert_changes (model, "0+4*");
g_object_unref (model);
destroy_widgets ();
assert_model (model, ""); /* make sure the model has a definite size */
gtk_property_lookup_list_model_set_object (model, widget);
assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow");
- assert_changes (model, "0+4");
+ assert_changes (model, "0+4*");
gtk_grid_remove (GTK_GRID (parent), widget);
assert_model (model, "GtkLabel");
- assert_changes (model, "1-3");
+ assert_changes (model, "1-3*");
gtk_box_append (GTK_BOX (grandparent), widget);
assert_model (model, "GtkLabel GtkBox GtkWindow");
- assert_changes (model, "1+2");
+ assert_changes (model, "1+2*");
g_object_unref (model);
destroy_widgets ();