class Gtk::SortListModel

Overview

A GListModel that sorts the elements of an underlying model according to a Gtk::Sorter.

The model is a stable sort. If two items compare equal according to the sorter, the one that appears first in the original model will also appear first after sorting. Note that if you change the sorter, the previous order will have no influence on the new order. If you want that, consider using a Gtk::MultiSorter and appending the previous sorter to it.

The model can be set up to do incremental sorting, so that sorting long lists doesn't block the UI. See Gtk::SortListModel#incremental= for details.

Gtk::SortListModel is a generic model and because of that it cannot take advantage of any external knowledge when sorting. If you run into performance issues with Gtk::SortListModel, it is strongly recommended that you write your own sorting list model.

Included Modules

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/sort_list_model.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Gio::ListModel

item(position : UInt32) : GObject::Object | Nil item, item_type : UInt64 item_type, items_changed(position : UInt32, removed : UInt32, added : UInt32) : Nil
items_changed(position : Int, removed : Int, added : Int) : Nil
items_changed
, items_changed_signal items_changed_signal, n_items : UInt32 n_items, to_unsafe to_unsafe

Constructor methods inherited from module Gio::ListModel

cast(obj : GObject::Object) : self cast

Class methods inherited from module Gio::ListModel

cast?(obj : GObject::Object) : self | Nil cast?, g_type : UInt64 g_type

Instance methods inherited from class GObject::Object

==(other : self) ==, 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) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, 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) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil 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, 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

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : 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

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

def self.new(model : Gio::ListModel | Nil, sorter : Gtk::Sorter | Nil) : self #

Creates a new sort list model that uses the sorter to sort model.


[View source]
def self.new #

Initialize a new SortListModel.


[View source]
def self.new(*, incremental : Bool | Nil = nil, model : Gio::ListModel | Nil = nil, pending : UInt32 | Nil = nil, sorter : Gtk::Sorter | Nil = nil) #

[View source]

Class Method Detail

def self.g_type : UInt64 #

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


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def incremental : Bool #

Returns whether incremental sorting is enabled.

See Gtk::SortListModel#incremental=.


[View source]
def incremental=(incremental : Bool) : Nil #

Sets the sort model to do an incremental sort.

When incremental sorting is enabled, the Gtk::SortListModel will not do a complete sort immediately, but will instead queue an idle handler that incrementally sorts the items towards their correct position. This of course means that items do not instantly appear in the right place. It also means that the total sorting time is a lot slower.

When your filter blocks the UI while sorting, you might consider turning this on. Depending on your model and sorters, this may become interesting around 10,000 to 100,000 items.

By default, incremental sorting is disabled.

See Gtk::SortListModel#pending for progress information about an ongoing incremental sorting operation.


[View source]
def incremental? : Bool #

[View source]
def model : Gio::ListModel | Nil #

Gets the model currently sorted or nil if none.


[View source]
def model=(model : Gio::ListModel | Nil) : Nil #

Sets the model to be sorted.

The model's item type must conform to the item type of self.


[View source]
def pending : UInt32 #

Estimates progress of an ongoing sorting operation.

The estimate is the number of items that would still need to be sorted to finish the sorting operation if this was a linear algorithm. So this number is not related to how many items are already correctly sorted.

If you want to estimate the progress, you can use code like this:

WARNING ⚠️ The following code is in c ⚠️

pending = gtk_sort_list_model_get_pending (self);
model = gtk_sort_list_model_get_model (self);
progress = 1.0 - pending / (double) MAX (1, g_list_model_get_n_items (model));

If no sort operation is ongoing - in particular when Gtk::SortListModel#incremental is false - this function returns 0.


[View source]
def sorter : Gtk::Sorter | Nil #

Gets the sorter that is used to sort self.


[View source]
def sorter=(sorter : Gtk::Sorter | Nil) : Nil #

Sets a new sorter on self.


[View source]