enum {
PROP_0,
+ PROP_ITEM_TYPE,
PROP_MODEL,
+ PROP_N_ITEMS,
+
NUM_PROPERTIES
};
}
g_list_model_items_changed (G_LIST_MODEL (self), real_position, removed, added);
+ if (removed != added)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
switch (prop_id)
{
+ case PROP_ITEM_TYPE:
+ g_value_set_gtype (value, gtk_flatten_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_flatten_list_model_get_n_items (G_LIST_MODEL (self)));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
if (real_removed > 0 || real_added > 0)
g_list_model_items_changed (G_LIST_MODEL (self), real_position, real_removed, real_added);
+ if (real_removed != real_added)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
}
static void
gobject_class->get_property = gtk_flatten_list_model_get_property;
gobject_class->dispose = gtk_flatten_list_model_dispose;
+ /**
+ * GtkFlattenListModel: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);
+
/**
* GtkFlattenListModel:model: (attributes org.gtk.Property.get=gtk_flatten_list_model_get_model org.gtk.Property.set=gtk_flatten_list_model_set_model)
*
G_TYPE_LIST_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GtkFlattenListModel: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);
+
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
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]);
}
}
}
+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;
}
add_store (model, 8, 10, 1);
assert_model (flat, "1 2 3 4 5 6 7 8 9 10");
- assert_changes (flat, "0+3, +3, 4+3, 7+3");
+ assert_changes (flat, "0+3*, +3*, 4+3*, 7+3*");
g_object_unref (model);
g_object_unref (flat);
store[2] = add_store (model, 5, 4, 1);
store[3] = add_store (model, 8, 8, 1);
assert_model (flat, "2 3 4 8");
- assert_changes (flat, "0+2, +2, +3");
+ assert_changes (flat, "0+2*, +2*, +3*");
insert (store[0], 0, 1);
splice (store[2], 0, 0, (guint[3]) { 5, 6, 7 }, 3);
splice (store[3], 1, 0, (guint[2]) { 9, 10 }, 2);
assert_model (flat, "1 2 3 4 5 6 7 8 9 10");
- assert_changes (flat, "+0, 4+3, 8+2");
+ assert_changes (flat, "+0*, 4+3*, 8+2*");
g_object_unref (model);
g_object_unref (flat);
add (store[0], 1);
assert_model (flat, "1");
- assert_changes (flat, "+0");
+ assert_changes (flat, "+0*");
add (store[1], 3);
assert_model (flat, "1 3");
- assert_changes (flat, "+1");
+ assert_changes (flat, "+1*");
add (store[0], 2);
assert_model (flat, "1 2 3");
- assert_changes (flat, "+1");
+ assert_changes (flat, "+1*");
add (store[1], 4);
assert_model (flat, "1 2 3 4");
- assert_changes (flat, "+3");
+ assert_changes (flat, "+3*");
g_object_unref (model);
g_object_unref (flat);
g_list_store_remove (model, 0);
g_object_unref (model);
assert_model (flat, "");
- assert_changes (flat, "3-4, 3-3, 0-3");
+ assert_changes (flat, "3-4*, 3-3*, 0-3*");
g_object_unref (flat);
}
g_object_unref (model);
assert_model (flat, "2 3 4 8");
- assert_changes (flat, "-0, 3-3, 4-2");
+ assert_changes (flat, "-0*, 3-3*, 4-2*");
g_object_unref (flat);
}