gtkmm: Gtk::TreeSelection Class Reference

Typedefed as Gtk::TreeView::Selection. More...

#include <gtkmm/treeselection.h>

Inheritance diagram for Gtk::TreeSelection:

Public Types

using SlotSelect = sigc::slot< bool(const Glib::RefPtr< TreeModel >&, const TreeModel::Path&, bool)>
 For instance, bool on_select_function(const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool path_currently_selected);. More...

 
using SlotForeachIter = sigc::slot< void(const TreeModel::const_iterator&)>
 For example, void on_foreach(const Gtk::TreeModel::const_iterator& iter);. More...

 
using SlotForeachPath = sigc::slot< void(const TreeModel::Path&)>
 For example, void on_foreach(const Gtk::TreeModel::Path& path);. More...

 
using SlotForeachPathAndIter = sigc::slot< void(const TreeModel::Path&, const TreeModel::const_iterator&)>
 For example, void on_foreach(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::const_iterator& iter);. More...

 
- Public Types inherited from Glib::Object
typedef void(*)(gpointer data DestroyNotify)
 
- Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify func_destroy_notify
 
- Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify func_destroy_notify
 

Public Member Functions

 TreeSelection (TreeSelection&& src) noexcept
 
TreeSelectionoperator= (TreeSelection&& src) noexcept
 
 ~TreeSelection () noexcept override
 
GtkTreeSelection* gobj ()
 Provides access to the underlying C GObject. More...

 
const GtkTreeSelection* gobj () const
 Provides access to the underlying C GObject. More...

 
GtkTreeSelection* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...

 
void set_mode (SelectionMode type)
 Sets the selection mode of the selection. More...

 
SelectionMode get_mode () const
 Gets the selection mode for selection. More...

 
void set_select_function (const SlotSelect& slot)
 Sets the selection callback slot. More...

 
TreeViewget_tree_view ()
 Returns the tree view associated with selection. More...

 
const TreeViewget_tree_view () const
 Returns the tree view associated with selection. More...

 
Glib::RefPtr< TreeModelget_model ()
 Shortcut for get_tree_view()->get_model(). More...

 
Glib::RefPtr< const TreeModelget_model () const
 
TreeModel::iterator get_selected ()
 Get the currently selected row. More...

 
TreeModel::const_iterator get_selected () const
 Get the currently selected row. More...

 
TreeModel::iterator get_selected (Glib::RefPtr< TreeModel >& model)
 Get the currently selected row. More...

 
TreeModel::const_iterator get_selected (Glib::RefPtr< const TreeModel >& model) const
 Get the currently selected row. More...

 
std::vector< TreeModel::Pathget_selected_rows () const
 Creates a vector of paths of all selected rows. More...

 
std::vector< TreeModel::Pathget_selected_rows (Glib::RefPtr< TreeModel >& model)
 Creates a list of paths of all selected rows. More...

 
int count_selected_rows () const
 Returns the number of rows that have been selected in tree. More...

 
void selected_foreach_iter (const SlotForeachIter& slot) const
 Calls a callback slot for each selected node. More...

 
void selected_foreach_path (const SlotForeachPath& slot) const
 Calls a callback slot for each selected node. More...

 
void selected_foreach (const SlotForeachPathAndIter& slot) const
 Calls a callback slot for each selected node. More...

 
void select (const TreeModel::Path& path)
 Select the row at path. More...

 
void select (const TreeModel::Path& start_path, const TreeModel::Path& end_path)
 Selects a range of nodes, determined by start_path and end_path inclusive. More...

 
void select (const TreeModel::const_iterator& iter)
 Selects the specified iterator. More...

 
void unselect (const TreeModel::Path& path)
 Unselects the row at path. More...

 
void unselect (const TreeModel::Path& start_path, const TreeModel::Path& end_path)
 Unselects a range of nodes, determined by start_path and end_path inclusive. More...

 
void unselect (const TreeModel::const_iterator& iter)
 Unselects the specified iterator. More...

 
bool is_selected (const TreeModel::Path& path) const
 Returns true if the row pointed to by path is currently selected. More...

 
bool is_selected (const TreeModel::const_iterator& iter) const
 Returns true if the row at iter is currently selected. More...

 
void select_all ()
 Selects all the nodes. More...

 
void unselect_all ()
 Unselects all the nodes. More...

 
Glib::PropertyProxy< SelectionModeproperty_mode ()
 Selection mode. More...

 
Glib::PropertyProxy_ReadOnly< SelectionModeproperty_mode () const
 Selection mode. More...

 
Glib::SignalProxy< void()> signal_changed ()
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&src) noexcept
 
Objectoperator= (Object &&src) noexcept
 
void * get_data (const QueryQuark &key)
 
void set_data (const Quark &key, void *data)
 
void set_data (const Quark &key, void *data, DestroyNotify notify)
 
void remove_data (const QueryQuark &quark)
 
void * steal_data (const QueryQuark &quark)
 
Glib::RefPtr< Glib::Objectwrap (GObject *object, bool take_copy=false)
 
- 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)
 
void get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
 
void set_property (const Glib::ustring &property_name, const PropertyType &value)
 
void get_property (const Glib::ustring &property_name, PropertyType &value) const
 
PropertyType get_property (const Glib::ustring &property_name) const
 
sigc::connection connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
 
sigc::connection connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
 
void freeze_notify ()
 
void thaw_notify ()
 
virtual void reference () const
 
virtual void unreference () const
 
GObject * gobj ()
 
const GObject * gobj () const
 
GObject * gobj_copy () const
 
- Public Member Functions inherited from sigc::trackable
 trackable () noexcept
 
 trackable (const trackable &src) noexcept
 
 trackable (trackable &&src) noexcept
 
 ~trackable ()
 
void add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
 
void notify_callbacks ()
 
trackableoperator= (const trackable &src)
 
trackableoperator= (trackable &&src) noexcept
 
void remove_destroy_notify_callback (notifiable *data) const
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...

 

Related Functions

(Note that these are not member functions.)

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

 

Additional Inherited Members

- 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 ()
 
 ObjectBase (const char *custom_type_name)
 
 ObjectBase (const std::type_info &custom_type_info)
 
 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)
 

Detailed Description

Typedefed as Gtk::TreeView::Selection.

This is a helper object to manage the selection for a Gtk::TreeView widget.

It is automatically created when a new Gtk::TreeView widget is created, and cannot exist independently of this widget. The primary reason this class exists is for cleanliness of code and API. That is, there is no conceptual reason all these methods could not be methods on the Gtk::TreeView widget instead of a separate class.

The Gtk::TreeSelection object can be obtained from a Gtk::TreeView by calling Gtk::TreeView::get_selection(). It can be manipulated to check the selection status of the tree, as well as to select and deselect individual rows. Selection is done completely view-side. As a result, multiple views of the same model can have completely different selections. Additionally, you cannot change the selection of a row on the model that is not currently displayed by the view without expanding its parents first.

When monitoring the selection of a view, it's important to remember that the "changed" signal is mostly a hint. That is, it may only emit one signal when a range of rows is selected. Additionally, it may on occasion emit a "changed" signal when nothing has happened.

Member Typedef Documentation

For example, void on_foreach(const Gtk::TreeModel::const_iterator& iter);.

Note that you cannot modify the tree or selection from within the callback function. As a result, get_selected_rows() might be more useful.

using Gtk::TreeSelection::SlotForeachPath = sigc::slot<void(const TreeModel::Path&)>

For example, void on_foreach(const Gtk::TreeModel::Path& path);.

Note that you cannot modify the tree or selection from within the callback function. As a result, get_selected_rows() might be more useful.

For example, void on_foreach(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::const_iterator& iter);.

Note that you cannot modify the tree or selection from within the callback function. As a result, get_selected_rows() might be more useful.

using Gtk::TreeSelection::SlotSelect = sigc::slot<bool(const Glib::RefPtr<TreeModel>&, const TreeModel::Path&, bool)>

For instance, bool on_select_function(const Glib::RefPtr<TreeModel>& model, const TreeModel::Path& path, bool path_currently_selected);.

The select function should return true if the state of the node may be toggled, and false if the state of the node should be left unchanged.

Constructor & Destructor Documentation

Gtk::TreeSelection::TreeSelection ( TreeSelection&&  src)
noexcept
Gtk::TreeSelection::~TreeSelection ( )
overridenoexcept

Member Function Documentation

int Gtk::TreeSelection::count_selected_rows ( ) const

Returns the number of rows that have been selected in tree.

Returns
The number of rows selected.
SelectionMode Gtk::TreeSelection::get_mode ( ) const

Gets the selection mode for selection.

See set_mode().

Returns
The current selection mode.
Glib::RefPtr<TreeModel> Gtk::TreeSelection::get_model ( )

Shortcut for get_tree_view()->get_model().

Returns
The TreeModel associated with this TreeSelection.
Glib::RefPtr<const TreeModel> Gtk::TreeSelection::get_model ( ) const
TreeModel::iterator Gtk::TreeSelection::get_selected ( )

Get the currently selected row.

Returns
The currently selected row. Or an invalid iterator, if no row is selected.
Note
This method won't work if the selection mode is Gtk::SelectionMode::MULTIPLE. Use get_selected_rows() for multiple selections.
TreeModel::const_iterator Gtk::TreeSelection::get_selected ( ) const

Get the currently selected row.

Returns
The currently selected row. Or an invalid iterator, if no row is selected.
Note
This method won't work if the selection mode is Gtk::SelectionMode::MULTIPLE. Use get_selected_rows() for multiple selections.
Since gtkmm 3.90:
TreeModel::iterator Gtk::TreeSelection::get_selected ( Glib::RefPtr< TreeModel >&  model)

Get the currently selected row.

Parameters
[out]modelThe current TreeModel.
Returns
The currently selected row. Or an invalid iterator, if no row is selected.
Note
This method won't work if the selection mode is Gtk::SelectionMode::MULTIPLE. Use get_selected_rows() for multiple selections.
TreeModel::const_iterator Gtk::TreeSelection::get_selected ( Glib::RefPtr< const TreeModel >&  model) const

Get the currently selected row.

Parameters
[out]modelThe current TreeModel.
Returns
The currently selected row. Or an invalid iterator, if no row is selected.
Note
This method won't work if the selection mode is Gtk::SelectionMode::MULTIPLE. Use get_selected_rows() for multiple selections.
Since gtkmm 3.90:
std::vector<TreeModel::Path> Gtk::TreeSelection::get_selected_rows ( ) const

Creates a vector of paths of all selected rows.

Additionally, if you are planning on modifying the model after calling this function, you may want to convert the returned list into a list of GtkTreeRowReferences.

Returns
A vector containing a Gtk::TreeModel::Path for each selected row.
std::vector<TreeModel::Path> Gtk::TreeSelection::get_selected_rows ( Glib::RefPtr< TreeModel >&  model)

Creates a list of paths of all selected rows.

Additionally, if you are planning on modifying the model after calling this function, you may want to convert the returned list into a list of GtkTreeRowReferences.

Parameters
[out]modelThe current TreeModel.
Returns
A vector containing a Gtk::TreeModel::Path for each selected row.
TreeView* Gtk::TreeSelection::get_tree_view ( )

Returns the tree view associated with selection.

Returns
A Gtk::TreeView.
const TreeView* Gtk::TreeSelection::get_tree_view ( ) const

Returns the tree view associated with selection.

Returns
A Gtk::TreeView.
static GType Gtk::TreeSelection::get_type ( )
static

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

GtkTreeSelection* Gtk::TreeSelection::gobj ( )
inline

Provides access to the underlying C GObject.

const GtkTreeSelection* Gtk::TreeSelection::gobj ( ) const
inline

Provides access to the underlying C GObject.

GtkTreeSelection* Gtk::TreeSelection::gobj_copy ( )

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

bool Gtk::TreeSelection::is_selected ( const TreeModel::Path path) const

Returns true if the row pointed to by path is currently selected.

If path does not point to a valid location, false is returned

Parameters
pathA Gtk::TreePath to check selection on.
Returns
true if path is selected.
bool Gtk::TreeSelection::is_selected ( const TreeModel::const_iterator iter) const

Returns true if the row at iter is currently selected.

Parameters
iterA valid Gtk::TreeIter.
Returns
true, if iter is selected.
TreeSelection& Gtk::TreeSelection::operator= ( TreeSelection&&  src)
noexcept
Glib::PropertyProxy< SelectionMode > Gtk::TreeSelection::property_mode ( )

Selection mode.

See Gtk::TreeSelection::set_mode() for more information on this property.

Default value: Gtk::SelectionMode::SINGLE

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.
Glib::PropertyProxy_ReadOnly< SelectionMode > Gtk::TreeSelection::property_mode ( ) const

Selection mode.

See Gtk::TreeSelection::set_mode() for more information on this property.

Default value: Gtk::SelectionMode::SINGLE

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.
void Gtk::TreeSelection::select ( const TreeModel::Path path)

Select the row at path.

Parameters
pathThe Gtk::TreePath to be selected.
void Gtk::TreeSelection::select ( const TreeModel::Path start_path,
const TreeModel::Path end_path 
)

Selects a range of nodes, determined by start_path and end_path inclusive.

selection must be set to Gtk::SelectionMode::MULTIPLE mode.

Parameters
start_pathThe initial node of the range.
end_pathThe final node of the range.
void Gtk::TreeSelection::select ( const TreeModel::const_iterator iter)

Selects the specified iterator.

Parameters
iterThe Gtk::TreeIter to be selected.
void Gtk::TreeSelection::select_all ( )

Selects all the nodes.

selection must be set to Gtk::SelectionMode::MULTIPLE mode.

void Gtk::TreeSelection::selected_foreach ( const SlotForeachPathAndIter slot) const

Calls a callback slot for each selected node.

Note that you cannot modify the tree or selection from within the callback function. As a result, get_selected_rows() might be more useful.

Parameters
slotThe function to call for each selected node.
void Gtk::TreeSelection::selected_foreach_iter ( const SlotForeachIter slot) const

Calls a callback slot for each selected node.

Note that you cannot modify the tree or selection from within the callback function. As a result, get_selected_rows() might be more useful.

Parameters
slotThe function to call for each selected node.
void Gtk::TreeSelection::selected_foreach_path ( const SlotForeachPath slot) const

Calls a callback slot for each selected node.

Note that you cannot modify the tree or selection from within the callback function. As a result, get_selected_rows() might be more useful.

Parameters
slotThe function to call for each selected node.
void Gtk::TreeSelection::set_mode ( SelectionMode  type)

Sets the selection mode of the selection.

If the previous type was Gtk::SelectionMode::MULTIPLE, then the anchor is kept selected, if it was previously selected.

Parameters
typeThe selection mode.
void Gtk::TreeSelection::set_select_function ( const SlotSelect slot)

Sets the selection callback slot.

If set, this function is called before any node is selected or unselected, giving some control over which nodes are selected.

The select function should return true if the state of the node may be toggled, and FALSE if the state of the node should be left unchanged.

Parameters
slotThe selection function.
Glib::SignalProxy<void()> Gtk::TreeSelection::signal_changed ( )
Slot Prototype:
void on_my_changed()

Flags: Run First

Emitted whenever the selection has (possibly) changed. Please note that this signal is mostly a hint. It may only be emitted once when a range of rows are selected, and it may occasionally be emitted when nothing has happened.

void Gtk::TreeSelection::unselect ( const TreeModel::Path path)

Unselects the row at path.

Parameters
pathThe Gtk::TreePath to be unselected.
void Gtk::TreeSelection::unselect ( const TreeModel::Path start_path,
const TreeModel::Path end_path 
)

Unselects a range of nodes, determined by start_path and end_path inclusive.

Parameters
start_pathThe initial node of the range.
end_pathThe initial node of the range.
void Gtk::TreeSelection::unselect ( const TreeModel::const_iterator iter)

Unselects the specified iterator.

Parameters
iterThe Gtk::TreeIter to be unselected.
void Gtk::TreeSelection::unselect_all ( )

Unselects all the nodes.

Friends And Related Function Documentation

Glib::RefPtr< Gtk::TreeSelection > wrap ( GtkTreeSelection *  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.