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

Sorting items. More...

#include <gtkmm/sorter.h>

Inheritance diagram for Gtk::Sorter:
Inheritance graph
[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 Member Functions

 Sorter (Sorter &&src) noexcept
 
Sorteroperator= (Sorter &&src) noexcept
 
 ~Sorter () noexcept override
 
GtkSortergobj ()
 Provides access to the underlying C GObject.
 
const GtkSortergobj () const
 Provides access to the underlying C GObject.
 
GtkSortergobj_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 ()
 

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 ()
 

Related Symbols

(Note that these are not member symbols.)

Glib::RefPtr< Gtk::Sorterwrap (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
changeHow 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
item1First item to compare.
item2Second 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()

static 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
changeHow 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
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.