:right-sidebar: True MapListModel =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: MapListModel(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gio.ListModel`, :class:`~gi.repository.Gtk.SectionModel` A ``GtkMapListModel`` maps the items in a list model to different items. ``GtkMapListModel`` uses a ``Gtk.MapListModelMapFunc``. Example: Create a list of ``GtkEventControllers`` .. code-block:: :dedent: 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 (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. ``GtkMapListModel`` passes through sections from the underlying model. Constructors ------------ .. rst-class:: interim-class .. class:: MapListModel :no-index: .. classmethod:: new(model: ~gi.repository.Gio.ListModel | None = None, map_func: ~typing.Callable[[...], ~gi.repository.GObject.Object] | None = None, *user_data: ~typing.Any) -> ~gi.repository.Gtk.MapListModel Creates a new ``GtkMapListModel`` for the given arguments. :param model: The model to map :param map_func: map function :param user_data: user data passed to ``map_func`` Methods ------- .. rst-class:: interim-class .. class:: MapListModel :no-index: .. method:: get_model() -> ~gi.repository.Gio.ListModel | None Gets the model that is currently being mapped or :const:`None` if none. .. method:: has_map() -> bool Checks if a map function is currently set on ``self``. .. method:: set_map_func(map_func: ~typing.Callable[[...], ~gi.repository.GObject.Object] | None = None, *user_data: ~typing.Any) -> None 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. :param map_func: map function :param user_data: user data passed to ``map_func`` .. method:: set_model(model: ~gi.repository.Gio.ListModel | None = None) -> None 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. :param model: The model to be mapped Properties ---------- .. rst-class:: interim-class .. class:: MapListModel :no-index: .. attribute:: props.has_map :type: bool If a map is set for this model .. attribute:: props.item_type :type: type The type of items. See :obj:`~gi.repository.Gio.ListModel.get_item_type`. .. versionadded:: 4.8 .. attribute:: props.model :type: ~gi.repository.Gio.ListModel The model being mapped. .. attribute:: props.n_items :type: int The number of items. See :obj:`~gi.repository.Gio.ListModel.get_n_items`. .. versionadded:: 4.8