[gtk/wip/matthiasc/shortcut-2] flattenlistmodel: Give access to child models
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/shortcut-2] flattenlistmodel: Give access to child models
- Date: Sun, 22 Mar 2020 17:54:33 +0000 (UTC)
commit 527b9fb0ca9865bd19870f9685419f23f6e21dcc
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Mar 22 13:19:55 2020 -0400
flattenlistmodel: Give access to child models
Add an api to retrieve the model containing a given
item in a flatten listmodel. With this api addition,
the flatten listmodel can replace the concat one.
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/gtkflattenlistmodel.c | 25 +++++++++++++++++++++++++
gtk/gtkflattenlistmodel.h | 4 ++++
3 files changed, 30 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 647fcafb5c4..c4209f9607f 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1246,6 +1246,7 @@ GtkFlattenListModel
gtk_flatten_list_model_new
gtk_flatten_list_model_set_model
gtk_flatten_list_model_get_model
+gtk_flatten_list_model_get_model_for_item
<SUBSECTION Standard>
GTK_FLATTEN_LIST_MODEL
GTK_IS_FLATTEN_LIST_MODEL
diff --git a/gtk/gtkflattenlistmodel.c b/gtk/gtkflattenlistmodel.c
index 3204f5b5eae..f557cb22329 100644
--- a/gtk/gtkflattenlistmodel.c
+++ b/gtk/gtkflattenlistmodel.c
@@ -539,3 +539,28 @@ gtk_flatten_list_model_get_model (GtkFlattenListModel *self)
return self->model;
}
+
+/**
+ * gtk_flatten_list_model_get_model_for_item:
+ * @self: a #GtkFlattenListModel
+ * @position: a position
+ *
+ * Returns the model containing the item at the given position.
+ *
+ * Returns: (transfer none): the model containing the item at @position
+ */
+GListModel *
+gtk_flatten_list_model_get_model_for_item (GtkFlattenListModel *self,
+ guint position)
+{
+ FlattenNode *node;
+
+ if (!self->items)
+ return NULL;
+
+ node = gtk_flatten_list_model_get_nth (self->items, position, NULL);
+ if (node == NULL)
+ return NULL;
+
+ return node->model;
+}
diff --git a/gtk/gtkflattenlistmodel.h b/gtk/gtkflattenlistmodel.h
index 75e39404d74..ec1eaaa84ec 100644
--- a/gtk/gtkflattenlistmodel.h
+++ b/gtk/gtkflattenlistmodel.h
@@ -45,6 +45,10 @@ void gtk_flatten_list_model_set_model (GtkFlattenListM
GDK_AVAILABLE_IN_ALL
GListModel * gtk_flatten_list_model_get_model (GtkFlattenListModel *self);
+GDK_AVAILABLE_IN_ALL
+GListModel * gtk_flatten_list_model_get_model_for_item (GtkFlattenListModel *self,
+ guint position);
+
G_END_DECLS
#endif /* __GTK_FLATTEN_LIST_MODEL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]