glibmm 2.82.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Gio::ListStore< T_item > Class Template Reference

A simple implementation of Gio::ListModel that stores all items in memory. More...

#include <giomm/liststore.h>

Inheritance diagram for Gio::ListStore< T_item >:
Inheritance graph
[legend]

Public Types

using SlotCompare = sigc::slot< int(const Glib::RefPtr< const T_item > &, const Glib::RefPtr< const T_item > &)>
 A slot that will be called to compare two items.
 
using SlotEqual = sigc::slot< bool(const Glib::RefPtr< const T_item > &, const Glib::RefPtr< const T_item > &)>
 A slot that will be called to compare two items.
 
- Public Types inherited from Gio::ListStoreBase
using SlotCompare = sigc::slot< int(const Glib::RefPtr< const Glib::ObjectBase > &, const Glib::RefPtr< const Glib::ObjectBase > &)>
 A slot that will be called to compare two items.
 
using SlotEqual = sigc::slot< bool(const Glib::RefPtr< const Glib::ObjectBase > &, const Glib::RefPtr< const Glib::ObjectBase > &)>
 A slot that will be called to compare two items.
 
- Public Types inherited from Glib::Object
using DestroyNotify = void(*)(gpointer data)
 

Public Member Functions

Glib::RefPtr< T_itemget_item (guint position)
 Get the item at position.
 
Glib::RefPtr< const T_itemget_item (guint position) const
 Get the item at position.
 
void insert (guint position, const Glib::RefPtr< T_item > &item)
 Inserts item at position.
 
guint insert_sorted (const Glib::RefPtr< T_item > &item, const SlotCompare &slot)
 Inserts item at a position to be determined by the slot.
 
void sort (const SlotCompare &slot)
 Sorts the items according to slot.
 
void append (const Glib::RefPtr< T_item > &item)
 Appends item.
 
void splice (guint position, guint n_removals, const std::vector< Glib::RefPtr< T_item > > &additions)
 Removes n_removals items and adds additions.size() items.
 
std::pair< bool, unsigned intfind (const Glib::RefPtr< const T_item > &item) const
 Looks up the given item in the list store by looping over the items until the first occurrence of item.
 
std::pair< bool, unsigned intfind (const Glib::RefPtr< const T_item > &item, const SlotEqual &slot) const
 Looks up the given item in the list store by looping over the items until the first occurrence of item.
 
- Public Member Functions inherited from Gio::ListStoreBase
 ListStoreBase (ListStoreBase &&src) noexcept
 
ListStoreBaseoperator= (ListStoreBase &&src) noexcept
 
 ~ListStoreBase () noexcept override
 
GListStoregobj ()
 Provides access to the underlying C GObject.
 
const GListStoregobj () const
 Provides access to the underlying C GObject.
 
GListStoregobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
 
void insert (guint position, const Glib::RefPtr< Glib::ObjectBase > &item)
 Inserts item into store at position.
 
guint insert_sorted (const Glib::RefPtr< Glib::ObjectBase > &item, const SlotCompare &slot)
 Inserts item into store at a position to be determined by the slot.
 
void sort (const SlotCompare &slot)
 Sort the items in store according to slot.
 
void append (const Glib::RefPtr< Glib::ObjectBase > &item)
 Appends item to store.
 
void remove (guint position)
 Removes the item from store that is at position.
 
void remove_all ()
 Removes all items from store.
 
void splice (guint position, guint n_removals, const std::vector< Glib::RefPtr< Glib::ObjectBase > > &additions)
 Removes n_removals items and adds additions.size() items.
 
std::pair< bool, unsigned intfind (const Glib::RefPtr< const Glib::ObjectBase > &item) const
 Looks up the given item in the list store by looping over the items until the first occurrence of item.
 
std::pair< bool, unsigned intfind (const Glib::RefPtr< const Glib::ObjectBase > &item, const SlotEqual &slot) const
 Looks up the given item in the list store by looping over the items until the first occurrence of item.
 
Glib::PropertyProxy_ReadOnly< GTypeproperty_item_type () const
 The type of items contained in this list store.
 
Glib::PropertyProxy_ReadOnly< unsigned intproperty_n_items () const
 The number of items contained in this list store.
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&src) noexcept
 
Objectoperator= (Object &&src) noexcept
 
voidget_data (const QueryQuark & key)
 
void set_data (const Quark & key, void *data)
 
void set_data_with_c_callback (const Quark & key, void *data, GDestroyNotify notify)
 
void set_data (const Quark & key, void *data, DestroyNotify notify)
 Prefer set_data_with_c_callback() with a callback with C linkage.
 
void remove_data (const QueryQuark &quark)
 
voidsteal_data (const QueryQuark &quark)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
 
ObjectBaseoperator= (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.
 
- Public Member Functions inherited from Gio::ListModel
 ListModel (ListModel &&src) noexcept
 
ListModeloperator= (ListModel &&src) noexcept
 
 ~ListModel () noexcept override
 
GListModelgobj ()
 Provides access to the underlying C GObject.
 
const GListModelgobj () 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::ObjectBaseget_object (guint position)
 Get the item at position.
 
Glib::RefPtr< const Glib::ObjectBaseget_object (guint position) const
 Get the item at position.
 
template<typename T_item >
Glib::RefPtr< T_itemget_typed_object (guint position)
 Get the item at position.
 
template<typename T_item >
Glib::RefPtr< const T_itemget_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
 
Interfaceoperator= (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
 
Interfaceoperator= (const Interface &)=delete
 
GObject * gobj ()
 
const GObject * gobj () const
 

Static Public Member Functions

static Glib::RefPtr< ListStorecreate ()
 
- Static Public Member Functions inherited from Gio::ListStoreBase
static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system.
 
static Glib::RefPtr< ListStoreBasecreate (GType item_type)
 
- Static Public Member Functions inherited from Gio::ListModel
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

 ListStore ()
 
- Protected Member Functions inherited from Gio::ListStoreBase
 ListStoreBase (GType item_type)
 
- Protected Member Functions inherited from Glib::Object
 Object ()
 
 Object (const Glib::ConstructParams &construct_params)
 
 Object (GObject *castitem)
 
 ~Object () noexcept override
 
- 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
 
ObjectBaseoperator= (ObjectBase &&src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject *castitem)
 
void initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
 
- Protected Member Functions inherited from Gio::ListModel
 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)
 

Additional Inherited Members

Detailed Description

template<typename T_item>
class Gio::ListStore< T_item >

A simple implementation of Gio::ListModel that stores all items in memory.

It provides insertions, deletions, and lookups in logarithmic time with a fast path for the common case of iterating the list linearly.

Since glibmm 2.50:
Template Parameters
T_itemBase class of the items in the ListStore. All items must be of type T_item or a type derived from T_item. T_item must be Glib::ObjectBase or a type derived from Glib::ObjectBase.

Member Typedef Documentation

◆ SlotCompare

A slot that will be called to compare two items.

The slot should return a negative integer if the first item comes before the second, 0 if they are equal, or a positive integer if the first value comes after the second. For instance,

int on_compare_item(const Glib::RefPtr<const T_item>& item1, const Glib::RefPtr<const T_item>& item2);
Since glibmm 2.50:

◆ SlotEqual

template <typename T_item >
using Gio::ListStore< T_item >::SlotEqual = sigc::slot<bool(const Glib::RefPtr<const T_item>&, const Glib::RefPtr<const T_item>&)>

A slot that will be called to compare two items.

The slot should return true if the items are equal, false if they are not equal. For instance,

bool on_equal_item(const Glib::RefPtr<const T_item>& item1, const Glib::RefPtr<const T_item>& item2);
Since glibmm 2.74:

Constructor & Destructor Documentation

◆ ListStore()

template <typename T_item >
Gio::ListStore< T_item >::ListStore ( )
protected

Member Function Documentation

◆ append()

template <typename T_item >
void Gio::ListStore< T_item >::append ( const Glib::RefPtr< T_item > &  item)

Appends item.

item must be of type ListStoreBase::property_item_type() or derived from it.

Use splice() to append multiple items at the same time efficiently.

Since glibmm 2.50:
Parameters
itemThe new item.

◆ create()

template <typename T_item >
static Glib::RefPtr< ListStore > Gio::ListStore< T_item >::create ( )
static

◆ find() [1/2]

template <typename T_item >
std::pair< bool, unsigned int > Gio::ListStore< T_item >::find ( const Glib::RefPtr< const T_item > &  item) const

Looks up the given item in the list store by looping over the items until the first occurrence of item.

If you need to compare the two items with a custom comparison function, use find(const Glib::RefPtr<const T_item>& item, const SlotEqual& slot) const instead.

Since glibmm 2.74:
Parameters
itemAn item.
Returns
{item_found, position} Whether the ListStore contains item. If it was found, position will be set to the position where item occurred for the first time, else position = std::numeric_limits<unsigned int>::max().

◆ find() [2/2]

template <typename T_item >
std::pair< bool, unsigned int > Gio::ListStore< T_item >::find ( const Glib::RefPtr< const T_item > &  item,
const SlotEqual slot 
) const

Looks up the given item in the list store by looping over the items until the first occurrence of item.

If you don't need to compare the two items with a custom comparison function, use find(const Glib::RefPtr<const T_item>& item) const instead.

Since glibmm 2.74:
Parameters
itemAn item.
slotA comparison function.
Returns
{item_found, position} Whether the ListStore contains item. If it was found, position will be set to the position where item occurred for the first time, else position = std::numeric_limits<unsigned int>::max().

◆ get_item() [1/2]

template <typename T_item >
Glib::RefPtr< T_item > Gio::ListStore< T_item >::get_item ( guint  position)

Get the item at position.

If position is greater than or equal to the number of items in list, an empty Glib::RefPtr is returned.

An empty Glib::RefPtr is never returned for an index that is less than the length of the list. See ListModel::get_n_items().

Since glibmm 2.50:
Parameters
positionThe position of the item to fetch.
Returns
The object at position.

◆ get_item() [2/2]

template <typename T_item >
Glib::RefPtr< const T_item > Gio::ListStore< T_item >::get_item ( guint  position) const

Get the item at position.

If position is greater than or equal to the number of items in list, an empty Glib::RefPtr is returned.

An empty Glib::RefPtr is never returned for an index that is less than the length of the list. See ListModel::get_n_items().

Since glibmm 2.50:
Parameters
positionThe position of the item to fetch.
Returns
The object at position.

◆ insert()

template <typename T_item >
void Gio::ListStore< T_item >::insert ( guint  position,
const Glib::RefPtr< T_item > &  item 
)

Inserts item at position.

item must be of type ListStoreBase::property_item_type() or derived from it. position must be smaller than the length of the list, or equal to it to append.

Use splice() to insert multiple items at the same time efficiently.

Since glibmm 2.50:
Parameters
positionThe position at which to insert the new item.
itemThe new item.

◆ insert_sorted()

template <typename T_item >
guint Gio::ListStore< T_item >::insert_sorted ( const Glib::RefPtr< T_item > &  item,
const SlotCompare slot 
)

Inserts item at a position to be determined by the slot.

The list must already be sorted before calling this function or the result is undefined. Usually you would approach this by only ever inserting items by way of this function.

Since glibmm 2.50:
Parameters
itemThe new item.
slotPairwise comparison function for sorting.
Returns
The position at which item was inserted.

◆ sort()

template <typename T_item >
void Gio::ListStore< T_item >::sort ( const SlotCompare slot)

Sorts the items according to slot.

Since glibmm 2.50:
Parameters
slotPairwise comparison function for sorting.

◆ splice()

template <typename T_item >
void Gio::ListStore< T_item >::splice ( guint  position,
guint  n_removals,
const std::vector< Glib::RefPtr< T_item > > &  additions 
)

Removes n_removals items and adds additions.size() items.

additions must contain items of type ListStoreBase::property_item_type() or derived from it. Empty RefPtr is not permitted.

This function is more efficient than insert() and remove(), because it only emits ListModel::signal_items_changed() once for the change.

The parameters position and n_removals must be correct (i.e. position + n_removals must be less than or equal to the length of the list at the time this function is called).

Since glibmm 2.50:
Parameters
positionThe position at which to make the change.
n_removalsThe number of items to remove.
additionsThe items to add.