GtkSortListModel

GtkSortListModel — A list model that sorts its items

Functions

Properties

gboolean has-sort Read
GType * item-type Read / Write / Construct Only
GListModel * model Read / Write / Construct Only

Types and Values

Object Hierarchy

    GObject
    ╰── GtkSortListModel

Implemented Interfaces

GtkSortListModel implements GListModel.

Includes

#include <gtk/gtk.h>

Description

GtkSortListModel is a list model that takes a list model and sorts its elements according to a compare function.

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.

Functions

gtk_sort_list_model_new ()

GtkSortListModel *
gtk_sort_list_model_new (GListModel *model,
                         GCompareDataFunc sort_func,
                         gpointer user_data,
                         GDestroyNotify user_destroy);

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

Parameters

model

the model to sort

 

sort_func

sort function or NULL to not sort items.

[allow-none]

user_data

user data passed to sort_func .

[closure]

user_destroy

destroy notifier for user_data

 

Returns

a new GtkSortListModel


gtk_sort_list_model_new_for_type ()

GtkSortListModel *
gtk_sort_list_model_new_for_type (GType item_type);

Creates a new empty sort list model set up to return items of type item_type . It is up to the application to set a proper sort function and model to ensure the item type is matched.

Parameters

item_type

the type of the items that will be returned

 

Returns

a new GtkSortListModel


gtk_sort_list_model_set_sort_func ()

void
gtk_sort_list_model_set_sort_func (GtkSortListModel *self,
                                   GCompareDataFunc sort_func,
                                   gpointer user_data,
                                   GDestroyNotify user_destroy);

Sets the function used to sort items. The function will be called for every item and must return an integer less than, equal to, or greater than zero if for two items from the model if the first item is considered to be respectively less than, equal to, or greater than the second.

Parameters

self

a GtkSortListModel

 

sort_func

sort function or NULL to not sort items.

[allow-none]

user_data

user data passed to sort_func .

[closure]

user_destroy

destroy notifier for user_data

 

gtk_sort_list_model_has_sort ()

gboolean
gtk_sort_list_model_has_sort (GtkSortListModel *self);

Checks if a sort function is currently set on self

Parameters

self

a GtkSortListModel

 

Returns

TRUE if a sort function is set


gtk_sort_list_model_set_model ()

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 .

Parameters

self

a GtkSortListModel

 

model

The model to be sorted.

[allow-none]

gtk_sort_list_model_get_model ()

GListModel *
gtk_sort_list_model_get_model (GtkSortListModel *self);

Gets the model currently sorted or NULL if none.

Parameters

self

a GtkSortListModel

 

Returns

The model that gets sorted.

[nullable][transfer none]


gtk_sort_list_model_resort ()

void
gtk_sort_list_model_resort (GtkSortListModel *self);

Causes self to resort all items in the model.

Calling this function is necessary when data used by the sort function has changed.

Parameters

self

a GtkSortListModel

 

Types and Values

GtkSortListModel

typedef struct _GtkSortListModel GtkSortListModel;

Property Details

The “has-sort” property

  “has-sort”                 gboolean

If a sort function is set for this model

Owner: GtkSortListModel

Flags: Read

Default value: FALSE


The “item-type” property

  “item-type”                GType *

The GType for items of this model

Owner: GtkSortListModel

Flags: Read / Write / Construct Only

Allowed values: GObject


The “model” property

  “model”                    GListModel *

The model being sorted

Owner: GtkSortListModel

Flags: Read / Write / Construct Only

See Also

GListModel