Interface

GioListModel

Description [src]

interface Gio.ListModel : GObject.Object

GListModel is an interface that represents a mutable list of GObjects. Its main intention is as a model for various widgets in user interfaces, such as list views, but it can also be used as a convenient method of returning lists of data, with support for updates.

Each object in the list may also report changes in itself via some mechanism (normally the GObject::notify signal). Taken together with the GListModel::items-changed signal, this provides for a list that can change its membership, and in which the members can change their individual properties.

A good example would be the list of visible wireless network access points, where each access point can report dynamic properties such as signal strength.

It is important to note that the GListModel itself does not report changes to the individual items. It only reports changes to the list membership. If you want to observe changes to the objects themselves then you need to connect signals to the objects that you are interested in.

All items in a GListModel are of (or derived from) the same type. g_list_model_get_item_type() returns that type. The type may be an interface, in which case all objects in the list must implement it.

The semantics are close to that of an array: g_list_model_get_n_items() returns the number of items in the list and g_list_model_get_item() returns an item at a (0-based) position. In order to allow implementations to calculate the list length lazily, you can also iterate over items: starting from 0, repeatedly call g_list_model_get_item() until it returns NULL.

An implementation may create objects lazily, but must take care to return the same object for a given position until all references to it are gone.

On the other side, a consumer is expected only to hold references on objects that are currently “user visible”, in order to facilitate the maximum level of laziness in the implementation of the list and to reduce the required number of signal connections at a given time.

This interface is intended only to be used from a single thread. The thread in which it is appropriate to use it depends on the particular implementation, but typically it will be from the thread that owns the [thread-default main context][g-main-context-push-thread-default] in effect at the time that the model was created.

Prerequisite

In order to implement ListModel, your type must inherit from GObject.

Instance methods

g_list_model_get_item

Get the item at position. If position is greater than the number of items in list, NULL is returned.

Available since: 2.44

g_list_model_get_item_type

Gets the type of the items in list. All items returned from g_list_model_get_type() are of that type or a subtype, or are an implementation of that interface.

Available since: 2.44

g_list_model_get_n_items

Gets the number of items in list.

Available since: 2.44

g_list_model_get_object

Get the item at position. If position is greater than the number of items in list, NULL is returned.

Available since: 2.44

g_list_model_items_changed

Emits the GListModel::items-changed signal on list.

Available since: 2.44

Signals

Gio.ListModel::items-changed

This signal is emitted whenever items were added to or removed from list. At position, removed items were removed and added items were added in their place.

Available since: 2.44

Interface structure

struct GioListModelInterface {
  GTypeInterface g_iface;
  GType (* get_item_type) (
    GListModel* list
  );
  guint (* get_n_items) (
    GListModel* list
  );
  GObject* (* get_item) (
    GListModel* list,
    guint position
  );
  
}
Interface members
g_iface
GTypeInterface
 

Parent GTypeInterface.

get_item_type
GType (* get_item_type) (
    GListModel* list
  )
 No description available.
get_n_items
guint (* get_n_items) (
    GListModel* list
  )
 No description available.
get_item
GObject* (* get_item) (
    GListModel* list,
    guint position
  )
 No description available.

Virtual methods

Gio.ListModel.get_item

Get the item at position. If position is greater than the number of items in list, NULL is returned.

Gio.ListModel.get_item_type

Gets the type of the items in list. All items returned from g_list_model_get_type() are of that type or a subtype, or are an implementation of that interface.

Gio.ListModel.get_n_items

Gets the number of items in list.