[gtk/column-sorting: 1/3] Add gtk_multi_sorter_splice




commit cfe54a94a3c31b777b6821eb445881e36e9051ec
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Oct 19 20:24:55 2022 -0400

    Add gtk_multi_sorter_splice
    
    There is no reason to have a weaker list api
    on this sorter than on a list store. We will
    need this function in the following commits.

 gtk/gtkmultisorter.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkmultisorter.h |  7 +++++++
 2 files changed, 58 insertions(+)
---
diff --git a/gtk/gtkmultisorter.c b/gtk/gtkmultisorter.c
index ddbdb440cb..79e05cde63 100644
--- a/gtk/gtkmultisorter.c
+++ b/gtk/gtkmultisorter.c
@@ -503,3 +503,54 @@ gtk_multi_sorter_remove (GtkMultiSorter *self,
                                 GTK_SORTER_CHANGE_LESS_STRICT,
                                 gtk_multi_sort_keys_new (self));
 }
+
+/**
+ * gtk_multi_sorter_splice:
+ * @self: a `GtkMultiSorter`
+ * @position: the position at which to make the change
+ * @n_removals: the number of items to remove
+ * @additions: (array length=n_additions) (element-type GtkSorter): the sorters to add
+ * @n_additions: the number of sorters to add
+ *
+ * Changes @self by removing @n_removals items and adding @n_additions
+ * sorters to it.
+ *
+ * This is the equivalent of [method@GLib.ListStore.splice].
+ *
+ * Since: 4.10
+ */
+void
+gtk_multi_sorter_splice (GtkMultiSorter  *self,
+                         guint            position,
+                         guint            n_removals,
+                         GtkSorter      **additions,
+                         guint            n_additions)
+{
+  guint n_items;
+
+  g_return_if_fail (GTK_IS_MULTI_SORTER (self));
+  g_return_if_fail (position + n_removals >= position); /* overflow */
+
+  n_items = gtk_sorters_get_size (&self->sorters);
+  g_return_if_fail (position + n_removals <= n_items);
+
+
+  for (guint i = 0; i < n_removals; i++)
+    {
+      GtkSorter *sorter = gtk_sorters_get (&self->sorters, position + i);
+      g_signal_handlers_disconnect_by_func (sorter, gtk_multi_sorter_changed_cb, self);
+    }
+  for (guint i = 0; i < n_additions; i++)
+    {
+      GtkSorter *sorter = additions[i];
+      g_signal_connect (sorter, "changed", G_CALLBACK (gtk_multi_sorter_changed_cb), self);
+    }
+  gtk_sorters_splice (&self->sorters, position, n_removals, FALSE, additions, n_additions);
+  g_list_model_items_changed (G_LIST_MODEL (self), position, n_removals, n_additions);
+  if (n_removals != n_additions)
+    g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
+
+  gtk_sorter_changed_with_keys (GTK_SORTER (self),
+                                GTK_SORTER_CHANGE_DIFFERENT,
+                                gtk_multi_sort_keys_new (self));
+}
diff --git a/gtk/gtkmultisorter.h b/gtk/gtkmultisorter.h
index d634711d51..ee8ef64e52 100644
--- a/gtk/gtkmultisorter.h
+++ b/gtk/gtkmultisorter.h
@@ -44,6 +44,13 @@ GDK_AVAILABLE_IN_ALL
 void                    gtk_multi_sorter_remove                 (GtkMultiSorter         *self,
                                                                  guint                   position);
 
+GDK_AVAILABLE_IN_4_10
+void                    gtk_multi_sorter_splice                 (GtkMultiSorter         *self,
+                                                                 guint                   position,
+                                                                 guint                   n_removals,
+                                                                 GtkSorter             **additions,
+                                                                 guint                   n_additions);
+
 G_END_DECLS
 
 #endif /* __GTK_MULTI_SORTER_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]