glibmm 2.66.5
|
Bind two object properties. More...
#include <glibmm/binding.h>
Public Types | |
using | SlotTransform = sigc::slot< bool, const GValue *, GValue * > |
A slot to be called to transform values in a binding created by bind_property_value(). More... | |
template<typename T_from , typename T_to > | |
using | SlotTypedTransform = sigc::slot< bool, const T_from &, T_to & > |
A slot to be called to transform values in a binding created by bind_property(). More... | |
Public Types inherited from Glib::Object | |
using | DestroyNotify = void(*)(gpointer data) |
Public Member Functions | |
Binding (Binding && src) noexcept | |
Binding & | operator= (Binding && src) noexcept |
~Binding () noexcept override | |
GBinding * | gobj () |
Provides access to the underlying C GObject. More... | |
const GBinding * | gobj () const |
Provides access to the underlying C GObject. More... | |
GBinding * | gobj_copy () |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More... | |
Glib::RefPtr< Glib::ObjectBase > | get_source () |
Retrieves the Glib::ObjectBase instance used as the source of the binding. More... | |
Glib::RefPtr< const Glib::ObjectBase > | get_source () const |
Retrieves the Glib::ObjectBase instance used as the source of the binding. More... | |
Glib::ustring | get_source_property () const |
Retrieves the name of the property of Binding::property_source() used as the source of the binding. More... | |
Glib::RefPtr< Glib::ObjectBase > | get_target () |
Retrieves the Glib::ObjectBase instance used as the target of the binding. More... | |
Glib::RefPtr< const Glib::ObjectBase > | get_target () const |
Retrieves the Glib::ObjectBase instance used as the target of the binding. More... | |
Glib::ustring | get_target_property () const |
Retrieves the name of the property of Binding::property_target() used as the target of the binding. More... | |
BindingFlags | get_flags () const |
Retrieves the flags passed when constructing the Binding. More... | |
void | unbind () |
Explicitly releases the binding between the source and the target property expressed by this Binding instance. More... | |
Glib::PropertyProxy_ReadOnly< Glib::BindingFlags > | property_flags () const |
Flags to be used to control the Binding. More... | |
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Glib::ObjectBase > > | property_source () const |
The Object that should be used as the source of the binding. More... | |
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_source_property () const |
The name of the property of Binding::property_source() that should be used as the source of the binding. More... | |
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Glib::ObjectBase > > | property_target () const |
The Object that should be used as the target of the binding. More... | |
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_target_property () const |
The name of the property of Binding::property_target() that should be used as the target of the binding. More... | |
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 (const Quark & key, void *data, DestroyNotify notify) |
void | remove_data (const QueryQuark & quark) |
void * | steal_data (const QueryQuark & quark) |
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) |
You probably want to use a specific property_*() accessor method instead. More... | |
void | get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const |
You probably want to use a specific property_*() accessor method instead. More... | |
template<class PropertyType > | |
void | set_property (const Glib::ustring & property_name, const PropertyType & value) |
You probably want to use a specific property_*() accessor method instead. More... | |
template<class PropertyType > | |
void | get_property (const Glib::ustring & property_name, PropertyType & value) const |
You probably want to use a specific property_*() accessor method instead. More... | |
void | connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void > & slot) |
You can use the signal_changed() signal of the property proxy instead. More... | |
void | connect_property_changed (const Glib::ustring & property_name, sigc::slot< void > && slot) |
You can use the signal_changed() signal of the property proxy instead. More... | |
sigc::connection | connect_property_changed_with_return (const Glib::ustring & property_name, const sigc::slot< void > & slot) |
You can use the signal_changed() signal of the property proxy instead. More... | |
sigc::connection | connect_property_changed_with_return (const Glib::ustring & property_name, sigc::slot< void > && slot) |
You can use the signal_changed() signal of the property proxy instead. More... | |
void | freeze_notify () |
Increases the freeze count on object. More... | |
void | thaw_notify () |
Reverts the effect of a previous call to freeze_notify(). More... | |
virtual void | reference () const |
Increment the reference count for this object. More... | |
virtual void | unreference () const |
Decrement the reference count for this object. More... | |
GObject * | gobj () |
Provides access to the underlying C GObject. More... | |
const GObject * | gobj () const |
Provides access to the underlying C GObject. More... | |
GObject * | gobj_copy () const |
Give a ref-ed copy to someone. Use for direct struct access. 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< Binding > | bind_property_value (const PropertyProxy_Base & source_property, const PropertyProxy_Base & target_property, BindingFlags flags=BINDING_DEFAULT, const SlotTransform & transform_to=SlotTransform(), const SlotTransform & transform_from=SlotTransform()) |
Creates a binding between source_property and target_property, allowing you to set the transformation functions to be used by the binding. More... | |
static Glib::RefPtr< Binding > | bind_property (const PropertyProxy_Base & source_property, const PropertyProxy_Base & target_property, BindingFlags flags=BINDING_DEFAULT) |
Creates a binding between source_property and target_property. More... | |
template<typename T_source , typename T_target , typename T_functor_to > | |
static Glib::RefPtr< Binding > | bind_property (const PropertyProxy< T_source > & source_property, const PropertyProxy< T_target > & target_property, BindingFlags flags, const T_functor_to & transform_to) |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding. More... | |
template<typename T_source , typename T_target , typename T_functor_to > | |
static Glib::RefPtr< Binding > | bind_property (const PropertyProxy< T_source > & source_property, const PropertyProxy_WriteOnly< T_target > & target_property, BindingFlags flags, const T_functor_to & transform_to) |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding. More... | |
template<typename T_source , typename T_target , typename T_functor_to > | |
static Glib::RefPtr< Binding > | bind_property (const PropertyProxy_ReadOnly< T_source > & source_property, const PropertyProxy< T_target > & target_property, BindingFlags flags, const T_functor_to & transform_to) |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding. More... | |
template<typename T_source , typename T_target , typename T_functor_to > | |
static Glib::RefPtr< Binding > | bind_property (const PropertyProxy_ReadOnly< T_source > & source_property, const PropertyProxy_WriteOnly< T_target > & target_property, BindingFlags flags, const T_functor_to & transform_to) |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding. More... | |
template<typename T_source , typename T_target , typename T_functor_to , typename T_functor_from > | |
static Glib::RefPtr< Binding > | bind_property (const PropertyProxy< T_source > & source_property, const PropertyProxy< T_target > & target_property, BindingFlags flags, const T_functor_to & transform_to, const T_functor_from & transform_from) |
Creates a binding between source_property and target_property, allowing you to set the transformation functions to be used by the binding. More... | |
Related Functions | |
(Note that these are not member functions.) | |
const Glib::RefPtr< Glib::Binding > & | manage (const Glib::RefPtr< Glib::Binding > & binding) |
Sets a Glib::Binding as having its lifetime managed by the lifetimes of its source and target objects, rather than requiring a Glib::RefPtr to be kept. More... | |
Glib::RefPtr< Glib::Binding > | wrap (GBinding * object, bool take_copy=false) |
A Glib::wrap() method for this object. More... | |
Related Functions inherited from Glib::Object | |
Glib::RefPtr< Glib::Object > | wrap (GObject * object, bool take_copy=false) |
Additional Inherited Members | |
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 () | |
This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More... | |
ObjectBase (const char * custom_type_name) | |
A derived constructor always overrides this choice. More... | |
ObjectBase (const std::type_info & custom_type_info) | |
This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More... | |
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) |
Bind two object properties.
Glib::Binding is the representation of a binding between a property on a Glib::ObjectBase instance (or source) and another property on another Glib::ObjectBase instance (or target). Whenever the source property changes, the same value is applied to the target property; for instance, the following binding:
will cause property_b() of object2 to be updated every time the value of property_a() of object1 changes.
It is possible to create a bidirectional binding between two properties of two Glib::ObjectBase instances, so that if either property changes, the other is updated as well, for instance:
will keep the two properties in sync.
It is also possible to set a custom transformation function (in both directions, in case of a bidirectional binding) to apply a custom transformation from the source value to the target value before applying it; for instance, the following binding:
will keep property_value() of the two adjustments in sync; the celsius_to_fahrenheit() function will be called whenever property_value() of adjustment1 changes and will transform the current value of the property before applying it to property_value() of adjustment2.
Vice versa, the fahrenheit_to_celsius() function will be called whenever property_value() of adjustment2 changes, and will transform the current value of the property before applying it to property_value() of adjustment1.
Note that Glib::Binding does not resolve cycles by itself; a cycle like
might lead to an infinite loop. The loop, in this particular case, can be avoided if the objects emit the GObject::notify signal only if the value has effectively been changed. A binding is implemented using the GObject::notify signal, so it is susceptible to all the various ways of blocking a signal emission, like Glib::SignalProxyNormal::emission_stop() or g_signal_handler_block().
The binding between properties is broken, and its resources freed, when the Glib::Binding loses its last Glib::RefPtr (by default), the source or target object is deleted, or unbind() is called. If a Glib::RefPtr to the Glib::Binding remains after the binding is broken another way, get_source() and get_target() return an empty Glib::RefPtr. So, by default, you must keep a Glib::RefPtr to the Glib::Binding for as long as you want it to bind, but doing that does not guarantee the source/target are still alive or bound.
If it is not convenient to maintain a Glib::RefPtr to keep a Glib::Binding active, you can pass the Glib::Binding to Glib::manage() to specify that it should have its lifetime managed by the source/target objects and unbind() only. In that case, it will stay active as long as the source and target exist and unbind() is not called, even if no Glib::RefPtr to it is kept.
using Glib::Binding::SlotTransform = sigc::slot<bool, const GValue*, GValue*> |
A slot to be called to transform values in a binding created by bind_property_value().
For instance:
true
if the transformation was successful, and false
otherwise. using Glib::Binding::SlotTypedTransform = sigc::slot<bool, const T_from&, T_to&> |
A slot to be called to transform values in a binding created by bind_property().
For instance:
true
if the transformation was successful, and false
otherwise.
|
noexcept |
|
overridenoexcept |
|
inlinestatic |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding.
source_property | The source property to bind. |
target_property | The target property to bind. |
flags | Flags to pass to Binding. |
transform_to | The transformation function from the source to the target, or an empty slot to use the default. |
nullptr
in case of error.T_source | Type of the source property. Must be a type that can be stored in a Glib::Value<T_source> object. |
T_target | Type of the target property. Must be a type that can be stored in a Glib::Value<T_target> object. |
T_functor_to | Type of functor that translates from the source to the target. Must be convertible to SlotTypedTransform<T_source, T_target>. |
|
inlinestatic |
Creates a binding between source_property and target_property, allowing you to set the transformation functions to be used by the binding.
source_property | The source property to bind. |
target_property | The target property to bind. |
flags | Flags to pass to Binding. |
transform_to | The transformation function from the source to the target, or an empty slot to use the default. |
transform_from | The transformation function from the target to the source, or an empty slot to use the default. |
nullptr
in case of error.T_source | Type of the source property. Must be a type that can be stored in a Glib::Value<T_source> object. |
T_target | Type of the target property. Must be a type that can be stored in a Glib::Value<T_target> object. |
T_functor_to | Type of functor that translates from the source to the target. Must be convertible to SlotTypedTransform<T_source, T_target>. |
T_functor_from | Type of functor that translates from the target to the source. Must be convertible to SlotTypedTransform<T_target, T_source>. |
|
inlinestatic |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding.
source_property | The source property to bind. |
target_property | The target property to bind. |
flags | Flags to pass to Binding. |
transform_to | The transformation function from the source to the target, or an empty slot to use the default. |
nullptr
in case of error.T_source | Type of the source property. Must be a type that can be stored in a Glib::Value<T_source> object. |
T_target | Type of the target property. Must be a type that can be stored in a Glib::Value<T_target> object. |
T_functor_to | Type of functor that translates from the source to the target. Must be convertible to SlotTypedTransform<T_source, T_target>. |
|
inlinestatic |
Creates a binding between source_property and target_property.
source_property | The source property to bind. |
target_property | The target property to bind. |
flags | Flags to pass to Binding. |
nullptr
in case of error.
|
inlinestatic |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding.
source_property | The source property to bind. |
target_property | The target property to bind. |
flags | Flags to pass to Binding. |
transform_to | The transformation function from the source to the target, or an empty slot to use the default. |
nullptr
in case of error.T_source | Type of the source property. Must be a type that can be stored in a Glib::Value<T_source> object. |
T_target | Type of the target property. Must be a type that can be stored in a Glib::Value<T_target> object. |
T_functor_to | Type of functor that translates from the source to the target. Must be convertible to SlotTypedTransform<T_source, T_target>. |
|
inlinestatic |
Creates a binding between source_property and target_property, allowing you to set a transformation function to be used by the binding.
source_property | The source property to bind. |
target_property | The target property to bind. |
flags | Flags to pass to Binding. |
transform_to | The transformation function from the source to the target, or an empty slot to use the default. |
nullptr
in case of error.T_source | Type of the source property. Must be a type that can be stored in a Glib::Value<T_source> object. |
T_target | Type of the target property. Must be a type that can be stored in a Glib::Value<T_target> object. |
T_functor_to | Type of functor that translates from the source to the target. Must be convertible to SlotTypedTransform<T_source, T_target>. |
|
static |
Creates a binding between source_property and target_property, allowing you to set the transformation functions to be used by the binding.
If flags contains Glib::BINDING_BIDIRECTIONAL then the binding will be mutual: if target_property changes then the source_property will be updated as well. The transform_from function is only used in case of bidirectional bindings, otherwise it will be ignored.
A Glib::ObjectBase instance can have multiple bindings.
If you supply transformation functions, it is usually easier to use one of the bind_property() overloads, to avoid the use of GValue in the transformation functions.
source_property | The source property to bind. |
target_property | The target property to bind. |
flags | Flags to pass to Binding. |
transform_to | The transformation function from the source to the target, or an empty slot to use the default. |
transform_from | The transformation function from the target to the source, or an empty slot to use the default. |
nullptr
in case of error.BindingFlags Glib::Binding::get_flags | ( | ) | const |
Glib::RefPtr< Glib::ObjectBase > Glib::Binding::get_source | ( | ) |
Retrieves the Glib::ObjectBase instance used as the source of the binding.
A Glib::Binding can outlive the source Glib::ObjectBase as the binding does not hold a strong reference to the source. If the source is destroyed before the binding then this function will return an empty Glib::RefPtr.
Glib::RefPtr< const Glib::ObjectBase > Glib::Binding::get_source | ( | ) | const |
Retrieves the Glib::ObjectBase instance used as the source of the binding.
A Glib::Binding can outlive the source Glib::ObjectBase as the binding does not hold a strong reference to the source. If the source is destroyed before the binding then this function will return an empty Glib::RefPtr.
Glib::ustring Glib::Binding::get_source_property | ( | ) | const |
Retrieves the name of the property of Binding::property_source() used as the source of the binding.
Glib::RefPtr< Glib::ObjectBase > Glib::Binding::get_target | ( | ) |
Retrieves the Glib::ObjectBase instance used as the target of the binding.
A Glib::Binding can outlive the target Glib::ObjectBase as the binding does not hold a strong reference to the target. If the target is destroyed before the binding then this function will return an empty Glib::RefPtr.
Glib::RefPtr< const Glib::ObjectBase > Glib::Binding::get_target | ( | ) | const |
Retrieves the Glib::ObjectBase instance used as the target of the binding.
A Glib::Binding can outlive the target Glib::ObjectBase as the binding does not hold a strong reference to the target. If the target is destroyed before the binding then this function will return an empty Glib::RefPtr.
Glib::ustring Glib::Binding::get_target_property | ( | ) | const |
Retrieves the name of the property of Binding::property_target() used as the target of the binding.
|
static |
Get the GType for this class, for use with the underlying GObject type system.
|
inline |
Provides access to the underlying C GObject.
|
inline |
Provides access to the underlying C GObject.
GBinding * Glib::Binding::gobj_copy | ( | ) |
Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
Glib::PropertyProxy_ReadOnly< Glib::BindingFlags > Glib::Binding::property_flags | ( | ) | const |
Flags to be used to control the Binding.
Default value: BINDING_DEFAULT
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Glib::ObjectBase > > Glib::Binding::property_source | ( | ) | const |
The Object that should be used as the source of the binding.
Glib::PropertyProxy_ReadOnly< Glib::ustring > Glib::Binding::property_source_property | ( | ) | const |
The name of the property of Binding::property_source() that should be used as the source of the binding.
This should be in [canonical form][canonical-parameter-names] to get the best performance.
Default value: ""
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Glib::ObjectBase > > Glib::Binding::property_target | ( | ) | const |
The Object that should be used as the target of the binding.
Glib::PropertyProxy_ReadOnly< Glib::ustring > Glib::Binding::property_target_property | ( | ) | const |
The name of the property of Binding::property_target() that should be used as the target of the binding.
This should be in [canonical form][canonical-parameter-names] to get the best performance.
Default value: ""
void Glib::Binding::unbind | ( | ) |
Explicitly releases the binding between the source and the target property expressed by this Binding instance.
The binding is also released if either the source object or the target object is deleted, or this Binding instance loses its last reference, i.e. there is no more Glib::RefPtr that holds a pointer to it.
|
related |
Sets a Glib::Binding as having its lifetime managed by the lifetimes of its source and target objects, rather than requiring a Glib::RefPtr to be kept.
See the class description of Glib::Binding for full information on the lifetimes of bindings.
For instance:
binding | The Glib::Binding to set as managed, or an empty Glib::RefPtr. |
|
related |
A Glib::wrap() method for this object.
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. |