:right-sidebar: True FilterListModel =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: FilterListModel(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gio.ListModel`, :class:`~gi.repository.Gtk.SectionModel` ``GtkFilterListModel`` is a list model that filters the elements of the underlying model according to a ``GtkFilter``. It hides some elements from the other model according to criteria given by a ``GtkFilter``. The model can be set up to do incremental filtering, so that filtering long lists doesn't block the UI. See :obj:`~gi.repository.Gtk.FilterListModel.set_incremental` for details. ``GtkFilterListModel`` passes through sections from the underlying model. Constructors ------------ .. rst-class:: interim-class .. class:: FilterListModel :no-index: .. classmethod:: new(model: ~gi.repository.Gio.ListModel | None = None, filter: ~gi.repository.Gtk.Filter | None = None) -> ~gi.repository.Gtk.FilterListModel Creates a new ``GtkFilterListModel`` that will filter ``model`` using the given ``filter``. :param model: the model to sort :param filter: filter Methods ------- .. rst-class:: interim-class .. class:: FilterListModel :no-index: .. method:: get_filter() -> ~gi.repository.Gtk.Filter | None Gets the ``GtkFilter`` currently set on ``self``. .. method:: get_incremental() -> bool Returns whether incremental filtering is enabled. See :obj:`~gi.repository.Gtk.FilterListModel.set_incremental`. .. method:: get_model() -> ~gi.repository.Gio.ListModel | None Gets the model currently filtered or :const:`None` if none. .. method:: get_pending() -> int Returns the number of items that have not been filtered yet. You can use this value to check if ``self`` is busy filtering by comparing the return value to 0 or you can compute the percentage of the filter remaining by dividing the return value by the total number of items in the underlying model: .. code-block:: :dedent: pending = gtk_filter_list_model_get_pending (self); model = gtk_filter_list_model_get_model (self); percentage = pending / (double) g_list_model_get_n_items (model); If no filter operation is ongoing - in particular when :obj:`~gi.repository.Gtk.FilterListModel.props.incremental` is :const:`False` - this function returns 0. .. method:: set_filter(filter: ~gi.repository.Gtk.Filter | None = None) -> None Sets the filter used to filter items. :param filter: filter to use .. method:: set_incremental(incremental: bool) -> None Sets the filter model to do an incremental sort. When incremental filtering is enabled, the ``GtkFilterListModel`` will not run filters immediately, but will instead queue an idle handler that incrementally filters the items and adds them to the list. This of course means that items are not instantly added to the list, but only appear incrementally. When your filter blocks the UI while filtering, you might consider turning this on. Depending on your model and filters, this may become interesting around 10,000 to 100,000 items. By default, incremental filtering is disabled. See :obj:`~gi.repository.Gtk.FilterListModel.get_pending` for progress information about an ongoing incremental filtering operation. :param incremental: :const:`True` to enable incremental filtering .. method:: set_model(model: ~gi.repository.Gio.ListModel | None = None) -> None Sets the model to be filtered. Note that GTK makes no effort to ensure that ``model`` conforms to the item type of ``self``. It assumes that the caller knows what they are doing and have set up an appropriate filter to ensure that item types match. :param model: The model to be filtered Properties ---------- .. rst-class:: interim-class .. class:: FilterListModel :no-index: .. attribute:: props.filter :type: ~gi.repository.Gtk.Filter The filter for this model. .. attribute:: props.incremental :type: bool If the model should filter 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 filtered. .. 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 Number of items not yet filtered.