gtkmm  4.8.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::TreeListModel Class Reference

A list model that can create child models on demand. More...

#include <gtkmm/treelistmodel.h>

Inherits Glib::Object, and Gio::ListModel.

Public Types

using SlotCreateModel = sigc::slot< Glib::RefPtr< Gio::ListModel >(const Glib::RefPtr< Glib::ObjectBase > &)>
 For instance: Glib::RefPtr<Gio::ListModel> create_func(const Glib::RefPtr<Glib::ObjectBase>& item);. More...
 

Public Member Functions

 TreeListModel (TreeListModel && src) noexcept
 
TreeListModeloperator= (TreeListModel && src) noexcept
 
 ~TreeListModel () noexcept override
 
GtkTreeListModel * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkTreeListModel * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkTreeListModel * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
Glib::RefPtr< Gio::ListModel > get_model ()
 Gets the root model that self was created with. More...
 
Glib::RefPtr< const Gio::ListModel > get_model () const
 Gets the root model that self was created with. More...
 
bool get_passthrough () const
 Gets whether the model is passing through original row items. More...
 
void set_autoexpand (bool autoexpand=true)
 Sets whether the model should autoexpand. More...
 
bool get_autoexpand () const
 Gets whether the model is set to automatically expand new rows that get added. More...
 
Glib::RefPtr< TreeListRowget_child_row (guint position)
 Gets the row item corresponding to the child at index position for self's root model. More...
 
Glib::RefPtr< const TreeListRowget_child_row (guint position) const
 Gets the row item corresponding to the child at index position for self's root model. More...
 
Glib::RefPtr< TreeListRowget_row (guint position)
 Gets the row object for the given row. More...
 
Glib::RefPtr< const TreeListRowget_row (guint position) const
 Gets the row object for the given row. More...
 
Glib::PropertyProxy< bool > property_autoexpand ()
 If all rows should be expanded by default. More...
 
Glib::PropertyProxy_ReadOnly< bool > property_autoexpand () const
 If all rows should be expanded by default. More...
 
Glib::PropertyProxy_ReadOnly< GType > property_item_type () const
 The type of items. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::ListModel > > property_model () const
 The root model displayed. More...
 
Glib::PropertyProxy_ReadOnly< unsigned int > property_n_items () const
 The number of items. More...
 
Glib::PropertyProxy_ReadOnly< bool > property_passthrough () const
 Gets whether the model is in passthrough mode. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< TreeListModelcreate (const Glib::RefPtr< Gio::ListModel > & root, const SlotCreateModel & slot_create, bool passthrough=false, bool autoexpand=false)
 Creates a new empty Gtk::TreeListModel displaying root with all rows collapsed. More...
 

Protected Member Functions

 TreeListModel (const Glib::RefPtr< Gio::ListModel > & root, const SlotCreateModel & slot_create, bool passthrough=false, bool autoexpand=false)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::TreeListModelwrap (GtkTreeListModel * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

A list model that can create child models on demand.

Gtk::TreeListModel is a Gio::ListModel implementation that can expand rows by creating new child list models on demand.

See also
Gio::ListModel
Since gtkmm 3.98:

Member Typedef Documentation

◆ SlotCreateModel

using Gtk::TreeListModel::SlotCreateModel = sigc::slot<Glib::RefPtr<Gio::ListModel>(const Glib::RefPtr<Glib::ObjectBase>&)>

For instance: Glib::RefPtr<Gio::ListModel> create_func(const Glib::RefPtr<Glib::ObjectBase>& item);.

Prototype of the function called to create new child models when Gtk::TreeListRow::set_expanded() is called.

This function can return nullptr to indicate that item is guaranteed to be a leaf node and will never have children. If it does not have children but may get children later, it should return an empty model that is filled once children arrive.

Parameters
itemThe item that is being expanded.
Returns
The model tracking the children of item or nullptr if item can never have children.

Constructor & Destructor Documentation

◆ TreeListModel() [1/2]

Gtk::TreeListModel::TreeListModel ( TreeListModel &&  src)
noexcept

◆ ~TreeListModel()

Gtk::TreeListModel::~TreeListModel ( )
overridenoexcept

◆ TreeListModel() [2/2]

Gtk::TreeListModel::TreeListModel ( const Glib::RefPtr< Gio::ListModel > &  root,
const SlotCreateModel slot_create,
bool  passthrough = false,
bool  autoexpand = false 
)
protected

Member Function Documentation

◆ create()

static Glib::RefPtr<TreeListModel> Gtk::TreeListModel::create ( const Glib::RefPtr< Gio::ListModel > &  root,
const SlotCreateModel slot_create,
bool  passthrough = false,
bool  autoexpand = false 
)
static

Creates a new empty Gtk::TreeListModel displaying root with all rows collapsed.

Parameters
rootThe Gio::ListModel to use as root.
slot_createSlot to call to create the Gio::ListModel for the children of an item.
passthroughtrue to pass through items from the models.
autoexpandtrue to set the autoexpand property and expand the root model.

◆ get_autoexpand()

bool Gtk::TreeListModel::get_autoexpand ( ) const

Gets whether the model is set to automatically expand new rows that get added.

This can be either rows added by changes to the underlying models or via Gtk::TreeListRow::set_expanded().

Returns
true if the model is set to autoexpand.

◆ get_child_row() [1/2]

Glib::RefPtr<TreeListRow> Gtk::TreeListModel::get_child_row ( guint  position)

Gets the row item corresponding to the child at index position for self's root model.

If position is greater than the number of children in the root model, nullptr is returned.

Do not confuse this function with get_row().

Parameters
positionPosition of the child to get.
Returns
The child in position.

◆ get_child_row() [2/2]

Glib::RefPtr<const TreeListRow> Gtk::TreeListModel::get_child_row ( guint  position) const

Gets the row item corresponding to the child at index position for self's root model.

If position is greater than the number of children in the root model, nullptr is returned.

Do not confuse this function with get_row().

Parameters
positionPosition of the child to get.
Returns
The child in position.

◆ get_model() [1/2]

Glib::RefPtr<Gio::ListModel> Gtk::TreeListModel::get_model ( )

Gets the root model that self was created with.

Returns
The root model.

◆ get_model() [2/2]

Glib::RefPtr<const Gio::ListModel> Gtk::TreeListModel::get_model ( ) const

Gets the root model that self was created with.

Returns
The root model.

◆ get_passthrough()

bool Gtk::TreeListModel::get_passthrough ( ) const

Gets whether the model is passing through original row items.

If this function returns false, the Gio::ListModel functions for self return custom Gtk::TreeListRow objects. You need to call Gtk::TreeListRow::get_item() on these objects to get the original item.

If true, the values of the child models are passed through in their original state. You then need to call get_row() to get the custom Gtk::TreeListRows.

Returns
true if the model is passing through original row items.

◆ get_row() [1/2]

Glib::RefPtr<TreeListRow> Gtk::TreeListModel::get_row ( guint  position)

Gets the row object for the given row.

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

The row object can be used to expand and collapse rows as well as to inspect its position in the tree. See its documentation for details.

This row object is persistent and will refer to the current item as long as the row is present in self, independent of other rows being added or removed.

If self is set to not be passthrough, this function is equivalent to calling Glib::list_model_get_item().

Do not confuse this function with get_child_row().

Parameters
positionThe position of the row to fetch.
Returns
The row item.

◆ get_row() [2/2]

Glib::RefPtr<const TreeListRow> Gtk::TreeListModel::get_row ( guint  position) const

Gets the row object for the given row.

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

The row object can be used to expand and collapse rows as well as to inspect its position in the tree. See its documentation for details.

This row object is persistent and will refer to the current item as long as the row is present in self, independent of other rows being added or removed.

If self is set to not be passthrough, this function is equivalent to calling Glib::list_model_get_item().

Do not confuse this function with get_child_row().

Parameters
positionThe position of the row to fetch.
Returns
The row item.

◆ get_type()

static GType Gtk::TreeListModel::get_type ( )
static

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

◆ gobj() [1/2]

GtkTreeListModel* Gtk::TreeListModel::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkTreeListModel* Gtk::TreeListModel::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkTreeListModel* Gtk::TreeListModel::gobj_copy ( )

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

◆ operator=()

TreeListModel& Gtk::TreeListModel::operator= ( TreeListModel &&  src)
noexcept

◆ property_autoexpand() [1/2]

Glib::PropertyProxy< bool > Gtk::TreeListModel::property_autoexpand ( )

If all rows should be expanded by default.

Default value: false

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

◆ property_autoexpand() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gtk::TreeListModel::property_autoexpand ( ) const

If all rows should be expanded by default.

Default value: false

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_item_type()

Glib::PropertyProxy_ReadOnly< GType > Gtk::TreeListModel::property_item_type ( ) const

The type of items.

See Gio::ListModel::get_item_type().

Since gtkmm 4.8:
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_model()

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Gio::ListModel> > Gtk::TreeListModel::property_model ( ) const

The root model displayed.

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 > Gtk::TreeListModel::property_n_items ( ) const

The number of items.

See Gio::ListModel::get_n_items().

Since gtkmm 4.8:

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.

◆ property_passthrough()

Glib::PropertyProxy_ReadOnly< bool > Gtk::TreeListModel::property_passthrough ( ) const

Gets whether the model is in passthrough mode.

If false, the Gio::ListModel functions for this object return custom Gtk::TreeListRow objects. If true, the values of the child models are pass through unmodified.

Default value: false

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

◆ set_autoexpand()

void Gtk::TreeListModel::set_autoexpand ( bool  autoexpand = true)

Sets whether the model should autoexpand.

If set to true, the model will recursively expand all rows that get added to the model. This can be either rows added by changes to the underlying models or via Gtk::TreeListRow::set_expanded().

Parameters
autoexpandtrue to make the model autoexpand its rows.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gtk::TreeListModel > wrap ( GtkTreeListModel *  object,
bool  take_copy = false 
)
related

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

Parameters
objectThe C instance.
take_copyFalse 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.