[gtk/prop-list: 11/18] column view column: Add a sorter property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 11/18] column view column: Add a sorter property
- Date: Sun, 8 Dec 2019 19:00:07 +0000 (UTC)
commit 82c86c3f774793f8a55b4ec6c578da702b994d5d
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 3 02:26:02 2019 -0500
column view column: Add a sorter property
This will be used to implement sort by header click.
docs/reference/gtk/gtk4-sections.txt | 2 ++
gtk/gtkcolumnviewcolumn.c | 69 ++++++++++++++++++++++++++++++++++++
gtk/gtkcolumnviewcolumn.h | 7 ++++
gtk/gtkcolumnviewcolumnprivate.h | 1 +
4 files changed, 79 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 5fb0ebfe5c..53e8ff91ac 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -587,6 +587,8 @@ gtk_column_view_column_set_factory
gtk_column_view_column_get_factory
gtk_column_view_column_set_title
gtk_column_view_column_get_title
+gtk_column_view_column_set_sorter
+gtk_column_view_column_get_sorter
<SUBSECTION Standard>
GTK_COLUMN_VIEW_COLUMN
GTK_COLUMN_VIEW_COLUMN_CLASS
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index 283f1f6082..c215daecaa 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -20,6 +20,7 @@
#include "config.h"
#include "gtkcolumnviewcolumnprivate.h"
+#include "gtkcolumnviewsorterprivate.h"
#include "gtkcolumnviewprivate.h"
#include "gtkcolumnviewtitleprivate.h"
@@ -32,6 +33,7 @@
#include "gtksizegroup.h"
#include "gtkstylecontext.h"
#include "gtkwidgetprivate.h"
+#include "gtksorter.h"
/**
* SECTION:gtkcolumnviewcolumn
@@ -48,6 +50,7 @@ struct _GtkColumnViewColumn
GtkListItemFactory *factory;
char *title;
+ GtkSorter *sorter;
/* data for the view */
GtkColumnView *view;
@@ -73,6 +76,7 @@ enum
PROP_COLUMN_VIEW,
PROP_FACTORY,
PROP_TITLE,
+ PROP_SORTER,
N_PROPS
};
@@ -90,6 +94,7 @@ gtk_column_view_column_dispose (GObject *object)
g_assert (self->first_cell == NULL); /* no view = no children */
g_clear_object (&self->factory);
+ g_clear_object (&self->sorter);
g_clear_pointer (&self->title, g_free);
G_OBJECT_CLASS (gtk_column_view_column_parent_class)->dispose (object);
@@ -117,6 +122,10 @@ gtk_column_view_column_get_property (GObject *object,
g_value_set_string (value, self->title);
break;
+ case PROP_SORTER:
+ g_value_set_object (value, self->sorter);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -141,6 +150,10 @@ gtk_column_view_column_set_property (GObject *object,
gtk_column_view_column_set_title (self, g_value_get_string (value));
break;
+ case PROP_SORTER:
+ gtk_column_view_column_set_sorter (self, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -192,6 +205,13 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_SORTER] =
+ g_param_spec_object ("sorter",
+ P_("Sorter"),
+ P_("Sorter for sorting list items"),
+ GTK_TYPE_SORTER,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@@ -552,6 +572,55 @@ gtk_column_view_column_get_title (GtkColumnViewColumn *self)
return self->title;
}
+/**
+ * gtk_column_view_column_set_sorter:
+ * @self: a #GtkColumnViewColumn
+ * @sorter: (nullable): the #GtkSorter to associate with @column
+ *
+ * Associates a sorter with the column.
+ *
+ * This sorter can be made active by clicking on the column
+ * header, or by calling gtk_column_view_sort_by_column().
+ */
+void
+gtk_column_view_column_set_sorter (GtkColumnViewColumn *self,
+ GtkSorter *sorter)
+{
+ GtkColumnViewSorter *view_sorter;
+
+ g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
+ g_return_if_fail (sorter == NULL || GTK_IS_SORTER (sorter));
+
+ if (!g_set_object (&self->sorter, sorter))
+ return;
+
+ if (self->header)
+ gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header));
+
+ view_sorter = GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (self->view));
+
+ if (gtk_column_view_sorter_remove_column (view_sorter, self))
+ gtk_column_view_active_sorter_changed (self->view);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SORTER]);
+}
+
+/**
+ * gtk_column_view_column_get_sorter:
+ * @self: a #GtkColumnViewColumn
+ *
+ * Returns the sorter that is associated with the column.
+ *
+ * Returns: (transfer none): the #GtkSorter of @self
+ */
+GtkSorter *
+gtk_column_view_column_get_sorter (GtkColumnViewColumn *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), NULL);
+
+ return self->sorter;
+}
+
void
gtk_column_view_column_active_sorter_changed (GtkColumnViewColumn *self)
{
diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h
index 612cdb1854..f74cedaa08 100644
--- a/gtk/gtkcolumnviewcolumn.h
+++ b/gtk/gtkcolumnviewcolumn.h
@@ -25,6 +25,7 @@
#endif
#include <gtk/gtkcolumnview.h>
+#include <gtk/gtksorter.h>
G_BEGIN_DECLS
@@ -65,6 +66,12 @@ void gtk_column_view_column_set_title (GtkColu
GDK_AVAILABLE_IN_ALL
const char * gtk_column_view_column_get_title (GtkColumnViewColumn *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_column_view_column_set_sorter (GtkColumnViewColumn *self,
+ GtkSorter *sorter);
+GDK_AVAILABLE_IN_ALL
+GtkSorter * gtk_column_view_column_get_sorter (GtkColumnViewColumn *self);
+
G_END_DECLS
#endif /* __GTK_COLUMN_VIEW_COLUMN_H__ */
diff --git a/gtk/gtkcolumnviewcolumnprivate.h b/gtk/gtkcolumnviewcolumnprivate.h
index 3df2958c07..5afeffad4f 100644
--- a/gtk/gtkcolumnviewcolumnprivate.h
+++ b/gtk/gtkcolumnviewcolumnprivate.h
@@ -24,6 +24,7 @@
#include "gtk/gtkcolumnviewcellprivate.h"
+
void gtk_column_view_column_set_column_view (GtkColumnViewColumn *self,
GtkColumnView *view);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]