1.117 <GtkMapListModel>

Class: <GtkMapListModel>

It derives from <GObject>.

A list model that maps the items in another model to different items.

<GtkMapListModel> uses 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 (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.

Properties

Property: map-list-model:has-map self

If a map is set for this model

Its value is a boolean.

It is read only.

Property: map-list-model:item-type self

The type of items. See list-model:get-item-type.

Its value is a class, or a GType number.

It is read only.

Property: map-list-model:model self

The model being mapped.

Its value is a <GListModel>, or #f.

Set it with (set! (map-list-model:model self) value).

Property: map-list-model:n-items self

The number of items. See list-model:get-n-items.

Its value is an unsigned 32-bit integer.

It is read only.

Procedures

Method: map-list-model:get-model self ⇒ %return
Method: get-model self ⇒ %return

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

self

Passed: a <GtkMapListModel>.

a <GtkMapListModel>

%return

Returned: a <GListModel>, or #f.

The model that gets mapped

Method: map-list-model:has-map? self ⇒ %return
Method: has-map? self ⇒ %return

Checks if a map function is currently set on self.

self

Passed: a <GtkMapListModel>.

a <GtkMapListModel>

%return

Returned: a boolean.

#t if a map function is set

Procedure: map-list-model:new [model] [map-func] ⇒ %return

Creates a new <GtkMapListModel> for the given arguments.

model

Passed, or left out: a <GListModel>, or #f.

The model to map

map-func

Passed, or left out: a procedure, or #f.

map function

See GtkMapListModelMapFunc for how it is called.

%return

Returned: a <GtkMapListModel>.

a new <GtkMapListModel>

user-data

Not passed: guile-gi supplies it.

user data passed to map-func

user-destroy

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

Method: map-list-model:set-map-func self [map-func]
Method: set-map-func self [map-func]

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

Passed: a <GtkMapListModel>.

a <GtkMapListModel>

map-func

Passed, or left out: a procedure, or #f.

map function

See GtkMapListModelMapFunc for how it is called.

user-data

Not passed: guile-gi supplies it.

user data passed to map-func

user-destroy

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

Method: map-list-model:set-model self [model]
Method: set-model self [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

Passed: a <GtkMapListModel>.

a <GtkMapListModel>

model

Passed, or left out: a <GListModel>, or #f.

The model to be mapped