glibmm 2.80.0
Public Types | Public Member Functions | List of all members
Glib::Property< T > Class Template Reference

A Glib::Object property. More...

#include <glibmm/property.h>

Inheritance diagram for Glib::Property< T >:
Inheritance graph
[legend]

Public Types

using PropertyType = T
 
using ValueType = Glib::Value< T >
 

Public Member Functions

 Property (Glib::Object &object, const Glib::ustring & name)
 Constructs a property of the object with the specified name.
 
 Property (Glib::Object &object, const Glib::ustring & name, const PropertyType &default_value)
 Constructs a property of the object with the specified name and default_value.
 
 Property (Glib::Object &object, const Glib::ustring & name, const Glib::ustring &nick, const Glib::ustring &blurb, Glib::ParamFlags flags)
 Constructs a property of the object with the specified name, nick, blurb and flags.
 
 Property (Glib::Object &object, const Glib::ustring & name, const PropertyType &default_value, const Glib::ustring &nick, const Glib::ustring &blurb, Glib::ParamFlags flags)
 Constructs a property of the object with the specified name, default_value, nick, blurb and flags.
 
void set_value (const PropertyType &data)
 Sets the value of the property to data.
 
PropertyType get_value () const
 Returns the value of the property.
 
Property< T > & operator= (const PropertyType &data)
 Sets the value of the property to data.
 
 operator PropertyType () const
 Returns the value of the property.
 
Glib::PropertyProxy< T > get_proxy ()
 Returns a proxy object that can be used to read or write this property.
 
Glib::PropertyProxy_ReadOnly< T > get_proxy () const
 Returns a proxy object that can be used to read this property.
 
- Public Member Functions inherited from Glib::PropertyBase
 PropertyBase (const PropertyBase &)=delete
 
PropertyBaseoperator= (const PropertyBase &)=delete
 
Glib::ustring get_name () const
 Returns the name of the property.
 
Glib::ustring get_nick () const
 Returns the nickname of the property.
 
Glib::ustring get_blurb () const
 Returns the short description of the property.
 
void notify ()
 Notifies the object containing the property that the property has changed.
 

Additional Inherited Members

- Protected Member Functions inherited from Glib::PropertyBase
 PropertyBase (Glib::Object &object, GType value_type)
 This constructs a property of type value_type for the object.
 
 ~PropertyBase () noexcept
 
bool lookup_property (const Glib::ustring & name)
 Checks if the property has already been installed.
 
void install_property (GParamSpec *param_spec)
 Installs the property specified by the given param_spec.
 
const charget_name_internal () const
 Returns the name of the property.
 
- Protected Attributes inherited from Glib::PropertyBase
Glib::Objectobject_
 
Glib::ValueBase value_
 
GParamSpecparam_spec_
 

Detailed Description

template<class T>
class Glib::Property< T >

A Glib::Object property.

This class wraps a GObject property, providing a C++ API to the GObject property system, for use with classes derived from Glib::Object or Glib::Interface.

A property is a value associated with each instance of a type and some class data for each property:

This Property class currently supports the name, nick name, description, default value and flags. The minimum and maximum bounds are set to the full range of the value. Because of internal implementation, flags shouldn't be set to values: Glib::ParamFlags::STATIC_NAME, Glib::ParamFlags::STATIC_NICK, Glib::ParamFlags::STATIC_BLURB, Glib::ParamFlags::CONSTRUCT and Glib::ParamFlags::CONSTRUCT_ONLY.

The class information must be installed into the GObject system once per property, but this is handled automatically.

Each property belongs to an object, inheriting from Glib::Object. A reference to the object must be passed to the constructor of the property.

Each instance of a Glib::Object-derived type must construct the same properties (same type, same name) in the same order. One way to achieve this is to declare all properties as direct data members of the type.

You may register new properties for your class (actually for the underlying GType) simply by adding a Property instance as a class member. However, your constructor must call the Glib::ObjectBase constructor with a new GType name, in order to register a new GType.

Example:

class MyCellRenderer : public Gtk::CellRenderer
{
public:
MyCellRenderer()
:
Glib::ObjectBase (typeid(MyCellRenderer)),
Gtk::CellRenderer(),
property_mybool (*this, "mybool", true),
property_myint_ (*this, "myint", 42)
{}
virtual ~MyCellRenderer() {}
// Glib::Property<> can be public,
Glib::Property<bool> property_mybool;
// or private, and combined with Glib::PropertyProxy<>.
Glib::PropertyProxy<int> property_myint() { return property_myint_.get_proxy(); }
Glib::PropertyProxy_ReadOnly<int> property_myint() const { return property_myint_.get_proxy(); }
private:
Glib::Property<int> property_myint_;
};
Glib::ObjectBase is a common base class for Objects and Interfaces.
Definition objectbase.h:56
See PropertyProxy().
Definition propertyproxy.h:104
A PropertyProxy can be used to get and set the value of an object's property.
Definition propertyproxy.h:43
A Glib::Object property.
Definition property.h:204
Definition containerhandle_shared.h:36
Glib::Property and Gtk::Builder
The new GType is registered, and the properties installed in the GType, when the first instance of the class is created. When the underlying GObject-derived instance is created before the wrapping Glib::Object-derived instance, you may have to first create a dummy instance just to register the GType. See the description of Gtk::Builder for instructions how to combine Property with Gtk::Builder.

Member Typedef Documentation

◆ PropertyType

template <class T >
using Glib::Property< T >::PropertyType = T

◆ ValueType

template <class T >
using Glib::Property< T >::ValueType = Glib::Value<T>

Constructor & Destructor Documentation

◆ Property() [1/4]

template <class T >
Glib::Property< T >::Property ( Glib::Object object,
const Glib::ustring name 
)

Constructs a property of the object with the specified name.

For each instance of the object, the same property must be constructed with the same name.

◆ Property() [2/4]

template <class T >
Glib::Property< T >::Property ( Glib::Object object,
const Glib::ustring name,
const PropertyType default_value 
)

Constructs a property of the object with the specified name and default_value.

For each instance of the object, the same property must be constructed with the same name.

◆ Property() [3/4]

template <class T >
Glib::Property< T >::Property ( Glib::Object object,
const Glib::ustring name,
const Glib::ustring nick,
const Glib::ustring blurb,
Glib::ParamFlags  flags 
)

Constructs a property of the object with the specified name, nick, blurb and flags.

For each instance of the object, the same property must be constructed with the same name.

◆ Property() [4/4]

template <class T >
Glib::Property< T >::Property ( Glib::Object object,
const Glib::ustring name,
const PropertyType default_value,
const Glib::ustring nick,
const Glib::ustring blurb,
Glib::ParamFlags  flags 
)

Constructs a property of the object with the specified name, default_value, nick, blurb and flags.

For each instance of the object, the same property must be constructed with the same name.

Member Function Documentation

◆ get_proxy() [1/2]

template <class T >
Glib::PropertyProxy< T > Glib::Property< T >::get_proxy ( )
inline

Returns a proxy object that can be used to read or write this property.

◆ get_proxy() [2/2]

template <class T >
Glib::PropertyProxy_ReadOnly< T > Glib::Property< T >::get_proxy ( ) const
inline

Returns a proxy object that can be used to read this property.

◆ get_value()

template <class T >
PropertyType Glib::Property< T >::get_value ( ) const
inline

Returns the value of the property.

◆ operator PropertyType()

template <class T >
Glib::Property< T >::operator PropertyType ( ) const
inline

Returns the value of the property.

◆ operator=()

template <class T >
Property< T > & Glib::Property< T >::operator= ( const PropertyType data)
inline

Sets the value of the property to data.

The object containing the property will be notified about the change.

◆ set_value()

template <class T >
void Glib::Property< T >::set_value ( const PropertyType data)
inline

Sets the value of the property to data.

The object containing the property will be notified about the change.