diff options
author | Benjamin Otte <otte@redhat.com> | 2022-02-26 04:52:16 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2023-04-11 13:37:32 +0200 |
commit | 849df30b504d889337d5d23340f9f2dae12ca33b (patch) | |
tree | 1469e374ceb4644026624fb6200dc5a9fcd7c000 | |
parent | f886f8e677587402fced55ad05443a022ab0e404 (diff) | |
download | gtk+-849df30b504d889337d5d23340f9f2dae12ca33b.tar.gz |
flattenlistmodel: Implement GtkSectionModel
Each child model is reported as one section.
-rw-r--r-- | gtk/gtkflattenlistmodel.c | 37 | ||||
-rw-r--r-- | gtk/gtksectionmodel.c | 2 |
2 files changed, 35 insertions, 4 deletions
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 |