SelectionModel

interface SelectionModel

GtkSelectionModel is an interface that add support for selection to list models.

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 most common selection modes such as class@Gtk.SingleSelection, so you will only need to implement this interface if you want detailed control about how selections should be handled.

A GtkSelectionModel supports a single boolean per item indicating if an item is selected or not. This can be queried via method@Gtk.SelectionModel.is_selected. When the selected state of one or more items changes, the model will emit the signal@Gtk.SelectionModel::selection-changed signal by calling the method@Gtk.SelectionModel.selection_changed function. 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 the signal@Gio.ListModel::items-changed signal are selected or not is up to the implementation.

Note that items added via signal@Gio.ListModel::items-changed may already be selected and no signal@Gtk.SelectionModel::selection-changed will be emitted for them. So to track which items are selected, it is necessary to listen to both signals.

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, GtkSelectionModels 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.

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open val gioListModelPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
abstract val gtkSelectionModelPointer: <Error class: unknown class><<Error class: unknown class>>

Functions

Link copied to clipboard
open fun connectSelectionChanged(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (<Error class: unknown class>, <Error class: unknown class>) -> Unit): <Error class: unknown class>

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

Link copied to clipboard
open fun getSelection(): Bitset

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

Link copied to clipboard
open fun getSelectionInRange(position: <Error class: unknown class>, nItems: <Error class: unknown class>): Bitset

Gets the set of selected items in a range.

Link copied to clipboard
open fun isSelected(position: <Error class: unknown class>): Boolean

Checks if the given item is selected.

Link copied to clipboard
open fun selectAll(): Boolean

Requests to select all items in the model.

Link copied to clipboard
open fun selectionChanged(position: <Error class: unknown class>, nItems: <Error class: unknown class>)

Helper function for implementations of GtkSelectionModel.

Link copied to clipboard
open fun selectItem(position: <Error class: unknown class>, unselectRest: Boolean): Boolean

Requests to select an item in the model.

Link copied to clipboard
open fun selectRange(position: <Error class: unknown class>, nItems: <Error class: unknown class>, unselectRest: Boolean): Boolean

Requests to select a range of items in the model.

Link copied to clipboard
open fun setSelection(selected: Bitset, mask: Bitset): Boolean

Make selection changes.

Link copied to clipboard
open fun unselectAll(): Boolean

Requests to unselect all items in the model.

Link copied to clipboard
open fun unselectItem(position: <Error class: unknown class>): Boolean

Requests to unselect an item in the model.

Link copied to clipboard
open fun unselectRange(position: <Error class: unknown class>, nItems: <Error class: unknown class>): Boolean

Requests to unselect a range of items in the model.