GtkMapListModel — A list model that transforms its items
gpointer | (*GtkMapListModelMapFunc) () |
GtkMapListModel * | gtk_map_list_model_new () |
void | gtk_map_list_model_set_map_func () |
void | gtk_map_list_model_set_model () |
GListModel * | gtk_map_list_model_get_model () |
gboolean | gtk_map_list_model_has_map () |
GObject ╰── GtkMapListModel
GtkMapListModel implements GListModel.
#include <gtk/gtk.h>
GtkMapListModel is a list model that takes a list model and maps the items in that model to different items according to a GtkMapListModelMapFunc.
Example: Create a list of GtkEventControllers
static gpointer map_to_controllers (gpointer widget, gpointer data) { gpointer result = gtk_widget_observe_controllers (widget); g_object_unref (widget); return result; } widgets = gtk_widget_observe_children (widget); controllers = gtk_map_list_model_new (G_TYPE_LIST_MODEL, widgets, map_to_controllers, NULL, NULL); model = gtk_flatten_list_model_new (GTK_TYPE_EVENT_CONTROLLER, controllers);
GtkMapListModel will attempt to discard the mapped objects as soon as they are no longer needed and recreate them if necessary.
gpointer (*GtkMapListModelMapFunc) (gpointer item, gpointer user_data);
User function that is called to map an item
of the original model to an item expected by the map model.
The returned items must conform to the item type of the model they are used with.
item | The item to map. | [type GObject][transfer full] |
user_data | user data |
The item to map to. This function may not return NULL
.
[type GObject][transfer full]
GtkMapListModel * gtk_map_list_model_new (GListModel *model
,GtkMapListModelMapFunc map_func
,gpointer user_data
,GDestroyNotify user_destroy
);
Creates a new GtkMapListModel for the given arguments.
model | The model to map or | [transfer full][allow-none] |
map_func | map function or | [allow-none] |
user_data | user data passed to | [closure] |
user_destroy | destroy notifier for |
a new GtkMapListModel
void gtk_map_list_model_set_map_func (GtkMapListModel *self
,GtkMapListModelMapFunc map_func
,gpointer user_data
,GDestroyNotify user_destroy
);
Sets the function used to map items. The function will be called whenever an item needs to be mapped and must return the item to use for the given input item.
Note that GtkMapListModel may call this function multiple times on the same item, because it may delete items it doesn't need anymore.
GTK makes no effort to ensure that map_func
conforms to the item type of self
. It assumes that the caller knows what they are doing and the map function returns items of the appropriate type.
self | ||
map_func | map function or | [allow-none] |
user_data | user data passed to | [closure] |
user_destroy | destroy notifier for |
void gtk_map_list_model_set_model (GtkMapListModel *self
,GListModel *model
);
Sets the model to be mapped.
GTK makes no effort to ensure that model
conforms to the item type expected by the map function. It assumes that the caller knows what they are doing and have set up an appropriate map function.
self | ||
model | The model to be mapped. | [allow-none] |
GListModel *
gtk_map_list_model_get_model (GtkMapListModel *self
);
Gets the model that is currently being mapped or NULL
if none.
self |
The model that gets mapped.
[nullable][transfer none]
gboolean
gtk_map_list_model_has_map (GtkMapListModel *self
);
Checks if a map function is currently set on self
self |
TRUE
if a map function is set
typedef struct _GtkMapListModel GtkMapListModel;
“has-map”
property“has-map” gboolean
If a map is set for this model
Owner: GtkMapListModel
Flags: Read
Default value: FALSE
“model”
property“model” GListModel *
The model being mapped
Owner: GtkMapListModel
Flags: Read / Write / Construct Only
GListModel
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkMapListModel.html