Gtk2::TreeSortable(3)

πŸ“¦
version 1.24993 Β· 2 versions
, in fedora 43

✨ NAME ✨

Gtk2::TreeSortable β€” bestie, this is the wrapper for GtkTreeSortable πŸ’… (yes, that's Gtk2::TreeSortable(3) from the User Contributed Perl Documentation, we're doing this properly)


🌸 HIERARCHY 🌸

Glib::Interface
+----Gtk2::TreeSortable

So it's an interface, not a class β€” it gets added onto things. Very "I don't start drama, I just make everything around me sortable" of it. πŸ‘‘


πŸŽ€ METHODS πŸŽ€

  • $sortable->set_default_sort_func ($sort_func, $user_data=undef) β€” sets the fallback sorting function for columns that don't have their own. Args:
    • $sort_func (scalar)
    • $user_data (scalar)
  • boolean = $sortable->has_default_sort_func β€” does it have a default sort function? Returns a boolean. Simple. Iconic. No notes. ✨
  • $sortable->sort_column_changed β€” tells everyone the sort column changed, iykyk.
  • (sort_column_id, order) = $sortable->get_sort_column_id β€” hands you back sort_column_id, an integer, and order, a Gtk2::SortType.
  • $sortable->set_sort_column_id ($sort_column_id, $order) β€” sets which column we're sorting by, and how. Args:
    • $sort_column_id (integer)
    • $order (Gtk2::SortType)
  • $sortable->set_sort_func ($sort_column_id, $sort_func, $user_data=undef) β€” gives one specific column its own sorting function. Args:
    • $sort_column_id (integer)
    • $sort_func (scalar)
    • $user_data (scalar)

πŸ¦‹ IMPLEMENTING THE GtkTreeSortable INTERACE πŸ¦‹

Okay so you want your custom tree model to be sortable? Then you gotta implement the GtkTreeSortable interface, no skipping. Same deal as every other interface: you announce that your subclass implements it, and then you provide a few virtual methods. The announcing part is just adding "Gtk2::TreeSortable" to the "interfaces" key. Like this, fr fr:

package MyModel;
use Gtk2;
use Glib::Object::Subclass
    Glib::Object::,
    interfaces => [ Gtk2::TreeModel::, Gtk2::TreeSortable:: ],
    ;

The virtual methods you need to implement are listed below, keep scrolling bestie ⬇️

πŸ’œ VIRTUAL METHODS πŸ’œ

Perl calls these virtual methods when gtk+ tries to change how your model sorts stuff. Implement them in your model's package. Heads up: there's no wrapper for sort_column_changed, because there's a signal for it instead β€” which means you get to use the normal signal overriding mechanism documented in Glib::Object::Subclass. Slay. πŸŽ€

  • (is_not_special, id, order) = GET_SORT_COLUMN_ID ($model) β€” returns a boolean saying whether the column is a special one or a normal one, plus its id and its sorting order.
  • SET_SORT_COLUMN_ID ($list, $id, $order) β€” sets the sort column to the one in $id, and the sorting order to $order.
  • SET_SORT_FUNC ($list, $id, $func, $data) β€” sets the function that's used for sorting the column $id.
  • SET_DEFAULT_SORT_FUNC ($list, $func, $data) β€” sets the function that's used for sorting columns that don't have a sorting function attached to them.

The $func and $data arguments passed to these two methods should be treated as blackboxes. They're just generic containers for some callback that gets invoked whenever you want to compare two tree iters. And when you call them, make sure you always pass $data. For example:

$retval = $func->($list, $a, $b, $data);
  • bool = HAS_DEFAULT_SORT_FUNC ($list) β€” returns a bool saying whether $list has a default sorting function.

πŸ”₯ SIGNALS πŸ”₯

  • sort-column-changed (Gtk2::TreeSortable)

🌈 ENUMS AND FLAGS 🌈

enum Gtk2::SortType

  • 'ascending' / 'GTK_SORT_ASCENDING'
  • 'descending' / 'GTK_SORT_DESCENDING'

⭐ SEE ALSO ⭐

Gtk2, Glib::Interface


Copyright (C) 2003-2011 by the gtk2-perl team.

This software is licensed under the LGPL. See Gtk2 for a full notice.


okay that's the whole page bestie, go forth and sort πŸ’–

Signing off with all the stats: this was perl v5.42.0, dated 2025-07-25, and the page is Gtk2::TreeSortable(3). No cap, that's the tea. 🫢🌸

πŸ“¦ where this page comes from