GtkSortListModel — A list model that sorts its items
GtkSortListModel * | gtk_sort_list_model_new () |
void | gtk_sort_list_model_set_sorter () |
GtkSorter * | gtk_sort_list_model_get_sorter () |
void | gtk_sort_list_model_set_model () |
GListModel * | gtk_sort_list_model_get_model () |
void | gtk_sort_list_model_set_incremental () |
gboolean | gtk_sort_list_model_get_incremental () |
guint | gtk_sort_list_model_get_pending () |
gboolean | incremental | Read / Write |
GListModel * | model | Read / Write |
guint | pending | Read |
GtkSorter * | sorter | Read / Write |
GObject ╰── GtkSortListModel
GtkSortListModel implements GListModel.
#include <gtk/gtk.h>
GtkSortListModel is a list model that takes a list model and sorts its elements according to a GtkSorter.
The model can be set up to do incremental sorting, so that sorting long lists doesn't block the UI. See gtk_sort_list_model_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 * gtk_sort_list_model_new (GListModel *model
,GtkSorter *sorter
);
Creates a new sort list model that uses the sorter
to sort model
.
model | the model to sort, or | [allow-none][transfer full] |
sorter | the GtkSorter to sort | [allow-none][transfer full] |
a new GtkSortListModel
void gtk_sort_list_model_set_sorter (GtkSortListModel *self
,GtkSorter *sorter
);
Sets a new sorter on self
.
self | ||
sorter | the GtkSorter to sort | [allow-none] |
GtkSorter *
gtk_sort_list_model_get_sorter (GtkSortListModel *self
);
Gets the sorter that is used to sort self
.
self |
the sorter of self.
[nullable][transfer none]
void gtk_sort_list_model_set_model (GtkSortListModel *self
,GListModel *model
);
Sets the model to be sorted. The model
's item type must conform to the item type of self
.
self | ||
model | The model to be sorted. | [allow-none] |
GListModel *
gtk_sort_list_model_get_model (GtkSortListModel *self
);
Gets the model currently sorted or NULL
if none.
self |
The model that gets sorted.
[nullable][transfer none]
void gtk_sort_list_model_set_incremental (GtkSortListModel *self
,gboolean incremental
);
Sets the sort model to do an incremental sort.
When incremental sorting is enabled, the sortlistmodel 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 gtk_sort_list_model_get_pending()
for progress information about an ongoing incremental sorting operation.
self | ||
incremental |
|
gboolean
gtk_sort_list_model_get_incremental (GtkSortListModel *self
);
Returns whether incremental sorting was enabled via gtk_sort_list_model_set_incremental()
.
self |
TRUE
if incremental sorting is enabled
guint
gtk_sort_list_model_get_pending (GtkSortListModel *self
);
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 “incremental” is FALSE
- this function returns 0.
self |
a progress estimate of remaining items to sort
typedef struct _GtkSortListModel GtkSortListModel;
“incremental”
property“incremental” gboolean
If the model should sort items incrementally
Owner: GtkSortListModel
Flags: Read / Write
Default value: FALSE
“model”
property“model” GListModel *
The model being sorted
Owner: GtkSortListModel
Flags: Read / Write
“pending”
property“pending” guint
Estimate of unsorted items remaining
Owner: GtkSortListModel
Flags: Read
Default value: 0
“sorter”
property“sorter” GtkSorter *
The sorter for this model
Owner: GtkSortListModel
Flags: Read / Write
GListModel, GtkSorter
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkSortListModel.html