glibmm 2.82.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Gio::ListStoreBase Class Reference

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

#include <giomm/liststore.h>

Inheritance diagram for Gio::ListStoreBase:
Inheritance graph
[legend]

Public Types

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

 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 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

 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

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

The templated subclass ListStore<> provides better compile-time type safety.

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:

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,

Since glibmm 2.50:

◆ SlotEqual

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 Glib::ObjectBase>& item1, const Glib::RefPtr<const Glib::ObjectBase>& item2);
Since glibmm 2.74:

Constructor & Destructor Documentation

◆ ListStoreBase() [1/2]

Gio::ListStoreBase::ListStoreBase ( ListStoreBase &&  src)
noexcept

◆ ~ListStoreBase()

Gio::ListStoreBase::~ListStoreBase ( )
overridenoexcept

◆ ListStoreBase() [2/2]

Gio::ListStoreBase::ListStoreBase ( GType  item_type)
explicitprotected

Member Function Documentation

◆ append()

void Gio::ListStoreBase::append ( const Glib::RefPtr< Glib::ObjectBase > &  item)

Appends item to store.

item must be of type ListStore::property_item_type().

This function takes a ref on item.

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

Since glibmm 2.50:
Parameters
itemThe new item.

◆ create()

static Glib::RefPtr< ListStoreBase > Gio::ListStoreBase::create ( GType  item_type)
static

◆ find() [1/2]

std::pair< bool, unsigned int > Gio::ListStoreBase::find ( 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.

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

Since glibmm 2.74:
Parameters
itemAn item.
Returns
{item_found, position} Whether the ListStoreBase 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]

std::pair< bool, unsigned int > Gio::ListStoreBase::find ( 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.

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

Since glibmm 2.74:
Parameters
itemAn item.
slotA comparison function.
Returns
{item_found, position} Whether the ListStoreBase 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_type()

static GType Gio::ListStoreBase::get_type ( )
static

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

◆ gobj() [1/2]

GListStore * Gio::ListStoreBase::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GListStore * Gio::ListStoreBase::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GListStore * Gio::ListStoreBase::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ insert()

void Gio::ListStoreBase::insert ( guint  position,
const Glib::RefPtr< Glib::ObjectBase > &  item 
)

Inserts item into store at position.

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

This function takes a ref on item.

Use g_list_store_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()

guint Gio::ListStoreBase::insert_sorted ( const Glib::RefPtr< Glib::ObjectBase > &  item,
const SlotCompare slot 
)

Inserts item into store 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.

This function takes a ref on item.

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

◆ operator=()

ListStoreBase & Gio::ListStoreBase::operator= ( ListStoreBase &&  src)
noexcept

◆ property_item_type()

Glib::PropertyProxy_ReadOnly< GType > Gio::ListStoreBase::property_item_type ( ) const

The type of items contained in this list store.

Items must be subclasses of Object.

Since glibmm 2.50:
Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_n_items()

Glib::PropertyProxy_ReadOnly< unsigned int > Gio::ListStoreBase::property_n_items ( ) const

The number of items contained in this list store.

Since glibmm 2.74:

Default value: 0

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ remove()

void Gio::ListStoreBase::remove ( guint  position)

Removes the item from store that is at position.

position must be smaller than the current length of the list.

Use g_list_store_splice() to remove multiple items at the same time efficiently.

Since glibmm 2.50:
Parameters
positionThe position of the item that is to be removed.

◆ remove_all()

void Gio::ListStoreBase::remove_all ( )

Removes all items from store.

Since glibmm 2.50:

◆ sort()

void Gio::ListStoreBase::sort ( const SlotCompare slot)

Sort the items in store according to slot.

Since glibmm 2.50:
Parameters
slotPairwise comparison function for sorting.

◆ splice()

void Gio::ListStoreBase::splice ( guint  position,
guint  n_removals,
const std::vector< Glib::RefPtr< Glib::ObjectBase > > &  additions 
)

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

additions must contain items of type 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.