Toc Gallery Index Tree Gtk.Tree_Model_Filter

Hierarchy

Interfaces

Description

A Gtk_Tree_Model_Filter is a tree model which wraps another tree model, and can do the following things:

- Filter specific rows, based on data from a "visible column", a column storing booleans indicating whether the row should be filtered or not, or based on the return value of a "visible function", which gets a model, iter and user_data and returns a boolean indicating whether the row should be filtered or not.

- Modify the "appearance" of the model, using a modify function. This is extremely powerful and allows for just changing some values and also for creating a completely different model based on the given child model.

- Set a different root node, also known as a "virtual root". You can pass in a Gtk_Tree_Path indicating the root node for the filter at construction time.

Types

  • type Destroy_Notify is access procedure (Data : in out Data_Type);
    Destroys the memory allocated for Data
  • type Gtk_Tree_Model_Filter is access all Gtk_Tree_Model_Filter_Record'Class;
  • type Gtk_Tree_Model_Filter_Modify_Func is access procedure (Model : access Gtk_Tree_Model_Filter_Record'Class; Iter : Gtk.Tree_Model.Gtk_Tree_Iter; Value : out Glib.Values.GValue; Column : Gint; User_Data : Data_Type);
  • type Gtk_Tree_Model_Filter_Record is new Gtk.Tree_Model.Gtk_Tree_Model_Record with null record;
  • type Gtk_Tree_Model_Filter_Visible_Func is access function (Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; Iter : Gtk.Tree_Model.Gtk_Tree_Iter; Data : Data_Type) return Boolean;

Subprograms

  • procedure Gtk_New (Model : out Gtk_Tree_Model_Filter; Child_Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; Root : Gtk.Tree_Model.Gtk_Tree_Path := null);
    procedure Initialize (Model : access Gtk_Tree_Model_Filter_Record'Class; Child_Model : access Gtk.Tree_Model.Gtk_Tree_Model_Record'Class; Root : Gtk.Tree_Model.Gtk_Tree_Path := null);
    Creates a new tree model, with Child_Model as the child_model and Root as the virtual root (or the same root as Child_Model by default).
  • function Get_Type return Glib.GType;
    Returns the internal type used for a Gtk_Tree_Model_Filter
  • Child model

    The tree model filter wraps another model, and offers functions to convert from one to the other. Generally speaking, you can change data on either of the two models, and these changes will be reflected graphically automatically.
  • function Get_Model (Filter : access Gtk_Tree_Model_Filter_Record) return Gtk.Tree_Model.Gtk_Tree_Model;
    Returns a pointer to the child model of Filter.
  • procedure Convert_Child_Iter_To_Iter (Filter : access Gtk_Tree_Model_Filter_Record; Filter_Iter : out Gtk.Tree_Model.Gtk_Tree_Iter; Child_Iter : Gtk.Tree_Model.Gtk_Tree_Iter);
    Sets Filter_Iter to point to the row in Filter that corresponds to the row pointed at by Child_Iter.
  • function Convert_Child_Path_To_Path (Filter : access Gtk_Tree_Model_Filter_Record; Child_Path : Gtk.Tree_Model.Gtk_Tree_Path) return Gtk.Tree_Model.Gtk_Tree_Path;
    Converts Child_Path to a path relative to Filter. That is, Child_Path points to a path in the child model. The returned path will point to the same row in the filtered model. If Child_Path isn't a valid path on the child model, then null is returned. The returned value must be freed with Path_Free.
  • procedure Convert_Iter_To_Child_Iter (Filter : access Gtk_Tree_Model_Filter_Record; Child_Iter : out Gtk.Tree_Model.Gtk_Tree_Iter; Filter_Iter : Gtk.Tree_Model.Gtk_Tree_Iter);
    Sets Child_Iter to point to the row pointed to by Filter_Iter.
  • function Convert_Path_To_Child_Path (Filter : access Gtk_Tree_Model_Filter_Record; Filter_Path : Gtk.Tree_Model.Gtk_Tree_Path) return Gtk.Tree_Model.Gtk_Tree_Path;
    Converts Filter_Path to a path on the child model of Filter. That is, Filter_Path points to a location in Filter. The returned path will point to the same location in the model not being filtered. If Filter_Path does not point to a location in the child model, null is returned. The returned value must be freed with Path_Free.
  • Changing visibility

    One of the capabilities of a Gtk_Tree_Model_Filter is to hide some of the rows of its child model, so that they are not visible on the screen.
  • procedure Set_Visible_Column (Filter : access Gtk_Tree_Model_Filter_Record; Column : Gint);
    Sets Column of the child_model to be the column where Filter should look for visibility information. Columns should be a column of type GType_Boolean, where True means that a row is visible, and False if not.
  • procedure Set_Visible_Func (Filter : access Gtk_Tree_Model_Filter_Record; Func : Gtk_Tree_Model_Filter_Visible_Func);
    Sets the visible function used when filtering the Filter to be Func. The function should return True if the given row should be visible and False otherwise. If the condition calculated by the function changes over time (e.g. because it depends on some global parameters), you must call Refilter to keep the visibility information of the model uptodate.
  • procedure Set_Visible_Func (Filter : access Gtk_Tree_Model_Filter_Record'Class; Func : Gtk_Tree_Model_Filter_Visible_Func; Data : Data_Type; Destroy : Destroy_Notify := null);
    Same as above, but the application can pass addition data to the function
  • procedure Refilter (Filter : access Gtk_Tree_Model_Filter_Record);
    Emits row_changed for each row in the child model, which causes the filter to re-evaluate whether a row is visible or not.
  • Modifying displayed values

    The other capability of a Gtk_Tree_Model_Filter is to modify on the fly the displayed value (ie we do not display directly what is in the child model, but change the value in memory, not in the model, on the fly)
  • procedure Set_Modify_Func (Filter : access Gtk_Tree_Model_Filter_Record; Types : Glib.GType_Array; Func : Gtk_Tree_Model_Filter_Modify_Func);
    Types can be used to override the column types that will be made visible to the parent model/view. Func is used to specify the modify function. The modify function will get called for *each* data access, the goal of the modify function is to return the data which should be displayed at the location specified using the parameters of the modify function.
  • procedure Set_Modify_Func (Filter : access Gtk_Tree_Model_Filter_Record'Class; Types : Glib.GType_Array; Func : Gtk_Tree_Model_Filter_Modify_Func; Data : Data_Type; Destroy : Destroy_Notify := null);
    Same as above, but the application can pass extra data to the function.
  • Misc

  • procedure Clear_Cache (Filter : access Gtk_Tree_Model_Filter_Record);
    This function should almost never be called. It clears the Filter of any cached iterators that haven't been reffed with Gtk.Tree_Model.Ref_Node. This might be useful if the child model being filtered 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 unrefed iters will be invalid.
  • Interfaces

    This class implements several interfaces. See Glib.Types
  • function "+" (Model : access Gtk_Tree_Model_Filter_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_Filter renames Implements_Drag_Source.To_Object;
    Converts to and from the Gtk_Tree_Drag_Source interface

Testgtk source code

This code is part of testgtk, a demo application packaged with GtkAda. Testgtk demonstrates the various widgets of GtkAda
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for the Gimp Toolkit -- -- -- -- Copyright (C) 2006 AdaCore -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public -- -- License along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- -- -- -- -- -- -- -- ----------------------------------------------------------------------- with Glib; use Glib; with Glib.Object; use Glib.Object; with Glib.Values; use Glib.Values; with Gtk; use Gtk; with Gtk.Enums; use Gtk.Enums; with Gtk.Scrolled_Window; use Gtk.Scrolled_Window; with Gtk.Cell_Renderer_Text; use Gtk.Cell_Renderer_Text; with Gtk.List_Store; use Gtk.List_Store; with Gtk.Tree_View; use Gtk.Tree_View; with Gtk.Tree_Model; use Gtk.Tree_Model; with Gtk.Tree_Model_Filter; use Gtk.Tree_Model_Filter; with Gtk.Tree_View_Column; use Gtk.Tree_View_Column; with Gtk.Frame; use Gtk.Frame; package body Create_Tree_Filter is Column_0 : constant := 0; function Custom_Filter (Model : access Gtk_Tree_Model_Record'Class; Iter : Gtk_Tree_Iter) return Boolean; -- Decide whether a row should be made visible or not procedure Custom_Appearance (Model : access Gtk_Tree_Model_Filter_Record'Class; Iter : Gtk_Tree_Iter; Value : out GValue; Column : Gint); -- Change the appearance of the view dynamically ---------- -- Help -- ---------- function Help return String is begin return "This example demonstrates a special tree modeL: it wraps another" & " model, and can be used to filter out lines, or even modify its" & " appearance on the fly." & ASCII.LF & "In this example, we have creates a model that contains the sequence" & " 1, 2, ... 9. Another model is applied on top of it, and filters" & " all odd numbers rows. It also changes the appearance to display" & " some extra text." & ASCII.LF & "The underlying model itself is never modified, and by changing a" & " few properties we can decide to show the whole underlying model" & " itself." & ASCII.LF & "Modifying the appearance on the fly is not efficient. It is" & " generally better to use the functions from @bGtk_Cell_Layout@B to" & " create ""virtual"" columns in the model. See the Cell View demo."; end Help; ------------------- -- Custom_Filter -- ------------------- function Custom_Filter (Model : access Gtk_Tree_Model_Record'Class; Iter : Gtk_Tree_Iter) return Boolean is Value : constant Gint := Get_Int (Model, Iter, Column_0); begin return Value mod 2 /=1 ; end Custom_Filter; ----------------------- -- Custom_Appearance -- ----------------------- procedure Custom_Appearance (Model : access Gtk_Tree_Model_Filter_Record'Class; Iter : Gtk_Tree_Iter; Value : out GValue; Column : Gint) is Val : Gint; Child_Iter : Gtk_Tree_Iter; begin Convert_Iter_To_Child_Iter (Model, Child_Iter, Iter); Val := Get_Int (Get_Model (Model), Child_Iter, Column); Set_String (Value, "This is line" & Gint'Image (Val)); end Custom_Appearance; --------- -- Run -- --------- procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is Model : Gtk_List_Store; Filter : Gtk_Tree_Model_Filter; Tree : Gtk_Tree_View; Scrolled : Gtk_Scrolled_Window; Col : Gtk_Tree_View_Column; Num : Gint; Text : Gtk_Cell_Renderer_Text; Iter : Gtk_Tree_Iter; pragma Unreferenced (Num); begin Set_Label (Frame, "Tree Model Filter"); Gtk_New (Scrolled); Add (Frame, Scrolled); Set_Policy (Scrolled, Policy_Automatic, Policy_Automatic); -- Create the model that contains the actual data. This model will -- never be modified Gtk_New (Model, (Column_0 => GType_Int)); for N in 1 .. 10 loop Append (Model, Iter); Set (Model, Iter, Column_0, Gint (N)); end loop; -- Now creates a filter around this model. We filter through a custom -- function, but that could be a simple row in the model as well. The -- function is slightly more flexible, though. Gtk_New (Filter, Model); Set_Visible_Func (Filter, Custom_Filter'Access); Set_Modify_Func (Filter, (0 => GType_String), Custom_Appearance'Access); -- And now a view that displays the filter. A single column is displayed Gtk_New (Tree, Filter); Add (Scrolled, Tree); Set_Headers_Visible (Tree, False); Gtk_New (Text); Gtk_New (Col); Num := Append_Column (Tree, Col); Pack_Start (Col, Text, True); Add_Attribute (Col, Text, "text", Column_0); Show_All (Frame); end Run; end Create_Tree_Filter;

Alphabetical Index