## GtkMapListModel GtkMapListModel — A list model that transforms its items |

## Functions

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 ()

## Properties

gboolean | has-map | Read
GType * | item-type | Read / Write / Construct Only
GListModel * | model | Read / Write / Construct Only

## Types and Values

| GtkMapListModel

## Object Hierarchy

        GObject
        ╰── GtkMapListModel

## Implemented Interfaces

GtkMapListModel implements GListModel.

## Includes

    #include <gtk/gtk.h>

## Description

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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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.

## Functions

### GtkMapListModelMapFunc ()

    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.

#### Parameters

item | The item to map. | [type GObject][transfer full]
user_data | user data |

#### Returns

The item to map to. This function may not return `NULL`.

[type GObject][transfer full]

### gtk_map_list_model_new ()

    GtkMapListModel *
    gtk_map_list_model_new (GType item_type,
                            GListModel *model,
                            GtkMapListModelMapFunc map_func,
                            gpointer user_data,
                            GDestroyNotify user_destroy);

Creates a new GtkMapListModel for the given arguments.

#### Parameters

item_type | the GType to use as the model's item type |
model | The model to map or `NULL` for none. | [allow-none]
map_func | map function or `NULL` to not map items. | [allow-none]
user_data | user data passed to `map_func` . | [closure]
user_destroy | destroy notifier for `user_data` |

#### Returns

a new GtkMapListModel

### gtk_map_list_model_set_map_func ()

    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.

#### Parameters

self | a GtkMapListModel |
map_func | map function or `NULL` to not map items. | [allow-none]
user_data | user data passed to `map_func` . | [closure]
user_destroy | destroy notifier for `user_data` |

### gtk_map_list_model_set_model ()

    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.

#### Parameters

self | a GtkMapListModel |
model | The model to be mapped. | [allow-none]

### gtk_map_list_model_get_model ()

    GListModel *
    gtk_map_list_model_get_model (GtkMapListModel *self);

Gets the model that is curently being mapped or `NULL` if none.

#### Parameters

self | a GtkMapListModel |

#### Returns

The model that gets mapped.

[nullable][transfer none]

### gtk_map_list_model_has_map ()

    gboolean
    gtk_map_list_model_has_map (GtkMapListModel *self);

Checks if a map function is currently set on `self`

#### Parameters

self | a GtkMapListModel |

#### Returns

`TRUE` if a map function is set

## Types and Values

### GtkMapListModel

    typedef struct _GtkMapListModel GtkMapListModel;

## Property Details

### The `“has-map”` property

      “has-map”                  gboolean

If a map is set for this model

Owner: GtkMapListModel

Flags: Read

Default value: FALSE

### The `“item-type”` property

      “item-type”                GType *

The GType for elements of this object

Owner: GtkMapListModel

Flags: Read / Write / Construct Only

Allowed values: GObject

### The `“model”` property

      “model”                    GListModel *

The model being mapped

Owner: GtkMapListModel

Flags: Read / Write / Construct Only

## See Also

GListModel