Gnome::Gtk4::TreeModelSort
Description
A GtkTreeModel which makes an underlying tree model sortable
The Gnome::Gtk4::TreeModelSort is a model which implements the Gnome::Gtk4::R-TreeSortable interface. It does not hold any data itself, but rather is created with a child model and proxies its data. It has identical column types to this child model, and the changes in the child are propagated. The primary purpose of this model is to provide a way to sort a different model without modifying it. Note that the sort function used by Gnome::Gtk4::TreeModelSort is not guaranteed to be stable.
The use of this is best demonstrated through an example. In the following sample code we create two Gnome::Gtk4::TreeView widgets each with a view of the same data. As the model is wrapped here by a Gnome::Gtk4::TreeModelSort, the two Gnome::Gtk4::TreeViews can each sort their view of the data without affecting the other. By contrast, if we simply put the same model in each widget, then sorting the first would sort the second.
Using a Gnome::Gtk4::TreeModelSort
To demonstrate how to access the underlying child model from the sort model, the next example will be a callback for the Gnome::Gtk4::TreeSelection Gnome::Gtk4::TreeSelection::changed` signal. In this callback, we get a string from COLUMN_1 of the model. We then modify the string, find the same selected row on the child model, and change the row there.
Accessing the child model of in a selection changed callback
Class initialization
Note: The native version of this class is deprecated in gtk4-lib() since version 4.10
new
:native-object
Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object :$native-object! )
new-with-model
Creates a new Gnome::Gtk4::TreeModelSort, with $child-model
as the child model.
method new-with-model ( N-Object() $child-model --> Gnome::Gtk4::TreeModelSort \)
$child-model; A Gnome::Gtk4::R-TreeModel.
Methods
clear-cache
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
This function should almost never be called. It clears the $tree-model-sort
of any cached iterators that haven’t been reffed with gtk_tree_model_ref_node(). This might be useful if the child model being sorted is static (and doesn’t change often) and there has been a lot of unreffed access to nodes. As a side effect of this function, all unreffed iters will be invalid.
method clear-cache ( )
convert-child-iter-to-iter
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Sets $sort-iter
to point to the row in $tree-model-sort
that corresponds to the row pointed at by $child-iter
. If $sort-iter
was not set, False
is returned. Note: a boolean is only returned since 2.14.
method convert-child-iter-to-iter ( N-Object $sort-iter, N-Object $child-iter --> Bool )
$sort-iter; An uninitialized Gnome::Gtk4::N-TreeIter
$child-iter; A valid Gnome::Gtk4::N-TreeIter pointing to a row on the child model
Return value; True
, if $sort-iter
was set, i.e. if $sort-iter
is a valid iterator pointer to a visible row in the child model..
convert-child-path-to-path
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Converts $child-path
to a path relative to $tree-model-sort
. That is, $child-path
points to a path in the child model. The returned path will point to the same row in the sorted model. If $child-path
isn’t a valid path on the child model, then undefined is returned.
method convert-child-path-to-path ( N-Object $child-path --> N-Object )
$child-path; A Gnome::Gtk4::N-TreePath to convert
Return value; A newly allocated Gnome::Gtk4::N-TreePath.
convert-iter-to-child-iter
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Sets $child-iter
to point to the row pointed to by $sorted-iter
.
method convert-iter-to-child-iter ( N-Object $child-iter, N-Object $sorted-iter )
$child-iter; An uninitialized Gnome::Gtk4::N-TreeIter
$sorted-iter; A valid Gnome::Gtk4::N-TreeIter pointing to a row on
$tree-model-sort
.
convert-path-to-child-path
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
Converts $sorted-path
to a path on the child model of $tree-model-sort
. That is, $sorted-path
points to a location in $tree-model-sort
. The returned path will point to the same location in the model not being sorted. If $sorted-path
does not point to a location in the child model, undefined is returned.
method convert-path-to-child-path ( N-Object $sorted-path --> N-Object )
$sorted-path; A Gnome::Gtk4::N-TreePath to convert
Return value; A newly allocated Gnome::Gtk4::N-TreePath.
get-model
Returns the model the Gnome::Gtk4::TreeModelSort is sorting.
method get-model (--> N-Object )
Return value; the "child model" being sorted.
iter-is-valid
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
> This function is slow. Only use it for debugging and/or testing > purposes.
Checks if the given iter is a valid iter for this Gnome::Gtk4::TreeModelSort.
method iter-is-valid ( N-Object $iter --> Bool )
$iter; A Gnome::Gtk4::N-TreeIter
Return value; True
if the iter is valid, False
if the iter is invalid..
reset-default-sort-func
Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10
This resets the default sort function to be in the “unsorted” state. That is, it is in the same order as the child model. It will re-sort the model to be in the same order as the child model only if the Gnome::Gtk4::TreeModelSort is in “unsorted” state.
method reset-default-sort-func ( )