package Implements_Tree_Sortable is new Glib.Types.Implements (Gtk.Tree_Sortable.Gtk_Tree_Sortable, Gtk_Tree_Model_Sort_Record, Gtk_Tree_Model_Sort);
package Implements_Drag_Source is new Glib.Types.Implements (Gtk.Tree_Dnd.Gtk_Tree_Drag_Source, Gtk_Tree_Model_Sort_Record, Gtk_Tree_Model_Sort);
type Gtk_Tree_Model_Sort_Record is new Gtk.Tree_Model.Gtk_Tree_Model_Record with null record;
type Gtk_Tree_Model_Sort is access all Gtk_Tree_Model_Sort_Record'Class;
Model_Property : constant Glib.Properties.Property_Object;
procedure Gtk_New_With_Model
( | Sort_Model | : out Gtk_Tree_Model_Sort; |
Child_Model | : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class); |
procedure Initialize_With_Model
( | Sort_Model | : access Gtk_Tree_Model_Sort_Record'Class; |
Child_Model | : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class); |
function Get_Type return Glib.GType;
function Get_Model
( | Tree_Model | : access Gtk_Tree_Model_Sort_Record) return Gtk.Tree_Model.Gtk_Tree_Model; |
function Convert_Child_Path_To_Path
( | Tree_Model_Sort | : access Gtk_Tree_Model_Sort_Record; |
Child_Path | : Gtk.Tree_Model.Gtk_Tree_Path) return Gtk.Tree_Model.Gtk_Tree_Path; |
procedure Convert_Child_Iter_To_Iter
( | Tree_Model_Sort | : access Gtk_Tree_Model_Sort_Record; |
Sort_Iter | : out Gtk.Tree_Model.Gtk_Tree_Iter; | |
Child_Iter | : Gtk.Tree_Model.Gtk_Tree_Iter); |
function Convert_Path_To_Child_Path
( | Tree_Model_Sort | : access Gtk_Tree_Model_Sort_Record; |
Sorted_Path | : Gtk.Tree_Model.Gtk_Tree_Path) return Gtk.Tree_Model.Gtk_Tree_Path; |
procedure Convert_Iter_To_Child_Iter
( | Tree_Model_Sort | : access Gtk_Tree_Model_Sort_Record; |
Child_Iter | : out Gtk.Tree_Model.Gtk_Tree_Iter; | |
Sorted_Iter | : Gtk.Tree_Model.Gtk_Tree_Iter); |
procedure Reset_Default_Sort_Func
( | Tree_Model_Sort | : access Gtk_Tree_Model_Sort_Record); |
procedure Clear_Cache
( | Tree_Model_Sort | : access Gtk_Tree_Model_Sort_Record); |
function Iter_Is_Valid
( | Tree_Model_Sort | : access Gtk_Tree_Model_Sort_Record; |
Iter | : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean; |
function "+"
( | Model | : access Gtk_Tree_Model_Sort_Record'Class) return Gtk.Tree_Sortable.Gtk_Tree_Sortable renames Implements_Tree_Sortable.To_Interface; |
function "-"
( | Sortable | : Gtk.Tree_Sortable.Gtk_Tree_Sortable) return Gtk_Tree_Model_Sort renames Implements_Tree_Sortable.To_Object; |
function "+"
( | Model | : access Gtk_Tree_Model_Sort_Record'Class) return Gtk.Tree_Dnd.Gtk_Tree_Drag_Source renames Implements_Drag_Source.To_Interface; |
function "-"
( | Drag_Source | : Gtk.Tree_Dnd.Gtk_Tree_Drag_Source) return Gtk_Tree_Model_Sort renames Implements_Drag_Source.To_Object; |
The Gtk_Tree_Model_Sort is a model which implements the Gtk_Tree_Sortable interface. It does not hold any data itself, but rather is created with 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 Gtk_Tree_Model_Sort is not guaranteed to be stable.
The use of this is best demonstrated through an example. In the following sample code we create two Gtk_Tree_View widgets each with a view of the same data. As the model is wrapped here by a Gtk_Tree_Model_Sort, the two Gtk_Tree_Views 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. declare Tree_View1, Tree_View2 : Gtk_Tree_View; Sort_Model1, Sort_Model2 : Gtk_Tree_Model_Sort; Child_Model : Gtk_Tree_Model; begin Child_Model := Get_My_Model; -- Your own implementation -- Create the first tree Gtk_New_With_Model (Sort_Model1, Child_Model); Gtk_New (Tree_View1, Sort_Model1); Set_Sort_Column_Id (Sort_Model1, COLUMN1, Sort_Ascending); -- Create the second tree Gtk_New_With_Model (Sort_Model2, Child_Model); Gtk_New (Tree_View2, Sort_Model2); Set_Sort_Column_Id (Sort_Model2, COLUMN1, Sort_Descending); end; To demonstrate how to access the underlying child model from the sort model, the next example will be a callback for the Gtk_Tree_Selection "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. procedure Selection_Changed (Selection : access Gtk_Tree_Selection_Record'Class) is Sort_Model, Child_Model : Gtk_Tree_Model; Sort_Iter, Child_Iter : Gtk_Tree_Iter; begin -- Get the currently selected row and the model Get_Selected (Selection, Sort_Model, Sort_Iter); if Sort_Iter = Null_Iter then return; end if; -- Lookup the current value on the selected row declare Some_Data : constant String := Get_String (Sort_Model, Sort_Iter, COLUMN1); begin -- Get an iterator on the child model instead of the sort model Convert_Iter_To_Child_Iter (Sort_Model, Child_Iter, Sort_Iter); -- Get the child model and change the value in the row -- In this example, the model is a Gtk_List_Store, but it could be -- anything Child_Model := Get_Model (Gtk_Sort_Model (Sort_Model)); Set (Ctk_List_Store (Child_Model), Child_Iter, COLUMN1, "data"); end; end Selection_Changed;
Binding from C File version 2.8.17