class Gtk::TreeStore

Overview

A tree-like data structure that can be used with the Gtk::TreeView

The Gtk::TreeStore object is a list model for use with a Gtk::TreeView widget. It implements the Gtk::TreeModel interface, and consequently, can use all of the methods available there. It also implements the Gtk::TreeSortable interface so it can be sorted by the view. Finally, it also implements the tree [drag and drop][gtk3-Gtk::TreeView-drag-and-drop] interfaces.

Gtk::TreeStore as Gtk::Buildable

The Gtk::TreeStore implementation of the Gtk::Buildable interface allows to specify the model columns with a element that may contain multiple elements, each specifying one model column. The “type” attribute specifies the data type for the column.

An example of a UI Definition fragment for a tree store: |[ ]|

Included Modules

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/tree_store.cr
lib/gtk4/src/bindings/gtk/tree_store.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Gtk::TreeSortable

default_sort_func=(sort_func : Gtk::TreeIterCompareFunc) : Nil default_sort_func=, has_default_sort_func : Bool has_default_sort_func, set_sort_column_id(sort_column_id : Int32, order : Gtk::SortType) : Nil set_sort_column_id, set_sort_func(sort_column_id : Int32, sort_func : Gtk::TreeIterCompareFunc) : Nil set_sort_func, sort_column_changed : Nil sort_column_changed, sort_column_changed_signal sort_column_changed_signal, sort_column_id(sort_column_id : Int32, order : Gtk::SortType) : Bool sort_column_id, to_unsafe to_unsafe

Class methods inherited from module Gtk::TreeSortable

g_type : UInt64 g_type

Instance methods inherited from module Gtk::TreeModel

column_type(index_ : Int32) : UInt64 column_type, filter_new(root : Gtk::TreePath?) : Gtk::TreeModel filter_new, flags : Gtk::TreeModelFlags flags, foreach(func : Gtk::TreeModelForeachFunc, user_data : Pointer(Void)?) : Nil foreach, iter(path : Gtk::TreePath) : Gtk::TreeIter iter, iter_children(parent : Gtk::TreeIter?) : Gtk::TreeIter iter_children, iter_first : Gtk::TreeIter iter_first, iter_from_string(path_string : String) : Gtk::TreeIter iter_from_string, iter_has_child(iter : Gtk::TreeIter) : Bool iter_has_child, iter_n_children(iter : Gtk::TreeIter?) : Int32 iter_n_children, iter_next(iter : Gtk::TreeIter) : Bool iter_next, iter_nth_child(parent : Gtk::TreeIter?, n : Int32) : Gtk::TreeIter iter_nth_child, iter_parent(child : Gtk::TreeIter) : Gtk::TreeIter iter_parent, iter_previous(iter : Gtk::TreeIter) : Bool iter_previous, n_columns : Int32 n_columns, path(iter : Gtk::TreeIter) : Gtk::TreePath path, ref_node(iter : Gtk::TreeIter) : Nil ref_node, row_changed(path : Gtk::TreePath, iter : Gtk::TreeIter) : Nil row_changed, row_changed_signal row_changed_signal, row_deleted(path : Gtk::TreePath) : Nil row_deleted, row_deleted_signal row_deleted_signal, row_has_child_toggled(path : Gtk::TreePath, iter : Gtk::TreeIter) : Nil row_has_child_toggled, row_has_child_toggled_signal row_has_child_toggled_signal, row_inserted(path : Gtk::TreePath, iter : Gtk::TreeIter) : Nil row_inserted, row_inserted_signal row_inserted_signal, rows_reordered(path : Gtk::TreePath, iter : Gtk::TreeIter?, new_order : Enumerable(Int32)) : Nil rows_reordered, string_from_iter(iter : Gtk::TreeIter) : String? string_from_iter, to_unsafe to_unsafe, unref_node(iter : Gtk::TreeIter) : Nil unref_node, value(iter : Gtk::TreeIter, column : Int32) : GObject::Value value

Class methods inherited from module Gtk::TreeModel

g_type : UInt64 g_type

Instance methods inherited from module Gtk::TreeDragSource

drag_data_delete(path : Gtk::TreePath) : Bool drag_data_delete, drag_data_get(path : Gtk::TreePath) : Gdk::ContentProvider? drag_data_get, row_draggable(path : Gtk::TreePath) : Bool row_draggable, to_unsafe to_unsafe

Class methods inherited from module Gtk::TreeDragSource

g_type : UInt64 g_type

Instance methods inherited from module Gtk::TreeDragDest

drag_data_received(dest : Gtk::TreePath, value : _) : Bool drag_data_received, row_drop_possible(dest_path : Gtk::TreePath, value : _) : Bool row_drop_possible, to_unsafe to_unsafe

Class methods inherited from module Gtk::TreeDragDest

g_type : UInt64 g_type

Instance methods inherited from module Gtk::Buildable

buildable_id : String? buildable_id, to_unsafe to_unsafe

Class methods inherited from module Gtk::Buildable

g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new(types : Enumerable(UInt64)) : self #

Creates a new tree store as with @n_columns columns each of the types passed in. Note that only types derived from standard GObject fundamental types are supported.

As an example,

gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING, GDK_TYPE_TEXTURE);

will create a new Gtk::TreeStore with three columns, of type int, gchararray, and Gdk::Texture respectively.


def self.new #

Initialize a new TreeStore.


def self.new(*types : UInt64) #

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def append(parent : Gtk::TreeIter?) : Gtk::TreeIter #

Appends a new row to @tree_store. If @parent is non-nil, then it will append the new row after the last child of @parent, otherwise it will append a row to the top level. @iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or gtk_tree_store_set_value().


def clear : Nil #

Removes all rows from @tree_store


def column_types=(types : Enumerable(UInt64)) : Nil #

This function is meant primarily for GObjects that inherit from Gtk::TreeStore, and should only be used when constructing a new Gtk::TreeStore. It will not function after a row has been added, or a method on the Gtk::TreeModel interface is called.


def insert(parent : Gtk::TreeIter?, position : Int32) : Gtk::TreeIter #

Creates a new row at @position. If parent is non-nil, then the row will be made a child of @parent. Otherwise, the row will be created at the toplevel. If @position is -1 or is larger than the number of rows at that level, then the new row will be inserted to the end of the list. @iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or gtk_tree_store_set_value().


def insert_after(parent : Gtk::TreeIter?, sibling : Gtk::TreeIter?) : Gtk::TreeIter #

Inserts a new row after @sibling. If @sibling is nil, then the row will be prepended to @parent ’s children. If @parent and @sibling are nil, then the row will be prepended to the toplevel. If both @sibling and @parent are set, then @parent must be the parent of @sibling. When @sibling is set, @parent is optional.

@iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or gtk_tree_store_set_value().


def insert_before(parent : Gtk::TreeIter?, sibling : Gtk::TreeIter?) : Gtk::TreeIter #

Inserts a new row before @sibling. If @sibling is nil, then the row will be appended to @parent ’s children. If @parent and @sibling are nil, then the row will be appended to the toplevel. If both @sibling and @parent are set, then @parent must be the parent of @sibling. When @sibling is set, @parent is optional.

@iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or gtk_tree_store_set_value().


def insert_with_values(parent : Gtk::TreeIter?, position : Int32, columns : Enumerable(Int32), values : Enumerable(_)) : Gtk::TreeIter #

Creates a new row at @position. @iter will be changed to point to this new row. If @position is -1, or larger than the number of rows on the list, then the new row will be appended to the list. The row will be filled with the values given to this function.

Calling gtk_tree_store_insert_with_values (tree_store, iter, position, ...) has the same effect as calling |[ gtk_tree_store_insert (tree_store, iter, position); gtk_tree_store_set (tree_store, iter, ...); ]| with the different that the former will only emit a row_inserted signal, while the latter will emit row_inserted, row_changed and if the tree store is sorted, rows_reordered. Since emitting the rows_reordered signal repeatedly can affect the performance of the program, gtk_tree_store_insert_with_values() should generally be preferred when inserting rows in a sorted tree store.


def is_ancestor(iter : Gtk::TreeIter, descendant : Gtk::TreeIter) : Bool #

Returns true if @iter is an ancestor of @descendant. That is, @iter is the parent (or grandparent or great-grandparent) of @descendant.


def iter_depth(iter : Gtk::TreeIter) : Int32 #

Returns the depth of @iter. This will be 0 for anything on the root level, 1 for anything down a level, etc.


def iter_is_valid(iter : Gtk::TreeIter) : Bool #

Checks if the given iter is a valid iter for this Gtk::TreeStore.

This function is slow. Only use it for debugging and/or testing purposes.


def move_after(iter : Gtk::TreeIter, position : Gtk::TreeIter?) : Nil #

Moves @iter in @tree_store to the position after @position. @iter and @position should be in the same level. Note that this function only works with unsorted stores. If @position is nil, @iter will be moved to the start of the level.


def move_before(iter : Gtk::TreeIter, position : Gtk::TreeIter?) : Nil #

Moves @iter in @tree_store to the position before @position. @iter and @position should be in the same level. Note that this function only works with unsorted stores. If @position is nil, @iter will be moved to the end of the level.


def prepend(parent : Gtk::TreeIter?) : Gtk::TreeIter #

Prepends a new row to @tree_store. If @parent is non-nil, then it will prepend the new row before the first child of @parent, otherwise it will prepend a row to the top level. @iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_tree_store_set() or gtk_tree_store_set_value().


def remove(iter : Gtk::TreeIter) : Bool #

Removes @iter from @tree_store. After being removed, @iter is set to the next valid row at that level, or invalidated if it previously pointed to the last one.


def set(iter : Gtk::TreeIter, columns : Enumerable(Int32), values : Enumerable(_)) : Nil #

Sets the value of one or more cells in the row referenced by @iter. The variable argument list should contain integer column numbers, each column number followed by the value to be set. The list is terminated by a -1. For example, to set column 0 with type %G_TYPE_STRING to “Foo”, you would write gtk_tree_store_set (store, iter, 0, "Foo", -1).

The value will be referenced by the store if it is a %G_TYPE_OBJECT, and it will be copied if it is a %G_TYPE_STRING or %G_TYPE_BOXED.


def set_value(iter : Gtk::TreeIter, column : Int32, value : _) : Nil #

Sets the data in the cell specified by @iter and @column. The type of @value must be convertible to the type of the column.


def swap(a : Gtk::TreeIter, b : Gtk::TreeIter) : Nil #

Swaps @a and @b in the same level of @tree_store. Note that this function only works with unsorted stores.