glibmm 2.82.0
|
A dynamic list of objects. More...
#include <giomm/listmodel.h>
Public Member Functions | |
ListModel (ListModel &&src) noexcept | |
ListModel & | operator= (ListModel &&src) noexcept |
~ListModel () noexcept override | |
GListModel * | gobj () |
Provides access to the underlying C GObject. | |
const GListModel * | gobj () const |
Provides access to the underlying C GObject. | |
GType | get_item_type () const |
Gets the type of the items in list. | |
guint | get_n_items () const |
Gets the number of items in list. | |
Glib::RefPtr< Glib::ObjectBase > | get_object (guint position) |
Get the item at position. | |
Glib::RefPtr< const Glib::ObjectBase > | get_object (guint position) const |
Get the item at position. | |
template<typename T_item > | |
Glib::RefPtr< T_item > | get_typed_object (guint position) |
Get the item at position. | |
template<typename T_item > | |
Glib::RefPtr< const T_item > | get_typed_object (guint position) const |
Get the item at position. | |
Glib::SignalProxy< void(guint, guint, guint)> | signal_items_changed () |
Public Member Functions inherited from Glib::Interface | |
Interface () | |
A Default constructor. | |
Interface (Interface &&src) noexcept | |
Interface & | operator= (Interface &&src) noexcept |
Interface (const Glib::Interface_Class &interface_class) | |
Called by constructors of derived classes. | |
Interface (GObject *castitem) | |
Called by constructors of derived classes. | |
~Interface () noexcept override | |
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. | |
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const |
You probably want to use a specific property_*() accessor method instead. | |
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. | |
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. | |
template<class PropertyType > | |
PropertyType | get_property (const Glib::ustring & property_name) const |
You probably want to use a specific property_*() accessor method instead. | |
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. | |
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. | |
void | freeze_notify () |
Increases the freeze count on object. | |
void | thaw_notify () |
Reverts the effect of a previous call to freeze_notify(). | |
virtual void | reference () const |
Increment the reference count for this object. | |
virtual void | unreference () const |
Decrement the reference count for this object. | |
GObject * | gobj () |
Provides access to the underlying C GObject. | |
const GObject * | gobj () const |
Provides access to the underlying C GObject. | |
GObject * | gobj_copy () const |
Give a ref-ed copy to someone. Use for direct struct access. | |
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. | |
Protected Member Functions | |
ListModel () | |
You should derive from this class to use it. | |
void | items_changed (guint position, guint removed, guint added) |
Emits the ListModel::signal_items_changed() signal on list. | |
virtual GType | get_item_type_vfunc () |
virtual guint | get_n_items_vfunc () |
virtual gpointer | get_item_vfunc (guint position) |
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. | |
ObjectBase (const char *custom_type_name) | |
A derived constructor always overrides this choice. | |
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. | |
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 Symbols | |
(Note that these are not member symbols.) | |
Glib::RefPtr< Gio::ListModel > | wrap (GListModel *object, bool take_copy=false) |
A Glib::wrap() method for this object. | |
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.
|
protected |
You should derive from this class to use it.
|
noexcept |
|
overridenoexcept |
GType Gio::ListModel::get_item_type | ( | ) | const |
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 ListModel can not change during the life of the model.
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
.
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.
This function is meant to be used by language bindings in place of g_list_model_get_item().
See also: g_list_model_get_n_items()
position | The position of the item to fetch. |
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.
This function is meant to be used by language bindings in place of g_list_model_get_item().
See also: g_list_model_get_n_items()
position | The position of the item to fetch. |
Get the GType for this class, for use with the underlying GObject type system.
Glib::RefPtr< T_item > Gio::ListModel::get_typed_object | ( | guint | position | ) |
Get the item at position.
If position is greater than the number of items in list, an empty RefPtr is returned.
is often equivalent to
If T_item is an interface, and the underlying C object is an instance of a C class that implements that interface, but there is no corresponding C++ class, get_typed_object() may manage to fetch the item even if get_object() fails and returns an empty RefPtr.
T_item | The item to fetch must be of type T_item or a type derived from T_item, otherwise an empty RefPtr is returned. T_item must be Glib::ObjectBase or a type derived from Glib::ObjectBase. |
position | The position of the item to fetch. |
Glib::RefPtr< const T_item > Gio::ListModel::get_typed_object | ( | guint | position | ) | const |
Get the item at position.
See the non-const version.
T_item | The item to fetch must be of type T_item or a type derived from T_item, otherwise an empty RefPtr is returned. T_item must be Glib::ObjectBase or a type derived from Glib::ObjectBase. |
position | The position of the item to fetch. |
|
inline |
Provides access to the underlying C GObject.
|
inline |
Provides access to the underlying C GObject.
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.
position | The position at which list changed. |
removed | The number of items removed. |
added | The number of items added. |
void on_my_items_changed(guint position, guint removed, guint added)
Flags: Run Last
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.
removed != added
, the positions of all later items in the model change.position | The position at which list changed. |
removed | The number of items removed. |
added | The number of items added. |
|
related |
A Glib::wrap() method for this object.
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. |