glibmm: Gio::ListModel Class Reference

glibmm 2.51.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gio::ListModel Class Reference

A dynamic list of objects. More...

`#include <giomm/listmodel.h>`

Inheritance diagram for Gio::ListModel:
[legend]

## Public Member Functions
| ListModel (ListModel&& src) noexcept
ListModel& | operator= (ListModel&& src) noexcept
| ~ListModel () noexceptoverride
GListModel* | gobj ()
| Provides access to the underlying C GObject. More...
const GListModel* | gobj () const
| Provides access to the underlying C GObject. More...
GType | get_item_type () const
| Gets the type of the items in list. More...
guint | get_n_items () const
| Gets the number of items in list. More...
Glib::RefPtr< Glib::ObjectBase > | get_object (guint position)
| Get the item at position. More...
Glib::RefPtr< const Glib::ObjectBase > | get_object (guint position) const
| Get the item at position. More...
Glib::SignalProxy< void(guint, guint, guint)> | signal_items_changed ()
virtual GType | get_item_type_vfunc ()
virtual guint | get_n_items_vfunc ()
virtual gpointer | get_item_vfunc (guint position)
Public Member Functions inherited from Glib::Interface
| Interface ()
| A Default constructor. More...
| Interface (Interface&& src) noexcept
Interface& | operator= (Interface&& src) noexcept
| Interface (const Glib::Interface_Class& interface_class)
| Called by constructors of derived classes. More...
| Interface (GObject* castitem)
| Called by constructors of derived classes. More...
| ~Interface () noexceptoverride
| Interface (const Interface&)=delete
Interface& | operator= (const Interface&)=delete
GObject* | gobj ()
const GObject* | gobj () const
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase&)=delete
ObjectBase& | operator= (const ObjectBase&)=delete
void | set_property_value (const Glib::ustring& property_name, const Glib::ValueBase& value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring& property_name, const PropertyType& value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring& property_name, PropertyType& value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
PropertyType | get_property (const Glib::ustring& property_name) const
| You probably want to use a specific property_*() accessor method instead. More...
sigc::connection | connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void()>& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed (const Glib::ustring& property_name, sigc::slot< void()>&& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject* | gobj ()
| Provides access to the underlying C GObject. More...
const GObject* | gobj () const
| Provides access to the underlying C GObject. More...
GObject* | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src)
void | remove_destroy_notify_callback (void *data) const

## Static Public Member Functions
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Member Functions
| ListModel ()
| You should derive from this class to use it. More...
void | items_changed (guint position, guint removed, guint added)
| Emits the ListModel::signal_items_changed() signal on list. More...
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char* custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info& custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
| ObjectBase (ObjectBase&& src) noexcept
ObjectBase& | operator= (ObjectBase&& src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject* castitem)
void | initialize_move (GObject* castitem, Glib::ObjectBase* previous_wrapper)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::ListModel > | wrap (GListModel* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Additional Inherited Members
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify

## Detailed Description

A dynamic list of objects.

A ListModel represents a mutable list of Glib::Objects. 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::PropertyProxy<>::signal_changed() signal of one or more of the object's properties). Taken together with the signal_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 ListModel 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 ListModel are of (or derived from) the same type. 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: get_n_items() returns the number of items in the list and get_object() 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 get_object() until it returns nullptr.

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 in effect at the time that the model was created.

Since glibmm 2.50:

## Constructor & Destructor Documentation

Gio::ListModel::ListModel | ( |  | ) |
| protected

You should derive from this class to use it.

Gio::ListModel::ListModel | ( | ListModel&& | src | ) |
| noexcept

Gio::ListModel::~ListModel | ( |  | ) |
| overridenoexcept

## Member Function Documentation

static void Gio::ListModel::add_interface | ( | GType | gtype_implementer | ) |
| static

GType Gio::ListModel::get_item_type | ( |  | ) | const

Gets the type of the items in list.

All items returned from Glib::list_model_get_type() are of that type or a subtype, or are an implementation of that interface.

The item type of a ListModel can not change during the life of the model.

Since glibmm 2.50:

Returns
  The Type of the items contained in list.

virtual GType Gio::ListModel::get_item_type_vfunc | ( |  | ) |
| virtual

virtual gpointer Gio::ListModel::get_item_vfunc | ( | guint | position | ) |
| virtual

guint Gio::ListModel::get_n_items | ( |  | ) | const

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 `nullptr`.

Since glibmm 2.50:

Returns
  The number of items in list.

virtual guint Gio::ListModel::get_n_items_vfunc | ( |  | ) |
| virtual

Glib::RefPtr<Glib::ObjectBase> Gio::ListModel::get_object | ( | guint | position | ) |

Get the item at position.

If position is greater than the number of items in list, `nullptr` is returned.

`nullptr` is never returned for an index that is smaller than the length of the list. See g_list_model_get_n_items().

Since glibmm 2.50:

Parameters

  position | The position of the item to fetch.

Returns
  The object at position.

Glib::RefPtr<const Glib::ObjectBase> Gio::ListModel::get_object | ( | guint | position | ) | const

Get the item at position.

If position is greater than the number of items in list, `nullptr` is returned.

`nullptr` is never returned for an index that is smaller than the length of the list. See g_list_model_get_n_items().

Since glibmm 2.50:

Parameters

  position | The position of the item to fetch.

Returns
  The object at position.

static GType Gio::ListModel::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

GListModel* Gio::ListModel::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

const GListModel* Gio::ListModel::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

void Gio::ListModel::items_changed | ( | guint | position,
|  | guint | removed,
|  | guint | added
| ) |  |
| protected

Emits the ListModel::signal_items_changed() signal on list.

This function should only be called by classes implementing ListModel. 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 ListStore), 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 ListModel 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 glibmm 2.50:

Parameters

  position | The position at which list changed.
  removed | The number of items removed.
  added | The number of items added.

ListModel& Gio::ListModel::operator= | ( | ListModel&& | src | ) |
| noexcept

Glib::SignalProxy<void(guint, guint, guint)> Gio::ListModel::signal_items_changed | ( |  | ) |

Slot Prototype:
  `void on_my_items_changed(guint position, guint removed, guint added)`

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

Since glibmm 2.50:

Parameters

  position | The position at which list changed.
  removed | The number of items removed.
  added | The number of items added.

## Friends And Related Function Documentation

Glib::RefPtr< Gio::ListModel > wrap | ( | GListModel * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.