Class Sorter

All Implemented Interfaces:
PointerInterface
Direct Known Subclasses:
CustomSorter, MultiSorter, NumericSorter, StringSorter, TreeListRowSorter

public class Sorter extends Object
`GtkSorter` is an object to describe sorting criteria.

Its primary user is [class@Gtk.SortListModel]

The model will use a sorter to determine the order in which
its items should appear by calling [method@Gtk.Sorter.compare]
for pairs of items.

Sorters may change their sorting behavior through their lifetime.
In that case, they will emit the [signal@Gtk.Sorter::changed] signal
to notify that the sort order is no longer valid and should be updated
by calling gtk_sorter_compare() again.

GTK provides various pre-made sorter implementations for common sorting
operations. [class@Gtk.ColumnView] has built-in support for sorting lists
via the [property@Gtk.ColumnViewColumn:sorter] property, where the user can
change the sorting by clicking on list headers.

Of course, in particular for large lists, it is also possible to subclass
`GtkSorter` and provide one's own sorter.

https://docs.gtk.org/gtk4/class.Sorter.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • changed

      public void changed(int change)
      Notifies all users of the sorter that it has changed.

      This emits the [signal@Gtk.Sorter::changed] signal. Users
      of the sorter should then update the sort order via
      [method@Gtk.Sorter.compare].

      Depending on the @change parameter, it may be possible to
      update the sort order without a full resorting. Refer to
      the [enum@Gtk.SorterChange] documentation for details.

      This function is intended for implementors of `GtkSorter`
      subclasses and should not be called from other functions.
      Parameters:
      change - How the sorter changed
    • compare

      public int compare(@Nonnull Pointer item1, @Nonnull Pointer item2)
      Compares two given items according to the sort order implemented
      by the sorter.

      Sorters implement a partial order:

      * It is reflexive, ie a = a
      * It is antisymmetric, ie if a < b and b < a, then a = b
      * It is transitive, ie given any 3 items with a ≤ b and b ≤ c,
      then a ≤ c

      The sorter may signal it conforms to additional constraints
      via the return value of [method@Gtk.Sorter.get_order].
      Parameters:
      item1 - first item to compare
      item2 - second item to compare
      Returns:
      %GTK_ORDERING_EQUAL if @item1 == @item2, %GTK_ORDERING_SMALLER if @item1 < @item2, %GTK_ORDERING_LARGER if @item1 > @item2
    • getOrder

      public int getOrder()
      Gets the order that @self conforms to.

      See [enum@Gtk.SorterOrder] for details
      of the possible return values.

      This function is intended to allow optimizations.
      Returns:
      The order
    • onChanged

      public SignalHandler onChanged(Sorter.OnChanged signal)
      Connect to signal "changed".
      See Sorter.OnChanged.onChanged(int) for signal description.
      Field SIGNAL_ON_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()