[gtk/prop-list: 5/8] column view: add sort model and sorter properties



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

    column view: add sort model and sorter properties
    
    These will be used to implement sorting via header click.

 gtk/gtkcolumnview.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcolumnview.h | 12 +++++++++
 2 files changed, 89 insertions(+)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index d6170dfc46..0f48c2e183 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -54,6 +54,9 @@ struct _GtkColumnView
 
   GtkListView *listview;
   GtkColumnListItemFactory *factory;
+
+  GtkSortListModel *sort_model;
+  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,9 @@ gtk_column_view_dispose (GObject *object)
   g_clear_pointer ((GtkWidget **) &self->listview, gtk_widget_unparent);
   g_clear_object (&self->factory);
 
+  g_clear_object (&self->sort_model);
+  g_clear_object (&self->sorter);
+
   G_OBJECT_CLASS (gtk_column_view_parent_class)->dispose (object);
 }
 
@@ -301,6 +309,14 @@ gtk_column_view_get_property (GObject    *object,
       g_value_set_enum (value, gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (self->listview)));
       break;
 
+    case PROP_SORT_MODEL:
+      g_value_set_object (value, self->sort_model);
+      break;
+
+    case PROP_SORTER:
+      g_value_set_object (value, self->sorter);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -357,6 +373,14 @@ gtk_column_view_set_property (GObject      *object,
         }
       break;
 
+    case PROP_SORT_MODEL:
+      gtk_column_view_set_sort_model (self, g_value_get_object (value));
+      break;
+
+    case PROP_SORTER:
+      gtk_column_view_set_sorter (self, g_value_get_object (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -429,6 +453,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_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 
   /**
@@ -681,3 +719,42 @@ gtk_column_view_get_header_widget (GtkColumnView *self)
   return GTK_LIST_ITEM_WIDGET (self->header);
 }
 
+void
+gtk_column_view_set_sort_model (GtkColumnView *self,
+                                GtkSortListModel *sort_model)
+{
+  g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
+  g_return_if_fail (sort_model == NULL || GTK_IS_SORT_LIST_MODEL (sort_model));
+
+  if (!g_set_object (&self->sort_model, sort_model))
+    return;
+
+  if (self->sort_model)
+    gtk_sort_list_model_set_sorter (self->sort_model, self->sorter);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SORT_MODEL]);
+}
+
+void
+gtk_column_view_set_sorter (GtkColumnView *self,
+                            GtkSorter     *sorter)
+{
+  g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
+  g_return_if_fail (sorter == NULL || GTK_IS_SORTER (sorter));
+
+  if (!g_set_object (&self->sorter, sorter))
+    return;
+
+  if (self->sort_model)
+    gtk_sort_list_model_set_sorter (self->sort_model, self->sorter);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SORTER]);
+}
+
+GtkSorter *
+gtk_column_view_get_sorter (GtkColumnView *self)
+{
+  g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), NULL);
+
+  return self->sorter;
+}
diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h
index a4ac08a8b1..2b5136d572 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,22 @@ 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
+void            gtk_column_view_set_sort_model                  (GtkColumnView          *self,
+                                                                 GtkSortListModel       *model);
+GDK_AVAILABLE_IN_ALL
+void            gtk_column_view_set_sorter                      (GtkColumnView          *self,
+                                                                 GtkSorter              *sorter);
+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]