gtkmm: Gtk::Sorter Class Reference

Sorting items. More...

#include <gtkmm/sorter.h>

Inheritance diagram for Gtk::Sorter:

Public Types

enum  Order {

  Order::PARTIAL,

  Order::NONE,

  Order::TOTAL

}
 Describes the type of order that a Gtk::Sorter may describe. More...

 
enum  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
 
Sorteroperator= (Sorter&& src) noexcept
 
 ~Sorter () noexcept override
 
GtkSorter* gobj ()
 Provides access to the underlying C GObject. More...

 
const GtkSorter* gobj () const
 Provides access to the underlying C GObject. More...

 
GtkSorter* gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...

 
Ordering compare (gpointer item1, gpointer item2)
 Compares two given items according to the sort order implemented by the sorter. More...

 
Order get_order () const
 Gets the order that self conforms to. More...

 
void changed (Change change)
 Emits the Gtk::Sorter::signal_changed() signal to notify all users of the sorter that it has changed. More...

 
Glib::SignalProxy< void(Change)> signal_changed ()
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&src) noexcept
 
Objectoperator= (Object &&src) noexcept
 
void * get_data (const QueryQuark &key)
 
void set_data (const Quark &key, void *data)
 
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::Objectwrap (GObject *object, bool take_copy=false)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
 
ObjectBaseoperator= (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 ()
 
trackableoperator= (const trackable &src)
 
trackableoperator= (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. More...

 

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
 
ObjectBaseoperator= (ObjectBase &&src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject *castitem)
 
void initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
 

Related Functions

(Note that these are not member functions.)

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

 

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

Gtk::Sorter::Sorter ( Sorter&&  src)
noexcept
Gtk::Sorter::~Sorter ( )
overridenoexcept
Gtk::Sorter::Sorter ( )
protected

Member Function Documentation

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

Emits the Gtk::Sorter::signal_changed() signal to notify all users of the sorter that it has changed.

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 implementors of Gtk::Sorter subclasses and should not be called from other functions.

Parameters
changeHow the sorter changed.
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.
virtual Ordering Gtk::Sorter::compare_vfunc ( gpointer  item1,
gpointer  item2 
)
protectedvirtual
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.
virtual Order Gtk::Sorter::get_order_vfunc ( )
protectedvirtual
static GType Gtk::Sorter::get_type ( )
static

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

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

Provides access to the underlying C GObject.

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

Provides access to the underlying C GObject.

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.

Sorter& Gtk::Sorter::operator= ( Sorter&&  src)
noexcept
Glib::SignalProxy<void(Change)> Gtk::Sorter::signal_changed ( )
Slot Prototype:
void on_my_changed(Change change)

Flags: Run Last

This signal is 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 Function Documentation

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.