Class SortListModel<T extends GObject>

All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, SequencedCollection<T>, ListModel<T>, SectionModel<T>, Proxy, ListModelJavaList<T>

@Generated("org.javagi.JavaGI") public class SortListModel<T extends GObject> extends GObject implements ListModel<T>, SectionModel<T>

A list model that sorts the elements of another model.

The elements are sorted according to a GtkSorter.

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 GtkMultiSorter 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 setIncremental(boolean) for details.

GtkSortListModel 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 GtkSortListModel, it is strongly recommended that you write your own sorting list model.

GtkSortListModel allows sorting the items into sections. It implements GtkSectionModel and when Gtk.SortListModel:section-sorter is set, it will sort all items with that sorter and items comparing equal with it will be put into the same section. The Gtk.SortListModel:sorter will then be used to sort items inside their sections.

  • Constructor Details

    • SortListModel

      public SortListModel(MemorySegment address)
      Create a SortListModel instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • SortListModel

      public SortListModel(@Nullable ListModel model, @Nullable Sorter sorter)
      Creates a new sort list model that uses the sorter to sort model.
      Parameters:
      model - the model to sort
      sorter - the GtkSorter to sort model with,
    • SortListModel

      public SortListModel()
      Create a new SortListModel.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the SortListModel class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected SortListModel asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getIncremental

      public boolean getIncremental()

      Returns whether incremental sorting is enabled.

      See setIncremental(boolean).

      Returns:
      true if incremental sorting is enabled
    • getModel

      public @Nullable ListModel getModel()
      Gets the model currently sorted or null if none.
      Returns:
      The model that gets sorted
    • getPending

      public int getPending()

      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:

      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.

      Returns:
      a progress estimate of remaining items to sort
    • getSectionSorter

      public @Nullable Sorter getSectionSorter()
      Gets the section sorter that is used to sort items of this SortListModel into sections.
      Returns:
      the sorter of self
      Since:
      4.12
    • getSorter

      public @Nullable Sorter getSorter()
      Gets the sorter that is used to sort self.
      Returns:
      the sorter of self
    • setIncremental

      public void setIncremental(boolean incremental)

      Sets the sort model to do an incremental sort.

      When incremental sorting is enabled, the GtkSortListModel 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 getPending() for progress information about an ongoing incremental sorting operation.

      Parameters:
      incremental - true to sort incrementally
    • setModel

      public void setModel(@Nullable ListModel model)

      Sets the model to be sorted.

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

      Parameters:
      model - The model to be sorted
    • setSectionSorter

      public void setSectionSorter(@Nullable Sorter sorter)
      Sets a new section sorter on self.
      Parameters:
      sorter - the GtkSorter to sort model with
      Since:
      4.12
    • setSorter

      public void setSorter(@Nullable Sorter sorter)
      Sets a new sorter on self.
      Parameters:
      sorter - the GtkSorter to sort model with
    • builder

      public static SortListModel.Builder<? extends SortListModel.Builder> builder()
      A SortListModel.Builder object constructs a SortListModel with the specified properties. Use the various set...() methods to set properties, and finish construction with SortListModel.Builder.build().
      Returns:
      the builder object