gtkmm 4.10.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::SelectionModel Class Reference

An extension of the list model interface that handles selections. More...

`#include <gtkmm/selectionmodel.h>`

Inheritance diagram for Gtk::SelectionModel:
[legend]

## Public Member Functions
| SelectionModel (SelectionModel && src) noexcept
SelectionModel & | operator= (SelectionModel && src) noexcept
| ~SelectionModel () noexcept override
GtkSelectionModel * | gobj ()
| Provides access to the underlying C GObject. More...
const GtkSelectionModel * | gobj () const
| Provides access to the underlying C GObject. More...
bool | is_selected (guint position) const
| Checks if the given item is selected. More...
Glib::RefPtr< const Bitset > | get_selection () const
| Gets the set containing all currently selected items in the model. More...
Glib::RefPtr< const Bitset > | get_selection (guint position, guint n_items) const
| Gets the set of selected items in a range. More...
bool | select_item (guint position, bool unselect_rest)
| Requests to select an item in the model. More...
bool | unselect_item (guint position)
| Requests to unselect an item in the model. More...
bool | select_range (guint position, guint n_items, bool unselect_rest)
| Requests to select a range of items in the model. More...
bool | unselect_range (guint position, guint n_items)
| Requests to unselect a range of items in the model. More...
bool | select_all ()
| Requests to select all items in the model. More...
bool | unselect_all ()
| Requests to unselect all items in the model. More...
bool | set_selection (const Glib::RefPtr< const Bitset > & selected, const Glib::RefPtr< const Bitset > & mask)
| Make selection changes. More...
Glib::SignalProxy< void(guint, guint)> | signal_selection_changed ()
Public Member Functions inherited from Glib::Interface
| Interface ()
| Interface (Interface &&src) noexcept
Interface & | operator= (Interface &&src) noexcept
| Interface (const Glib::Interface_Class &interface_class)
| Interface (GObject *castitem)
| ~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)
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 ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (notifiable *data) const

## 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. More...

## Protected Member Functions
| SelectionModel ()
| You should derive from this class to use it. More...
void | selection_changed (guint position, guint n_items)
| Helper function for implementations of `Gtk::SelectionModel`. More...
virtual bool | is_selected_vfunc (guint position) const
virtual Glib::RefPtr< const Bitset > | get_selection_vfunc (guint position, guint n_items)
virtual bool | select_item_vfunc (guint position, bool unselect_rest)
virtual bool | unselect_item_vfunc (guint position)
virtual bool | select_range_vfunc (guint position, guint n_items, bool unselect_rest)
virtual bool | unselect_range_vfunc (guint position, guint n_items)
virtual bool | select_all_vfunc ()
virtual bool | unselect_all_vfunc ()
virtual bool | set_selection_vfunc (const Glib::RefPtr< const Bitset > & selected, const Glib::RefPtr< const Bitset > & mask)
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
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gtk::SelectionModel > | wrap (GtkSelectionModel * object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Additional Inherited Members
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

## Detailed Description

An extension of the list model interface that handles selections.

Gtk::SelectionModel is an interface that extends the Gio::ListModel interface by adding support for selections. This support is then used by widgets using list models to add the ability to select and unselect various items.

GTK provides default implementations of the common selection modes such as Gtk::SingleSelection, so you will only need to implement this interface if you want detailed control about how selections should be handled.

A Gtk::SelectionModel supports a single boolean per row indicating if a row is selected or not. This can be queried via is_selected(). When the selected state of one or more rows changes, the model will emit signal_selection_changed() by calling the selection_changed() method. The positions given in that signal may have their selection state changed, though that is not a requirement.
If new items added to the model via Gio::ListModel::signal_items_changed() are selected or not is up to the implementation.

Additionally, the interface can expose functionality to select and unselect items. If these functions are implemented, GTK's list widgets will allow users to select and unselect items. However, Gtk::SelectionModels are free to only implement them partially or not at all. In that case the widgets will not support the unimplemented operations.

When selecting or unselecting is supported by a model, the return values of the selection functions do NOT indicate if selection or unselection happened. They are only meant to indicate complete failure, like when this mode of selecting is not supported by the model. Selections may happen asynchronously, so the only reliable way to find out when an item was selected is to listen to the signals that indicate selection.

See also
  Gio::ListModel, Gtk::SingleSelection

Since gtkmm 3.96:

## Constructor & Destructor Documentation

## ◆ SelectionModel() [1/2]

Gtk::SelectionModel::SelectionModel | ( |  | ) |
| protected

You should derive from this class to use it.

## ◆ SelectionModel() [2/2]

Gtk::SelectionModel::SelectionModel | ( | SelectionModel && | src | ) |
| noexcept

## ◆ ~SelectionModel()

Gtk::SelectionModel::~SelectionModel | ( |  | ) |
| override noexcept

## Member Function Documentation

## ◆ add_interface()

static void Gtk::SelectionModel::add_interface | ( | GType | gtype_implementer | ) |
| static

## ◆ get_selection() [1/2]

Glib::RefPtr<const Bitset> Gtk::SelectionModel::get_selection | ( |  | ) | const

Gets the set containing all currently selected items in the model.

This function may be slow, so if you are only interested in single item, consider using is_selected() or if you are only interested in a few, consider get_selection_in_range().

Returns
  A `Gtk::Bitset` containing all the values currently selected in model. If no items are selected, the bitset is empty. The bitset must not be modified.

## ◆ get_selection() [2/2]

Glib::RefPtr<const Bitset> Gtk::SelectionModel::get_selection | ( | guint | position,
|  | guint | n_items
| ) |  | const

Gets the set of selected items in a range.

This function is an optimization for get_selection() when you are only interested in part of the model's selected state. A common use case is in response to the signal_selection_changed() signal.

Parameters

  position | Start of the queried range.
  n_items | Number of items in the queried range.

Returns
  A `Gtk::Bitset` that matches the selection state for the given range with all other values being undefined. The bitset must not be modified.

## ◆ get_selection_vfunc()

virtual Glib::RefPtr<const Bitset> Gtk::SelectionModel::get_selection_vfunc | ( | guint | position,
|  | guint | n_items
| ) |  |
| protected virtual

## ◆ get_type()

static GType Gtk::SelectionModel::get_type | ( |  | ) |
| static

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

## ◆ gobj() [1/2]

GtkSelectionModel* Gtk::SelectionModel::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GtkSelectionModel* Gtk::SelectionModel::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ is_selected()

bool Gtk::SelectionModel::is_selected | ( | guint | position | ) | const

Checks if the given item is selected.

Parameters

  position | The position of the item to query.

Returns
  `true` if the item is selected.

## ◆ is_selected_vfunc()

virtual bool Gtk::SelectionModel::is_selected_vfunc | ( | guint | position | ) | const
| protected virtual

## ◆ operator=()

SelectionModel& Gtk::SelectionModel::operator= | ( | SelectionModel && | src | ) |
| noexcept

## ◆ select_all()

bool Gtk::SelectionModel::select_all | ( |  | ) |

Requests to select all items in the model.

Returns
  `true` if this action was supported and no fallback should be tried. This does not mean that all items are now selected.

## ◆ select_all_vfunc()

virtual bool Gtk::SelectionModel::select_all_vfunc | ( |  | ) |
| protected virtual

## ◆ select_item()

bool Gtk::SelectionModel::select_item | ( | guint | position,
|  | bool | unselect_rest
| ) |  |

Requests to select an item in the model.

Parameters

  position | The position of the item to select.
  unselect_rest | Whether previously selected items should be unselected.

Returns
  `true` if this action was supported and no fallback should be tried. This does not mean the item was selected.

## ◆ select_item_vfunc()

virtual bool Gtk::SelectionModel::select_item_vfunc | ( | guint | position,
|  | bool | unselect_rest
| ) |  |
| protected virtual

## ◆ select_range()

bool Gtk::SelectionModel::select_range | ( | guint | position,
|  | guint | n_items,
|  | bool | unselect_rest
| ) |  |

Requests to select a range of items in the model.

Parameters

  position | The first item to select.
  n_items | The number of items to select.
  unselect_rest | Whether previously selected items should be unselected.

Returns
  `true` if this action was supported and no fallback should be tried. This does not mean the range was selected.

## ◆ select_range_vfunc()

virtual bool Gtk::SelectionModel::select_range_vfunc | ( | guint | position,
|  | guint | n_items,
|  | bool | unselect_rest
| ) |  |
| protected virtual

## ◆ selection_changed()

void Gtk::SelectionModel::selection_changed | ( | guint | position,
|  | guint | n_items
| ) |  |
| protected

Helper function for implementations of `Gtk::SelectionModel`.

Call this when the selection changes to emit the signal_selection_changed() signal.

Parameters

  position | The first changed item.
  n_items | The number of changed items.

## ◆ set_selection()

bool Gtk::SelectionModel::set_selection | ( | const Glib::RefPtr< const Bitset > & | selected,
|  | const Glib::RefPtr< const Bitset > & | mask
| ) |  |

Make selection changes.

This is the most advanced selection updating method that allows the most fine-grained control over selection changes. If you can, you should try the simpler versions, as implementations are more likely to implement support for those.

Requests that the selection state of all positions set in mask be updated to the respective value in the selected bitmask.

In pseudocode, it would look something like this:

[C example ellipted]

mask and selected must not be modified. They may refer to the same bitset, which would mean that every item in the set should be selected.

Parameters

  selected | Bitmask specifying if items should be selected or unselected.
  mask | Bitmask specifying which items should be updated.

Returns
  `true` if this action was supported and no fallback should be tried. This does not mean that all items were updated according to the inputs.

## ◆ set_selection_vfunc()

virtual bool Gtk::SelectionModel::set_selection_vfunc | ( | const Glib::RefPtr< const Bitset > & | selected,
|  | const Glib::RefPtr< const Bitset > & | mask
| ) |  |
| protected virtual

## ◆ signal_selection_changed()

Glib::SignalProxy<void(guint, guint)> Gtk::SelectionModel::signal_selection_changed | ( |  | ) |

Slot Prototype:
  `void on_my_selection_changed(guint position, guint n_items)`

Flags: Run Last

Emitted when the selection state of some of the items in model changes.

Note that this signal does not specify the new selection state of the items, they need to be queried manually. It is also not necessary for a model to change the selection state of any of the items in the selection model, though it would be rather useless to emit such a signal.

Parameters

  position | The first item that may have changed.
  n_items | Number of items with changes.

## ◆ unselect_all()

bool Gtk::SelectionModel::unselect_all | ( |  | ) |

Requests to unselect all items in the model.

Returns
  `true` if this action was supported and no fallback should be tried. This does not mean that all items are now unselected.

## ◆ unselect_all_vfunc()

virtual bool Gtk::SelectionModel::unselect_all_vfunc | ( |  | ) |
| protected virtual

## ◆ unselect_item()

bool Gtk::SelectionModel::unselect_item | ( | guint | position | ) |

Requests to unselect an item in the model.

Parameters

  position | The position of the item to unselect.

Returns
  `true` if this action was supported and no fallback should be tried. This does not mean the item was unselected.

## ◆ unselect_item_vfunc()

virtual bool Gtk::SelectionModel::unselect_item_vfunc | ( | guint | position | ) |
| protected virtual

## ◆ unselect_range()

bool Gtk::SelectionModel::unselect_range | ( | guint | position,
|  | guint | n_items
| ) |  |

Requests to unselect a range of items in the model.

Parameters

  position | The first item to unselect.
  n_items | The number of items to unselect.

Returns
  `true` if this action was supported and no fallback should be tried. This does not mean the range was unselected.

## ◆ unselect_range_vfunc()

virtual bool Gtk::SelectionModel::unselect_range_vfunc | ( | guint | position,
|  | guint | n_items
| ) |  |
| protected virtual

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gtk::SelectionModel > wrap | ( | GtkSelectionModel * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

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

Parameters

  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.

Returns
  A C++ instance that wraps this C instance.