About all my projects
Gnome::Gtk4::ListStore

Gnome::Gtk4::ListStore

Description

A list-like data structure that can be used with the Gnome::Gtk4::TreeView.

The Gnome::Gtk4::ListStore object is a list model for use with a Gnome::Gtk4::TreeView widget. It implements the Gnome::Gtk4::R-TreeModel interface, and consequentialy, can use all of the methods available there. It also implements the Gnome::Gtk4::R-TreeSortable interface so it can be sorted by the view. Finally, it also implements the tree [drag](iface.TreeDragSource.html) and [drop](iface.TreeDragDest.html) interfaces.

The Gnome::Gtk4::ListStore can accept most Gnome::GObject::ListStores as a column type, though it can’t accept all custom types. Internally, it will keep a copy of data passed in (such as a string or a boxed pointer). Columns that accept Gnome::GObject::Objects are handled a little differently. The Gnome::Gtk4::ListStore will keep a reference to the object instead of copying the value. As a result, if the object is modified, it is up to the application writer to call .row-changed() in class Gnome::Gtk4::R-TreeModel to emit the row_changed defined in TreeModel signal. This most commonly affects lists with Gnome::Gdk4::Textures stored.

An example for creating a simple list store:

Gnome::Gtk4::ListStore is deprecated since GTK 4.10, and should not be used in newly written code. You should use Gnome::Gtk4::ListStore instead, and the various list models provided by GTK.

Performance Considerations

Internally, the Gnome::Gtk4::ListStore was originally implemented with a linked list with a tail pointer. As a result, it was fast at data insertion and deletion, and not fast at random data access. The Gnome::Gtk4::ListStore sets the GTK_TREE_MODEL_ITERS_PERSIST flag, which means that Gnome::Gtk4::N-TreeIters can be cached while the row exists. Thus, if access to a particular row is needed often and your code is expected to run on older versions of GTK, it is worth keeping the iter around.

Atomic Operations

It is important to note that only the methods .insert-with-values() and .insert-with-valuesv() are atomic, in the sense that the row is being appended to the store and the values filled in in a single operation with regard to Gnome::Gtk4::R-TreeModel signaling. In contrast, using e.g. .append() and then .set() will first create a row, which triggers the Gnome::Gtk4::R-TreeModel::row-inserted` signal on Gnome::Gtk4::ListStore. The row, however, is still empty, and any signal handler connecting to Gnome::Gtk4::R-TreeModel::row-inserted` on this particular store should be prepared for the situation that the row might be empty. This is especially important if you are wrapping the Gnome::Gtk4::ListStore inside a Gnome::Gtk4::R-TreeModelFilter and are using a Gnome::Gtk4::R-TreeModelFilterVisibleFunc. Using any of the non-atomic operations to append rows to the Gnome::Gtk4::ListStore will cause the Gnome::Gtk4::R-TreeModelFilterVisibleFunc to be visited with an empty row first; the function must be prepared for that.

GtkListStore as GtkBuildable

The GtkListStore implementation of the Gnome::Gtk4::R-Buildable interface allows to specify the model columns with a `<columns>` element that may contain multiple `<column>` elements, each specifying one model column. The “type” attribute specifies the data type for the column.

Additionally, it is possible to specify content for the list store in the UI definition, with the `<data>` element. It can contain multiple `<row>` elements, each specifying to content for one row of the list model. Inside a `<row>`, the `<col>` elements specify the content for individual cells.

Note that it is probably more common to define your models in the code, and one might consider it a layering violation to specify the content of a list store in a UI definition, data, not presentation, and common wisdom is to separate the two, as far as possible.

An example of a UI Definition fragment for a list store:

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-liststore This function is not yet available

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Creates a new list store.

The list store will have $n-columns columns, with each column using the given type passed to this function.

Note that only types derived from standard GObject fundamental types are supported.

As an example:

will create a new Gnome::Gtk4::ListStore with three columns, of type int, gchararray and Gnome::Gdk4::Texture, respectively.

method new-liststore ( Int() $n-columns, … --> Gnome::Gtk4::ListStore \)
  • $n-columns; number of columns in the list store.

  • …; …. Note that each argument must be specified as a type followed by its value!

newv This function is not yet available

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Creates a new Gnome::Gtk4::ListStore.

This function is meant to be used by language bindings.

method newv ( Int() $n-columns, … --> Gnome::Gtk4::ListStore \)
  • $n-columns; number of columns in the list store.

  • types; an array of Gnome::GObject::ListStore types for the columns, from first to last. Note that each argument must be specified as a type followed by its value!

Methods

append

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Appends a new row to $list-store. $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 .set() or .set-value().

method append ( N-Object $iter )
  • $iter; An unset Gnome::Gtk4::N-TreeIter to set to the appended row

clear

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Removes all rows from the list store.

method clear ( )

insert

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Creates a new row at $position. $iter will be changed to point to this new row. If $position is -1 or is larger than the number of rows on the list, then the new row will be appended to the list. The row will be empty after this function is called. To fill in values, you need to call .set() or .set-value().

method insert ( N-Object $iter, Int() $position )
  • $iter; An unset Gnome::Gtk4::N-TreeIter to set to the new row

  • $position; position to insert the new row, or -1 for last.

insert-after

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Inserts a new row after $sibling. If $sibling is undefined, then the row will be prepended to the beginning 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 .set() or .set-value().

method insert-after ( N-Object $iter, N-Object $sibling )
  • $iter; An unset Gnome::Gtk4::N-TreeIter to set to the new row

  • $sibling; A valid Gnome::Gtk4::N-TreeIter

insert-before

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Inserts a new row before $sibling. If $sibling is undefined, then the row will be appended 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 .set() or .set-value().

method insert-before ( N-Object $iter, N-Object $sibling )
  • $iter; An unset Gnome::Gtk4::N-TreeIter to set to the new row

  • $sibling; A valid Gnome::Gtk4::N-TreeIter

insert-with-values This function is not yet available

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

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 in 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_list_store_insert_with_values (list_store, iter, position...)` has the same effect as calling:

with the difference that the former will only emit Gnome::Gtk4::R-TreeModel::row-inserted once, while the latter will emit Gnome::Gtk4::R-TreeModel::row-inserted, Gnome::Gtk4::R-TreeModel::row-changed and, if the list store is sorted, Gnome::Gtk4::R-TreeModel::rows-reordered for every inserted value.

Since emitting the Gnome::Gtk4::R-TreeModel::rows-reordered` signal repeatedly can affect the performance of the program, .insert-with-values() should generally be preferred when inserting rows in a sorted list store.

method insert-with-values ( N-Object $iter, Int() $position, … )
  • $iter; An unset Gnome::Gtk4::N-TreeIter to set to the new row

  • $position; position to insert the new row, or -1 to append after existing rows.

  • …; …. Note that each argument must be specified as a type followed by its value!

insert-with-valuesv

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

A variant of .insert-with-values() which takes the columns and values as two arrays, instead of varargs.

This function is mainly intended for language-bindings.

method insert-with-valuesv ( N-Object $iter, Int() $position, Array[Int] $columns, N-Object $values, Int() $n-values )
  • $iter; An unset Gnome::Gtk4::N-TreeIter to set to the new row

  • $position; position to insert the new row, or -1 for last.

  • $columns; an array of column numbers.

  • $values; an array of GValues

  • $n-values; the length of the $columns and $values arrays.

iter-is-valid

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Checks if the given iter is a valid iter for this Gnome::Gtk4::ListStore.

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

method iter-is-valid ( N-Object $iter --> Bool )
  • $iter; the iterator to check

Return value; True if the iter is valid, False if the iter is invalid..

move-after

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Moves $iter in $store to the position after $position. Note that this function only works with unsorted stores. If $position is undefined, $iter will be moved to the start of the list.

method move-after ( N-Object $iter, N-Object $position )
  • $iter; A Gnome::Gtk4::N-TreeIter

  • $position; A Gnome::Gtk4::N-TreeIter

move-before

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Moves $iter in $store to the position before $position. Note that this function only works with unsorted stores. If $position is undefined, $iter will be moved to the end of the list.

method move-before ( N-Object $iter, N-Object $position )
  • $iter; A Gnome::Gtk4::N-TreeIter

  • $position; A Gnome::Gtk4::N-TreeIter

prepend

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Prepends a new row to $list-store. $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 .set() or .set-value().

method prepend ( N-Object $iter )
  • $iter; An unset Gnome::Gtk4::N-TreeIter to set to the prepend row

remove

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Removes the given row from the list store. After being removed, $iter is set to be the next valid row, or invalidated if it pointed to the last row in $list-store.

method remove ( N-Object $iter --> Bool )
  • $iter; A valid Gnome::Gtk4::N-TreeIter

Return value; True if $iter is valid, False if not..

reorder

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Reorders $store to follow the order indicated by $new-order. Note that this function only works with unsorted stores.

method reorder ( Array[Int] $new-order )
  • $new-order; an array of integers mapping the new position of each child to its old position before the re-ordering, i.e. $new-order`[newpos] = oldpos`. It must have exactly as many items as the list store’s length..

set This function is not yet available

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

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_list_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.

method set ( N-Object $iter, … )
  • $iter; row iterator

  • …; …. Note that each argument must be specified as a type followed by its value!

set-column-types This function is not yet available

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Sets the types of the columns of a list store.

This function is meant primarily for objects that inherit from Gnome::Gtk4::ListStore, and should only be used when constructing a new instance.

This function cannot be called after a row has been added, or a method on the Gnome::Gtk4::R-TreeModel interface is called.

method set-column-types ( Int() $n-columns, … )
  • $n-columns; Number of columns for the list store.

  • types; An array length n of Gnome::GObject::ListStores. Note that each argument must be specified as a type followed by its value!

set-valist This function is not yet available

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

See .set(); this version takes a va_list for use by language bindings.

method set-valist ( N-Object $iter, … )
  • $iter; A valid Gnome::Gtk4::N-TreeIter for the row being modified

  • var-args; va_list of column/value pairs. Note that each argument must be specified as a type followed by its value!

set-value

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

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

method set-value ( N-Object $iter, Int() $column, N-Object $value )
  • $iter; A valid Gnome::Gtk4::N-TreeIter for the row being modified

  • $column; column number to modify.

  • $value; new value for the cell

set-valuesv

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

A variant of .set-valist() which takes the columns and values as two arrays, instead of varargs. This function is mainly intended for language-bindings and in case the number of columns to change is not known until run-time.

method set-valuesv ( N-Object $iter, Array[Int] $columns, N-Object $values, Int() $n-values )
  • $iter; A valid Gnome::Gtk4::N-TreeIter for the row being modified

  • $columns; an array of column numbers.

  • $values; an array of GValues

  • $n-values; the length of the $columns and $values arrays.

swap

Note: The native version of this routine is deprecated in gtk4-lib() since version 4.10

Swaps $a and $b in $store. Note that this function only works with unsorted stores.

method swap ( N-Object $a, N-Object $b )
  • $a; A Gnome::Gtk4::N-TreeIter

  • $b; Another Gnome::Gtk4::N-TreeIter