mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-15 14:50:06 +00:00
flattenlistmodeL: Compute items-changed position properly
The code previously forgot to include the left child of the model's node. Which of course only happened if that child wasn't NULL, which is a common case. Found and test provided by Matthias Clasen.
This commit is contained in:
parent
72814c54a8
commit
129691f3a6
@ -216,17 +216,25 @@ gtk_flatten_list_model_items_changed_cb (GListModel *model,
|
||||
guint added,
|
||||
gpointer _node)
|
||||
{
|
||||
FlattenNode *node = _node, *parent;
|
||||
FlattenNode *node = _node, *parent, *left;
|
||||
GtkFlattenListModel *self = node->list;
|
||||
guint real_position;
|
||||
|
||||
gtk_rb_tree_node_mark_dirty (node);
|
||||
real_position = position;
|
||||
|
||||
for (real_position = position;
|
||||
left = gtk_rb_tree_node_get_left (node);
|
||||
if (left)
|
||||
{
|
||||
FlattenAugment *aug = gtk_rb_tree_get_augment (self->items, left);
|
||||
real_position += aug->n_items;
|
||||
}
|
||||
|
||||
for (;
|
||||
(parent = gtk_rb_tree_node_get_parent (node)) != NULL;
|
||||
node = parent)
|
||||
{
|
||||
FlattenNode *left = gtk_rb_tree_node_get_left (parent);
|
||||
left = gtk_rb_tree_node_get_left (parent);
|
||||
if (left != node)
|
||||
{
|
||||
if (left)
|
||||
|
@ -300,6 +300,44 @@ test_submodel_add (void)
|
||||
g_object_unref (flat);
|
||||
}
|
||||
|
||||
static void
|
||||
test_submodel_add2 (void)
|
||||
{
|
||||
GtkFlattenListModel *flat;
|
||||
GListStore *model, *store[2];
|
||||
|
||||
model = g_list_store_new (G_TYPE_LIST_MODEL);
|
||||
flat = new_model (model);
|
||||
assert_model (flat, "");
|
||||
assert_changes (flat, "");
|
||||
|
||||
store[0] = add_store (model, 1, 0, 0);
|
||||
store[1] = add_store (model, 1, 0, 0);
|
||||
store[2] = add_store (model, 1, 0, 0);
|
||||
|
||||
assert_model (flat, "");
|
||||
assert_changes (flat, "");
|
||||
|
||||
add (store[0], 1);
|
||||
assert_model (flat, "1");
|
||||
assert_changes (flat, "+0");
|
||||
|
||||
add (store[1], 3);
|
||||
assert_model (flat, "1 3");
|
||||
assert_changes (flat, "+1");
|
||||
|
||||
add (store[0], 2);
|
||||
assert_model (flat, "1 2 3");
|
||||
assert_changes (flat, "+1");
|
||||
|
||||
add (store[1], 4);
|
||||
assert_model (flat, "1 2 3 4");
|
||||
assert_changes (flat, "+3");
|
||||
|
||||
g_object_unref (model);
|
||||
g_object_unref (flat);
|
||||
}
|
||||
|
||||
static void
|
||||
test_model_remove (void)
|
||||
{
|
||||
@ -365,6 +403,7 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/flattenlistmodel/model/add", test_model_add);
|
||||
#if GLIB_CHECK_VERSION (2, 58, 0) /* g_list_store_splice() is broken before 2.58 */
|
||||
g_test_add_func ("/flattenlistmodel/submodel/add", test_submodel_add);
|
||||
g_test_add_func ("/flattenlistmodel/submodel/add2", test_submodel_add2);
|
||||
g_test_add_func ("/flattenlistmodel/model/remove", test_model_remove);
|
||||
g_test_add_func ("/flattenlistmodel/submodel/remove", test_submodel_remove);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user