gtkmm  4.8.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::SortListModel Class Reference

A list model that sorts its items. More...

#include <gtkmm/sortlistmodel.h>

Inherits Glib::Object, and Gio::ListModel.

Public Member Functions

 SortListModel (SortListModel && src) noexcept
 
SortListModeloperator= (SortListModel && src) noexcept
 
 ~SortListModel () noexcept override
 
GtkSortListModel * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkSortListModel * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkSortListModel * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
void set_sorter (const Glib::RefPtr< Sorter > & sorter)
 Sets a new sorter on self. More...
 
Glib::RefPtr< Sorterget_sorter ()
 Gets the sorter that is used to sort self. More...
 
Glib::RefPtr< const Sorterget_sorter () const
 Gets the sorter that is used to sort self. More...
 
void set_model (const Glib::RefPtr< Gio::ListModel > & model)
 Sets the model to be sorted. More...
 
Glib::RefPtr< Gio::ListModel > get_model ()
 Gets the model currently sorted or nullptr if none. More...
 
Glib::RefPtr< const Gio::ListModel > get_model () const
 Gets the model currently sorted or nullptr if none. More...
 
void set_incremental (bool incremental=true)
 Sets the sort model to do an incremental sort. More...
 
bool get_incremental () const
 Returns whether incremental sorting is enabled. More...
 
guint get_pending () const
 Estimates progress of an ongoing sorting operation. More...
 
Glib::PropertyProxy< bool > property_incremental ()
 If the model should sort items incrementally. More...
 
Glib::PropertyProxy_ReadOnly< bool > property_incremental () const
 If the model should sort items incrementally. More...
 
Glib::PropertyProxy_ReadOnly< GType > property_item_type () const
 The type of items. More...
 
Glib::PropertyProxy< Glib::RefPtr< Gio::ListModel > > property_model ()
 The model being sorted. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gio::ListModel > > property_model () const
 The model being sorted. More...
 
Glib::PropertyProxy_ReadOnly< unsigned int > property_n_items () const
 The number of items. More...
 
Glib::PropertyProxy_ReadOnly< guint > property_pending () const
 Estimate of unsorted items remaining. More...
 
Glib::PropertyProxy< Glib::RefPtr< Sorter > > property_sorter ()
 The sorter for this model. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Sorter > > property_sorter () const
 The sorter for this model. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< SortListModelcreate (const Glib::RefPtr< Gio::ListModel > & model, const Glib::RefPtr< Sorter > & sorter)
 

Protected Member Functions

 SortListModel (const Glib::RefPtr< Gio::ListModel > & model, const Glib::RefPtr< Sorter > & sorter)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::SortListModelwrap (GtkSortListModel * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

A list model that sorts its items.

Gtk::SortListModel is a list model that takes a list model and sorts its elements according to a Gtk::Sorter.

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

Gtk::SortListModel 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 Gtk::SortListModel, it is strongly recommended that you write your own sorting list model.

See also
Gio::ListModel, Gtk::Sorter
Since gtkmm 3.98:

Constructor & Destructor Documentation

◆ SortListModel() [1/2]

Gtk::SortListModel::SortListModel ( SortListModel &&  src)
noexcept

◆ ~SortListModel()

Gtk::SortListModel::~SortListModel ( )
overridenoexcept

◆ SortListModel() [2/2]

Gtk::SortListModel::SortListModel ( const Glib::RefPtr< Gio::ListModel > &  model,
const Glib::RefPtr< Sorter > &  sorter 
)
explicitprotected

Member Function Documentation

◆ create()

static Glib::RefPtr<SortListModel> Gtk::SortListModel::create ( const Glib::RefPtr< Gio::ListModel > &  model,
const Glib::RefPtr< Sorter > &  sorter 
)
static

◆ get_incremental()

bool Gtk::SortListModel::get_incremental ( ) const

Returns whether incremental sorting is enabled.

See set_incremental().

Returns
true if incremental sorting is enabled.

◆ get_model() [1/2]

Glib::RefPtr<Gio::ListModel> Gtk::SortListModel::get_model ( )

Gets the model currently sorted or nullptr if none.

Returns
The model that gets sorted.

◆ get_model() [2/2]

Glib::RefPtr<const Gio::ListModel> Gtk::SortListModel::get_model ( ) const

Gets the model currently sorted or nullptr if none.

Returns
The model that gets sorted.

◆ get_pending()

guint Gtk::SortListModel::get_pending ( ) const

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 example ellipted]

If no sort operation is ongoing - in particular when property_incremental() is false - this function returns 0.

Returns
A progress estimate of remaining items to sort.

◆ get_sorter() [1/2]

Glib::RefPtr<Sorter> Gtk::SortListModel::get_sorter ( )

Gets the sorter that is used to sort self.

Returns
The sorter of #self.

◆ get_sorter() [2/2]

Glib::RefPtr<const Sorter> Gtk::SortListModel::get_sorter ( ) const

Gets the sorter that is used to sort self.

Returns
The sorter of #self.

◆ get_type()

static GType Gtk::SortListModel::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GtkSortListModel* Gtk::SortListModel::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkSortListModel* Gtk::SortListModel::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkSortListModel* Gtk::SortListModel::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ operator=()

SortListModel& Gtk::SortListModel::operator= ( SortListModel &&  src)
noexcept

◆ property_incremental() [1/2]

Glib::PropertyProxy< bool > Gtk::SortListModel::property_incremental ( )

If the model should sort items incrementally.

Default value: false

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_incremental() [2/2]

Glib::PropertyProxy_ReadOnly< bool > Gtk::SortListModel::property_incremental ( ) const

If the model should sort items incrementally.

Default value: false

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_item_type()

Glib::PropertyProxy_ReadOnly< GType > Gtk::SortListModel::property_item_type ( ) const

The type of items.

See Gio::ListModel::get_item_type().

Since gtkmm 4.8:
Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_model() [1/2]

Glib::PropertyProxy< Glib::RefPtr<Gio::ListModel> > Gtk::SortListModel::property_model ( )

The model being sorted.

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_model() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Gio::ListModel> > Gtk::SortListModel::property_model ( ) const

The model being sorted.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_n_items()

Glib::PropertyProxy_ReadOnly< unsigned int > Gtk::SortListModel::property_n_items ( ) const

The number of items.

See Gio::ListModel::get_n_items().

Since gtkmm 4.8:

Default value: 0

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_pending()

Glib::PropertyProxy_ReadOnly< guint > Gtk::SortListModel::property_pending ( ) const

Estimate of unsorted items remaining.

Default value: 0

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_sorter() [1/2]

Glib::PropertyProxy< Glib::RefPtr<Sorter> > Gtk::SortListModel::property_sorter ( )

The sorter for this model.

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_sorter() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Sorter> > Gtk::SortListModel::property_sorter ( ) const

The sorter for this model.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ set_incremental()

void Gtk::SortListModel::set_incremental ( bool  incremental = true)

Sets the sort model to do an incremental sort.

When incremental sorting is enabled, the Gtk::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 get_pending() for progress information about an ongoing incremental sorting operation.

Parameters
incrementaltrue to sort incrementally.

◆ set_model()

void Gtk::SortListModel::set_model ( const Glib::RefPtr< Gio::ListModel > &  model)

Sets the model to be sorted.

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

Parameters
modelThe model to be sorted.

◆ set_sorter()

void Gtk::SortListModel::set_sorter ( const Glib::RefPtr< Sorter > &  sorter)

Sets a new sorter on self.

Parameters
sorterThe Gtk::Sorter to sort model with.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gtk::SortListModel > wrap ( GtkSortListModel *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.