gtkmm: Gtk::Sorter Class Reference

gtkmm 4.23.0

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gtk::Sorter Class Reference
ListView Classes

Sorting items. More...

`#include <gtkmm/sorter.h>`

Inheritance diagram for Gtk::Sorter:
[legend]

## Public Types
enum class | Order { Order::PARTIAL , Order::NONE , Order::TOTAL }
| Describes the type of order that a Gtk::Sorter may produce. More...
enum class | Change { Change::DIFFERENT , Change::INVERTED , Change::LESS_STRICT , Change::MORE_STRICT }
| Describes changes in a sorter in more detail and allows users to optimize resorting. More...
Public Types inherited from Glib::Object
typedef void(*)(gpointer data | DestroyNotify)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify
Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify | func_destroy_notify

## Public Member Functions
| Sorter (Sorter && src) noexcept
Sorter & | operator= (Sorter && src) noexcept
| ~Sorter () noexcept override
GtkSorter * | gobj ()
| Provides access to the underlying C GObject.
const GtkSorter * | gobj () const
| Provides access to the underlying C GObject.
GtkSorter * | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
Ordering | compare (gpointer item1, gpointer item2)
| Compares two given items according to the sort order implemented by the sorter.
Order | get_order () const
| Gets the order that self conforms to.
void | changed (Change change)
| Notifies all users of the sorter that it has changed.
Glib::SignalProxy< void(Change)> | signal_changed ()
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data_with_c_callback (const Quark &key, void *data, GDestroyNotify notify)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src) noexcept
| ~trackable ()
void | add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src) noexcept
void | remove_destroy_notify_callback (notifiable *data) const

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system.

## Protected Member Functions
| Sorter ()
virtual Ordering | compare_vfunc (gpointer item1, gpointer item2)
virtual Order | get_order_vfunc ()
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Gtk::Sorter > | wrap (GtkSorter * object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

Sorting items.

Gtk::Sorter is the way to describe sorting criteria. Its primary user is Gtk::SortListModel.

The model will use a sorter to determine the order in which its items should appear by calling compare() for pairs of items.

Sorters may change their sorting behavior through their lifetime. In that case, they will emit the signal_changed() signal to notify that the sort order is no longer valid and should be updated by calling compare() again.

GTK provides various pre-made sorter implementations for common sorting operations. Gtk::ColumnView has built-in support for sorting lists via the Gtk::ColumnViewColumn::property_sorter(), where the user can change the sorting by clicking on list headers.

Of course, in particular for large lists, it is also possible to subclass Gtk::Sorter and provide one's own sorter.

See also
  Gtk::SortListModel

Since gtkmm 3.98

## Constructor & Destructor Documentation

## ◆ Sorter() [1/2]

Gtk::Sorter::Sorter | ( | Sorter && | src | ) |
| noexcept

## ◆ ~Sorter()

Gtk::Sorter::~Sorter | ( |  | ) |
| overridenoexcept

## ◆ Sorter() [2/2]

Gtk::Sorter::Sorter | ( |  | ) |
| protected

## Member Function Documentation

## ◆ changed()

void Gtk::Sorter::changed | ( | Change | change | ) |

Notifies all users of the sorter that it has changed.

This emits the signal_changed() signal. Users of the sorter should then update the sort order via compare().

Depending on the change parameter, it may be possible to update the sort order without a full resorting. Refer to the Gtk::SorterChange documentation for details.

This function is intended for implementers of Gtk::Sorter subclasses and should not be called from other functions.

Parameters

  change | How the sorter changed.

## ◆ compare()

Ordering Gtk::Sorter::compare | ( | gpointer | item1,
|  | gpointer | item2 )

Compares two given items according to the sort order implemented by the sorter.

Sorters implement a partial order:

- It is reflexive, ie a = a
- It is antisymmetric, ie if a < b and b < a, then a = b
- It is transitive, ie given any 3 items with a ≤ b and b ≤ c, then a ≤ c

The sorter may signal it conforms to additional constraints via the return value of get_order().

Parameters

  item1 | First item to compare.
  item2 | Second item to compare.

Returns
  Gtk::Ordering::EQUAL if item1 == item2, Gtk::Ordering::SMALLER if item1 < item2, Gtk::Ordering::LARGER if item1 > item2.

## ◆ compare_vfunc()

virtual Ordering Gtk::Sorter::compare_vfunc | ( | gpointer | item1,
|  | gpointer | item2 )
| protectedvirtual

## ◆ get_order()

Order Gtk::Sorter::get_order | ( |  | ) | const

Gets the order that self conforms to.

See Gtk::SorterOrder for details of the possible return values.

This function is intended to allow optimizations.

Returns
  The order.

## ◆ get_order_vfunc()

virtual Order Gtk::Sorter::get_order_vfunc | ( |  | ) |
| protectedvirtual

## ◆ get_type()

GType Gtk::Sorter::get_type | ( |  | ) |
| static

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

## ◆ gobj() [1/2]

GtkSorter * Gtk::Sorter::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GtkSorter * Gtk::Sorter::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GtkSorter * Gtk::Sorter::gobj_copy | ( |  | ) |

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

## ◆ operator=()

Sorter & Gtk::Sorter::operator= | ( | Sorter && | src | ) |
| noexcept

## ◆ signal_changed()

Glib::SignalProxy< void(Change)> Gtk::Sorter::signal_changed | ( |  | ) |

Slot Prototype:
  void on_my_changed(Change change)

Flags: Run Last

Emitted whenever the sorter changed.

Users of the sorter should then update the sort order again via Gtk::Sorter::compare().

Gtk::SortListModel handles this signal automatically.

Depending on the change parameter, it may be possible to update the sort order without a full resorting. Refer to the Gtk::SorterChange documentation for details.

Parameters

  change | How the sorter changed.

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Gtk::Sorter > wrap | ( | GtkSorter * | object,
|  | bool | take_copy = false )
| related

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

Parameters

  object | The C instance.
  take_copy | False 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.