W3cubDocs

/GTK 4.0

GtkFilterListModel

GtkFilterListModel — A list model that filters its items

Properties

GtkFilter * filter Read / Write
gboolean incremental Read / Write
GListModel * model Read / Write
guint pending Read

Types and Values

Object Hierarchy

    GObject
    ╰── GtkFilterListModel

Implemented Interfaces

GtkFilterListModel implements GListModel.

Includes

#include <gtk/gtk.h>

Description

GtkFilterListModel is a list model that filters a given other listmodel. It hides some elements from the other model according to criteria given by a GtkFilter.

The model can be set up to do incremental searching, so that filtering long lists doesn't block the UI. See gtk_filter_list_model_set_incremental() for details.

Functions

gtk_filter_list_model_new ()

GtkFilterListModel *
gtk_filter_list_model_new (GListModel *model,
                           GtkFilter *filter);

Creates a new GtkFilterListModel that will filter model using the given filter .

Parameters

model

the model to sort, or NULL.

[allow-none][transfer full]

filter

filter or NULL to not filter items.

[allow-none][transfer full]

Returns

a new GtkFilterListModel

gtk_filter_list_model_set_model ()

void
gtk_filter_list_model_set_model (GtkFilterListModel *self,
                                 GListModel *model);

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.

Parameters

self

a GtkFilterListModel

model

The model to be filtered.

[allow-none]

gtk_filter_list_model_get_model ()

GListModel *
gtk_filter_list_model_get_model (GtkFilterListModel *self);

Gets the model currently filtered or NULL if none.

Parameters

Returns

The model that gets filtered.

[nullable][transfer none]

gtk_filter_list_model_set_filter ()

void
gtk_filter_list_model_set_filter (GtkFilterListModel *self,
                                  GtkFilter *filter);

Sets the filter used to filter items.

Parameters

self

a GtkFilterListModel

filter

filter to use or NULL to not filter items.

[allow-none][transfer none]

gtk_filter_list_model_get_filter ()

GtkFilter *
gtk_filter_list_model_get_filter (GtkFilterListModel *self);

Gets the GtkFilter currently set on self .

Parameters

Returns

The filter currently in use or NULL if the list isn't filtered.

[nullable][transfer none]

gtk_filter_list_model_set_incremental ()

void
gtk_filter_list_model_set_incremental (GtkFilterListModel *self,
                                       gboolean incremental);

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 gtk_filter_list_model_get_pending() for progress information about an ongoing incremental filtering operation.

Parameters

self

a GtkFilterListModel

incremental

TRUE to enable incremental filtering

gtk_filter_list_model_get_incremental ()

gboolean
gtk_filter_list_model_get_incremental (GtkFilterListModel *self);

Returns whether incremental filtering was enabled via gtk_filter_list_model_set_incremental().

Parameters

Returns

TRUE if incremental filtering is enabled

gtk_filter_list_model_get_pending ()

guint
gtk_filter_list_model_get_pending (GtkFilterListModel *self);

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:

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 “incremental” is FALSE - this function returns 0.

Parameters

Returns

The number of items not yet filtered

Types and Values

GtkFilterListModel

typedef struct _GtkFilterListModel GtkFilterListModel;

Property Details

The “filter” property

  “filter”                   GtkFilter *

The filter for this model

Owner: GtkFilterListModel

Flags: Read / Write

The “incremental” property

  “incremental”              gboolean

If the model should filter items incrementally

Owner: GtkFilterListModel

Flags: Read / Write

Default value: FALSE

The “model” property

  “model”                    GListModel *

The model being filtered

Owner: GtkFilterListModel

Flags: Read / Write

The “pending” property

  “pending”                  guint

Number of items not yet filtered

Owner: GtkFilterListModel

Flags: Read

Default value: 0

See Also

GListModel, GtkFilter

© 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/GtkFilterListModel.html