[gtk/prop-list: 9/21] column view: Add a sorter property



commit fdcc452fd63b6b9e13ce7e69ec7fa30b99f9b9e7
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 3 02:25:20 2019 -0500

    column view: Add a sorter property
    
    The sorter is where the column view combines the sorters of
    individual columns, as the user clicks on headers. To make
    sorting take effect, the sorter needs to be associated with
    a sort model underneath the model thats shown in the view.

 docs/reference/gtk/gtk4-sections.txt |  1 +
 gtk/gtkcolumnview.c                  | 51 ++++++++++++++++++++++++++++++++++++
 gtk/gtkcolumnview.h                  |  6 +++++
 3 files changed, 58 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index cd1e882542..6078a5c64b 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -562,6 +562,7 @@ gtk_column_view_new
 gtk_column_view_get_columns
 gtk_column_view_get_model
 gtk_column_view_set_model
+gtk_column_view_get_sorter
 gtk_column_view_get_show_separators
 gtk_column_view_set_show_separators
 <SUBSECTION Standard>
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 59b304e053..5762610f32 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -26,6 +26,7 @@
 #include "gtkcolumnlistitemfactoryprivate.h"
 #include "gtkcolumnviewcolumnprivate.h"
 #include "gtkcolumnviewlayoutprivate.h"
+#include "gtkcolumnviewsorterprivate.h"
 #include "gtkcssnodeprivate.h"
 #include "gtkintl.h"
 #include "gtklistview.h"
@@ -54,6 +55,8 @@ struct _GtkColumnView
 
   GtkListView *listview;
   GtkColumnListItemFactory *factory;
+
+  GtkSorter *sorter;
 };
 
 struct _GtkColumnViewClass
@@ -71,6 +74,8 @@ enum
   PROP_SHOW_SEPARATORS,
   PROP_VADJUSTMENT,
   PROP_VSCROLL_POLICY,
+  PROP_SORT_MODEL,
+  PROP_SORTER,
 
   N_PROPS
 };
@@ -250,6 +255,8 @@ gtk_column_view_dispose (GObject *object)
   g_clear_pointer ((GtkWidget **) &self->listview, gtk_widget_unparent);
   g_clear_object (&self->factory);
 
+  g_clear_object (&self->sorter);
+
   G_OBJECT_CLASS (gtk_column_view_parent_class)->dispose (object);
 }
 
@@ -301,6 +308,10 @@ gtk_column_view_get_property (GObject    *object,
       g_value_set_enum (value, gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (self->listview)));
       break;
 
+    case PROP_SORTER:
+      g_value_set_object (value, self->sorter);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -429,6 +440,20 @@ gtk_column_view_class_init (GtkColumnViewClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  properties[PROP_SORT_MODEL] =
+    g_param_spec_object ("sort-model",
+                         P_("Sort Model"),
+                         P_("Sort Model for the items displayed"),
+                         GTK_TYPE_SORT_LIST_MODEL,
+                         G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+  properties[PROP_SORTER] =
+    g_param_spec_object ("sorter",
+                         P_("Sorter"),
+                         P_("Sorter"),
+                         GTK_TYPE_SORTER,
+                         G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 
   /**
@@ -468,6 +493,7 @@ gtk_column_view_init (GtkColumnView *self)
   gtk_widget_set_layout_manager (self->header, gtk_column_view_layout_new (self));
   gtk_widget_set_parent (self->header, GTK_WIDGET (self));
 
+  self->sorter = gtk_column_view_sorter_new ();
   self->factory = gtk_column_list_item_factory_new (self);
   self->listview = GTK_LIST_VIEW (gtk_list_view_new_with_factory (
         GTK_LIST_ITEM_FACTORY (g_object_ref (self->factory))));
@@ -643,6 +669,7 @@ gtk_column_view_remove_column (GtkColumnView       *self,
         break;
     }
 
+  gtk_column_view_sorter_remove_column (GTK_COLUMN_VIEW_SORTER (self->sorter), column);
   gtk_column_view_column_set_column_view (column, NULL);
   g_list_store_remove (self->columns, i);
 }
@@ -681,6 +708,30 @@ gtk_column_view_get_header_widget (GtkColumnView *self)
   return GTK_LIST_ITEM_WIDGET (self->header);
 }
 
+/**
+ * gtk_column_view_get_sorter:
+ * @self: a #GtkColumnView
+ *
+ * Returns the sorter associated with the column view.
+ *
+ * To enable customizable sorting by clicking on column
+ * headers, this sorter needs to be set on the sort
+ * model(s) underneath the model that is displayed
+ * by the view.
+ *
+ * See gtk_column_view_get_sorter() for setting up
+ * per-column sorting.
+ *
+ * Returns: (transfer none): the #GtkSorter of @self
+ */
+GtkSorter *
+gtk_column_view_get_sorter (GtkColumnView *self)
+{
+  g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), NULL);
+
+  return self->sorter;
+}
+
 void
 gtk_column_view_active_sorter_changed (GtkColumnView *self)
 {
diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h
index a4ac08a8b1..6ec91319e8 100644
--- a/gtk/gtkcolumnview.h
+++ b/gtk/gtkcolumnview.h
@@ -25,6 +25,8 @@
 #endif
 
 #include <gtk/gtktypes.h>
+#include <gtk/gtksortlistmodel.h>
+#include <gtk/gtksorter.h>
 
 G_BEGIN_DECLS
 
@@ -65,12 +67,16 @@ GListModel *    gtk_column_view_get_model                       (GtkColumnView
 GDK_AVAILABLE_IN_ALL
 void            gtk_column_view_set_model                       (GtkColumnView          *self,
                                                                  GListModel             *model);
+
 GDK_AVAILABLE_IN_ALL
 gboolean        gtk_column_view_get_show_separators             (GtkColumnView          *self);
 GDK_AVAILABLE_IN_ALL
 void            gtk_column_view_set_show_separators             (GtkColumnView          *self,
                                                                  gboolean                show_separators);
 
+GDK_AVAILABLE_IN_ALL
+GtkSorter *     gtk_column_view_get_sorter                      (GtkColumnView          *self);
+
 G_END_DECLS
 
 #endif  /* __GTK_COLUMN_VIEW_H__ */


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