Gtk.MapListModel

g GObject.GInterface GObject.GInterface Gio.ListModel Gio.ListModel GObject.GInterface->Gio.ListModel Gtk.SectionModel Gtk.SectionModel GObject.GInterface->Gtk.SectionModel GObject.Object GObject.Object Gtk.MapListModel Gtk.MapListModel GObject.Object->Gtk.MapListModel Gio.ListModel->Gtk.MapListModel Gtk.SectionModel->Gtk.MapListModel

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.ListModel (4), Gtk.SectionModel (2)

Structs:

GObject.ObjectClass (5)

class

new (model, map_func, *user_data)

get_model ()

has_map ()

set_map_func (map_func, *user_data)

set_model (model)

Virtual Methods

Inherited:

GObject.Object (7), Gio.ListModel (3), Gtk.SectionModel (1)

Properties

Name

Type

Flags

Short Description

has-map

bool

r/en

item-type

GObject.GType

r

model

Gio.ListModel

r/w/co/en

n-items

int

r

Signals

Inherited:

GObject.Object (1), Gio.ListModel (1), Gtk.SectionModel (1)

Fields

Inherited:

GObject.Object (1), Gio.ListModel (1), Gtk.SectionModel (1)

Class Details

class Gtk.MapListModel(**kwargs)
Bases:

GObject.Object, Gio.ListModel, Gtk.SectionModel

Abstract:

No

Structure:

Gtk.MapListModelClass

A GtkMapListModel maps the items in a list model to different items.

GtkMapListModel uses a [callback`Gtk`.MapListModelMapFunc].

Example: Create a list of GtkEventControllers ```c static object map_to_controllers (object widget, object data) { object result = Gtk.Widget.observe_controllers (widget); GObject.Object.unref (widget); return result; }

widgets = Gtk.Widget.observe_children (widget);

controllers = Gtk.MapListModel.new (widgets, map_to_controllers, None, None);

model = Gtk.FlattenListModel.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.

classmethod new(model, map_func, *user_data)[source]
Parameters:
Returns:

a new GtkMapListModel

Return type:

Gtk.MapListModel

Creates a new GtkMapListModel for the given arguments.

get_model()[source]
Returns:

The model that gets mapped

Return type:

Gio.ListModel or None

Gets the model that is currently being mapped or None if none.

has_map()[source]
Returns:

True if a map function is set

Return type:

bool

Checks if a map function is currently set on self.

set_map_func(map_func, *user_data)[source]
Parameters:

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.

set_model(model)[source]
Parameters:

model (Gio.ListModel or None) – The model to be mapped

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.

Property Details

Gtk.MapListModel.props.has_map
Name:

has-map

Type:

bool

Default Value:

False

Flags:

READABLE, EXPLICIT_NOTIFY

If a map is set for this model

Gtk.MapListModel.props.item_type
Name:

item-type

Type:

GObject.GType

Default Value:

<GType GObject>

Flags:

READABLE

The type of items. See [method`Gio`.ListModel.get_item_type].

New in version 4.8.

Gtk.MapListModel.props.model
Name:

model

Type:

Gio.ListModel

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY, EXPLICIT_NOTIFY

The model being mapped.

Gtk.MapListModel.props.n_items
Name:

n-items

Type:

int

Default Value:

0

Flags:

READABLE

The number of items. See [method`Gio`.ListModel.get_n_items].

New in version 4.8.