Gtk.SortListModel

g GObject.GInterface GObject.GInterface Gio.ListModel Gio.ListModel GObject.GInterface->Gio.ListModel Gtk.SectionModel Gtk.SectionModel GObject.GInterface->Gtk.SectionModel GObject.Object GObject.Object Gtk.SortListModel Gtk.SortListModel GObject.Object->Gtk.SortListModel Gio.ListModel->Gtk.SortListModel Gtk.SectionModel->Gtk.SortListModel

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.ListModel (4), Gtk.SectionModel (2)

Structs:

GObject.ObjectClass (5)

class

new (model, sorter)

get_incremental ()

get_model ()

get_pending ()

get_section_sorter ()

get_sorter ()

set_incremental (incremental)

set_model (model)

set_section_sorter (sorter)

set_sorter (sorter)

Virtual Methods

Inherited:

GObject.Object (7), Gio.ListModel (3), Gtk.SectionModel (1)

Properties

Name

Type

Flags

Short Description

incremental

bool

r/w/en

item-type

GObject.GType

r

model

Gio.ListModel

r/w/en

n-items

int

r

pending

int

r/en

section-sorter

Gtk.Sorter

r/w/en

sorter

Gtk.Sorter

r/w/en

Signals

Inherited:

GObject.Object (1), Gio.ListModel (1), Gtk.SectionModel (1)

Fields

Inherited:

GObject.Object (1), Gio.ListModel (1), Gtk.SectionModel (1)

Class Details

class Gtk.SortListModel(**kwargs)
Bases:

GObject.Object, Gio.ListModel, Gtk.SectionModel

Abstract:

No

Structure:

Gtk.SortListModelClass

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 [method`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 [property`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 [property`Gtk`.SortListModel:sorter] will then be used to sort items inside their sections.

classmethod new(model, sorter)[source]
Parameters:
Returns:

a new GtkSortListModel

Return type:

Gtk.SortListModel

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

get_incremental()[source]
Returns:

True if incremental sorting is enabled

Return type:

bool

Returns whether incremental sorting is enabled.

See [method`Gtk`.SortListModel.set_incremental].

get_model()[source]
Returns:

The model that gets sorted

Return type:

Gio.ListModel or None

Gets the model currently sorted or None if none.

get_pending()[source]
Returns:

a progress estimate of remaining items to sort

Return type:

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: ``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 [property`Gtk`.SortListModel:incremental] is False - this function returns 0.

get_section_sorter()[source]
Returns:

the sorter of #self

Return type:

Gtk.Sorter or None

Gets the section sorter that is used to sort items of self into sections.

New in version 4.12.

get_sorter()[source]
Returns:

the sorter of #self

Return type:

Gtk.Sorter or None

Gets the sorter that is used to sort self.

set_incremental(incremental)[source]
Parameters:

incremental (bool) – True to sort incrementally

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 [method`Gtk`.SortListModel.get_pending] for progress information about an ongoing incremental sorting operation.

set_model(model)[source]
Parameters:

model (Gio.ListModel or None) – The model to be sorted

Sets the model to be sorted.

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

set_section_sorter(sorter)[source]
Parameters:

sorter (Gtk.Sorter or None) – the GtkSorter to sort model with

Sets a new section sorter on self.

New in version 4.12.

set_sorter(sorter)[source]
Parameters:

sorter (Gtk.Sorter or None) – the GtkSorter to sort model with

Sets a new sorter on self.

Property Details

Gtk.SortListModel.props.incremental
Name:

incremental

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

If the model should sort items incrementally.

Gtk.SortListModel.props.item_type
Name:

item-type

Type:

GObject.GType

Default Value:

<GType GObject>

Flags:

READABLE

The type of items. See [method`Gio`.ListModel.get_item_type].

New in version 4.8.

Gtk.SortListModel.props.model
Name:

model

Type:

Gio.ListModel

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The model being sorted.

Gtk.SortListModel.props.n_items
Name:

n-items

Type:

int

Default Value:

0

Flags:

READABLE

The number of items. See [method`Gio`.ListModel.get_n_items].

New in version 4.8.

Gtk.SortListModel.props.pending
Name:

pending

Type:

int

Default Value:

0

Flags:

READABLE, EXPLICIT_NOTIFY

Estimate of unsorted items remaining.

Gtk.SortListModel.props.section_sorter
Name:

section-sorter

Type:

Gtk.Sorter

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The section sorter for this model, if one is set.

New in version 4.12.

Gtk.SortListModel.props.sorter
Name:

sorter

Type:

Gtk.Sorter

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The sorter for this model.