[glib] Add g_list_store_sort
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add g_list_store_sort
- Date: Mon, 31 Aug 2015 14:43:55 +0000 (UTC)
commit e5734c37a6f1b0d3ce467e7a5ac11c29c1d5f56a
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Aug 26 23:20:39 2015 -0400
Add g_list_store_sort
GListStore already has a g_list_store_insert_sorted function,
which can be used to keep the list sorted according to a fixed
sort function. But if the sort function changes (as e.g. with
sort columns in a list UI), the entire list needs to be
resorted. In that case, you want g_list_store_sort().
https://bugzilla.gnome.org/show_bug.cgi?id=754152
docs/reference/gio/gio-sections.txt | 1 +
gio/gliststore.c | 26 ++++++++++++++++++++++++++
gio/gliststore.h | 5 +++++
3 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 039b20c..6dbe767 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -4443,6 +4443,7 @@ g_list_store_append
g_list_store_remove
g_list_store_remove_all
g_list_store_splice
+g_list_store_sort
<SUBSECTION Standard>
G_TYPE_LIST_STORE
<SUBSECTION Private>
diff --git a/gio/gliststore.c b/gio/gliststore.c
index 5e5f3e3..dff3958 100644
--- a/gio/gliststore.c
+++ b/gio/gliststore.c
@@ -317,6 +317,32 @@ g_list_store_insert_sorted (GListStore *store,
}
/**
+ * g_list_store_sort:
+ * @store: a #GListStore
+ * @compare_func: (scope call): pairwise comparison function for sorting
+ * @user_data: (closure): user data for @compare_func
+ *
+ * Sort the items in @store according to @compare_func.
+ *
+ * Since: 2.46
+ */
+void
+g_list_store_sort (GListStore *store,
+ GCompareDataFunc compare_func,
+ gpointer user_data)
+{
+ gint n_items;
+
+ g_return_if_fail (G_IS_LIST_STORE (store));
+ g_return_val_if_fail (compare_func != NULL, 0);
+
+ g_sequence_sort (store->items, compare_func, user_data);
+
+ n_items = g_sequence_get_length (store->items);
+ g_list_store_items_changed (store, 0, n_items, n_items);
+}
+
+/**
* g_list_store_append:
* @store: a #GListStore
* @item: (type GObject): the new item
diff --git a/gio/gliststore.h b/gio/gliststore.h
index 88ce941..cc8011e 100644
--- a/gio/gliststore.h
+++ b/gio/gliststore.h
@@ -49,6 +49,11 @@ guint g_list_store_insert_sorted (GListSt
GCompareDataFunc compare_func,
gpointer user_data);
+GLIB_AVAILABLE_IN_2_46
+void g_list_store_sort (GListStore *store,
+ GCompareDataFunc compare_func,
+ gpointer user_data);
+
GLIB_AVAILABLE_IN_2_44
void g_list_store_append (GListStore *store,
gpointer item);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]