:right-sidebar: True SortListModel =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: SortListModel(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gio.ListModel`, :class:`~gi.repository.Gtk.SectionModel` A ``GListModel`` that sorts the elements of an underlying model 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 :obj:`~gi.repository.Gtk.SortListModel.set_incremental` 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 :obj:`~gi.repository.Gtk.SortListModel.props.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 :obj:`~gi.repository.Gtk.SortListModel.props.sorter` will then be used to sort items inside their sections. Constructors ------------ .. rst-class:: interim-class .. class:: SortListModel :no-index: .. classmethod:: new(model: ~gi.repository.Gio.ListModel | None = None, sorter: ~gi.repository.Gtk.Sorter | None = None) -> ~gi.repository.Gtk.SortListModel Creates a new sort list model that uses the ``sorter`` to sort ``model``. :param model: the model to sort :param sorter: the ``GtkSorter`` to sort ``model`` with, Methods ------- .. rst-class:: interim-class .. class:: SortListModel :no-index: .. method:: get_incremental() -> bool Returns whether incremental sorting is enabled. See :obj:`~gi.repository.Gtk.SortListModel.set_incremental`. .. method:: get_model() -> ~gi.repository.Gio.ListModel | None Gets the model currently sorted or :const:`None` if none. .. method:: get_pending() -> int 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: .. code-block:: :dedent: 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 :obj:`~gi.repository.Gtk.SortListModel.props.incremental` is :const:`False` - this function returns 0. .. method:: get_section_sorter() -> ~gi.repository.Gtk.Sorter | None Gets the section sorter that is used to sort items of ``self`` into sections. .. versionadded:: 4.12 .. method:: get_sorter() -> ~gi.repository.Gtk.Sorter | None Gets the sorter that is used to sort ``self``. .. method:: set_incremental(incremental: bool) -> None 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 :obj:`~gi.repository.Gtk.SortListModel.get_pending` for progress information about an ongoing incremental sorting operation. :param incremental: :const:`True` to sort incrementally .. method:: set_model(model: ~gi.repository.Gio.ListModel | None = None) -> None Sets the model to be sorted. The ``model``'s item type must conform to the item type of ``self``. :param model: The model to be sorted .. method:: set_section_sorter(sorter: ~gi.repository.Gtk.Sorter | None = None) -> None Sets a new section sorter on ``self``. .. versionadded:: 4.12 :param sorter: the ``GtkSorter`` to sort ``model`` with .. method:: set_sorter(sorter: ~gi.repository.Gtk.Sorter | None = None) -> None Sets a new sorter on ``self``. :param sorter: the ``GtkSorter`` to sort ``model`` with Properties ---------- .. rst-class:: interim-class .. class:: SortListModel :no-index: .. attribute:: props.incremental :type: bool If the model should sort items incrementally. .. attribute:: props.item_type :type: type The type of items. See :obj:`~gi.repository.Gio.ListModel.get_item_type`. .. versionadded:: 4.8 .. attribute:: props.model :type: ~gi.repository.Gio.ListModel The model being sorted. .. attribute:: props.n_items :type: int The number of items. See :obj:`~gi.repository.Gio.ListModel.get_n_items`. .. versionadded:: 4.8 .. attribute:: props.pending :type: int Estimate of unsorted items remaining. .. attribute:: props.section_sorter :type: ~gi.repository.Gtk.Sorter The section sorter for this model, if one is set. .. versionadded:: 4.12 .. attribute:: props.sorter :type: ~gi.repository.Gtk.Sorter The sorter for this model.