From: Benjamin Otte Date: Sat, 26 Feb 2022 03:52:16 +0000 (+0100) Subject: flattenlistmodel: Implement GtkSectionModel X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~287^2~29 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ff6c5ad710bcd291cb4470ac25e2a3390b49403c;p=gtk4.git flattenlistmodel: Implement GtkSectionModel Each child model is reported as one section. --- diff --git a/gtk/gtkflattenlistmodel.c b/gtk/gtkflattenlistmodel.c index 04cf04c6fd..f80e80ff6d 100644 --- a/gtk/gtkflattenlistmodel.c +++ b/gtk/gtkflattenlistmodel.c @@ -21,8 +21,8 @@ #include "gtkflattenlistmodel.h" +#include "gtksectionmodel.h" #include "gtkrbtreeprivate.h" -#include "gtkprivate.h" /** * GtkFlattenListModel: @@ -200,8 +200,39 @@ gtk_flatten_list_model_model_init (GListModelInterface *iface) iface->get_item = gtk_flatten_list_model_get_item; } +static void +gtk_flatten_list_model_get_section (GtkSectionModel *model, + guint position, + guint *out_start, + guint *out_end) +{ + GtkFlattenListModel *self = GTK_FLATTEN_LIST_MODEL (model); + FlattenNode *node; + guint model_pos; + + node = gtk_flatten_list_model_get_nth (self->items, position, &model_pos); + if (node == NULL) + { + *out_start = gtk_flatten_list_model_get_n_items (G_LIST_MODEL (self)); + *out_end = G_MAXUINT; + return; + } + + *out_start = position - model_pos; + *out_end = position - model_pos + g_list_model_get_n_items (node->model); +} + +static void +gtk_flatten_list_model_section_model_init (GtkSectionModelInterface *iface) +{ + iface->get_section = gtk_flatten_list_model_get_section; +} + G_DEFINE_TYPE_WITH_CODE (GtkFlattenListModel, gtk_flatten_list_model, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, gtk_flatten_list_model_model_init)) + G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, + gtk_flatten_list_model_model_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_SECTION_MODEL, + gtk_flatten_list_model_section_model_init)) static void gtk_flatten_list_model_items_changed_cb (GListModel *model, @@ -433,7 +464,7 @@ gtk_flatten_list_model_class_init (GtkFlattenListModelClass *class) properties[PROP_MODEL] = g_param_spec_object ("model", NULL, NULL, G_TYPE_LIST_MODEL, - GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); /** * GtkFlattenListModel:n-items: diff --git a/gtk/gtksectionmodel.c b/gtk/gtksectionmodel.c index 2df8562e01..a5084ab340 100644 --- a/gtk/gtksectionmodel.c +++ b/gtk/gtksectionmodel.c @@ -93,7 +93,7 @@ gtk_section_model_default_init (GtkSectionModelInterface *iface) * model, though it would be rather useless to emit such a signal. * * The [signal@Gio.ListModel::items-changed] implies the effect of the - * [signal@Gtk.SectionModel::section-changed] signal for all the items + * [signal@Gtk.SectionModel::sections-changed] signal for all the items * it covers. * * Since: 4.12