Glib.List_Model.Glist_Model 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 Glib.Object.GObject::notify signal). Taken together with the Glib.List_Model.Glist_Model::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 Glib.List_Model.Glist_Model 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 Glib.List_Model.Glist_Model are of (or derived from) the same type. Glib.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: Glib.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.
Over time, it has established itself as good practice for listmodel implementations to provide properties item-type and n-items to ease working with them. While it is not required, it is recommended that implementations provide these two properties. They should return the values of Glib.List_Model.Get_Item_Type and Glib.List_Model.Get_N_Items respectively and be defined as such:
properties[PROP_ITEM_TYPE] =
g_param_spec_gtype ("item-type", "", "", G_TYPE_OBJECT,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties[PROP_N_ITEMS] =
g_param_spec_uint ("n-items", "", "", 0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
function "+" (W : Glist_Model) return Glist_Model
type Cb_Glist_Model_Guint_Guint_Guint_Void is not null access procedure
(Self : Glist_Model;
Position : Guint;
Removed : Guint;
Added : Guint);
type Cb_GObject_Guint_Guint_Guint_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class;
Position : Guint;
Removed : Guint;
Added : Guint);
function Get_Item
(Self : Glist_Model;
Position : Guint) return Glib.Object.GObject
Get the item at Position. If Position is greater than the number of items in List, null is returned. null is never returned for an index that is smaller than the length of the list. This function is meant to be used by language bindings in place of g_list_model_get_item. See also: Glib.List_Model.Get_N_Items Since: gtk+ 2.44
the position of the item to fetch
the object at Position. Has transfer-ownership='full'.
function Get_Item_Type (Self : Glist_Model) return GType
Gets the type of the items in List. All items returned from g_list_model_get_item are of the type returned by this function, or a subtype, or if the type is an interface, they are an implementation of that interface. The item type of a Glib.List_Model.Glist_Model can not change during the life of the model. Since: gtk+ 2.44
the GType of the items contained in List.
function Get_N_Items (Self : Glist_Model) return Guint
Gets the number of items in List. Depending on the model implementation, calling this function may be less efficient than iterating the list with increasing values for Position until g_list_model_get_item returns null. Since: gtk+ 2.44
the number of items in List.
function Get_Type return Glib.GType
type Glist_Model is new Glib.Types.GType_Interface;
procedure Items_Changed
(Self : Glist_Model;
Position : Guint;
Removed : Guint;
Added : Guint)
Emits the Glib.List_Model.Glist_Model::items-changed signal on List. This function should only be called by classes implementing Glib.List_Model.Glist_Model. It has to be called after the internal representation of List has been updated, because handlers connected to this signal might query the new state of the list. Implementations must only make changes to the model (as visible to its consumer) in places that will not cause problems for that consumer. For models that are driven directly by a write API (such as Glib.List_Store.Glist_Store), changes can be reported in response to uses of that API. For models that represent remote data, changes should only be made from a fresh mainloop dispatch. It is particularly not permitted to make changes in response to a call to the Glib.List_Model.Glist_Model consumer API. Stated another way: in general, it is assumed that code making a series of accesses to the model via the API, without returning to the mainloop, and without calling other code, will continue to view the same contents of the model. Since: gtk+ 2.44
the position at which List changed
the number of items removed
the number of items added
subtype List_Model_Interface_Descr is Glib.Object.Interface_Description;
Null_Glist_Model : constant Glist_Model;
procedure On_Items_Changed
(Self : Glist_Model;
Call : Cb_Glist_Model_Guint_Guint_Guint_Void;
After : Boolean := False)
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.
Note: If removed != added, the positions of all later items in the model change.
Callback parameters: -- @param Position the position at which List changed -- @param Removed the number of items removed -- @param Added the number of items added
procedure On_Items_Changed
(Self : Glist_Model;
Call : Cb_GObject_Guint_Guint_Guint_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
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.
Note: If removed != added, the positions of all later items in the model change.
Callback parameters: -- @param Position the position at which List changed -- @param Removed the number of items removed -- @param Added the number of items added
procedure Set_Get_Item
(Self : List_Model_Interface_Descr;
Handler : Virtual_Get_Item)
procedure Set_Get_Item_Type
(Self : List_Model_Interface_Descr;
Handler : Virtual_Get_Item_Type)
procedure Set_Get_N_Items
(Self : List_Model_Interface_Descr;
Handler : Virtual_Get_N_Items)
See Glib.Object.Add_Interface
Signal_Items_Changed : constant Glib.Signal_Name := "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.
Note: If removed != added, the positions of all later items in the model change.
Callback parameters: -- @param Position the position at which List changed -- @param Removed the number of items removed -- @param Added the number of items added
type Virtual_Get_Item is access function (Self : Glist_Model; Position : Guint) return System.Address;
Get the item at Position. If Position is greater than the number of items in List, null is returned. null is never returned for an index that is smaller than the length of the list. See Glib.List_Model.Get_N_Items. The same Glib.Object.GObject instance may not appear more than once in a Glib.List_Model.Glist_Model. Since: gtk+ 2.44
the position of the item to fetch
the object at Position.
type Virtual_Get_Item_Type is access function (Self : Glist_Model) return GType;
Gets the type of the items in List. All items returned from g_list_model_get_item are of the type returned by this function, or a subtype, or if the type is an interface, they are an implementation of that interface. The item type of a Glib.List_Model.Glist_Model can not change during the life of the model. Since: gtk+ 2.44
the GType of the items contained in List.
type Virtual_Get_N_Items is access function (Self : Glist_Model) return Guint;
Gets the number of items in List. Depending on the model implementation, calling this function may be less efficient than iterating the list with increasing values for Position until g_list_model_get_item returns null. Since: gtk+ 2.44
the number of items in List.