cgv
Loading...
Searching...
No Matches
cgv::gui::control< T > Class Template Reference

#include <control.h>

Inheritance diagram for cgv::gui::control< T >:
cgv::gui::abst_control cgv::gui::abst_view cgv::base::node cgv::base::named cgv::base::base cgv::data::ref_counted cgv::reflect::self_reflection_tag cgv::gui::key_control< T >

Public Types

typedef cgv::signal::bool_signal< control< T > & > value_check_signal_type
 type of the value check signal
 
typedef cgv::signal::signal< control< T > & > value_change_signal_type
 type of the value change signal
 

Public Member Functions

 control (const std::string &_name, T &_value)
 construct abstract element from reference to value
 
 control (const std::string &_name, T *_value)
 construct abstract element from control_provider
 
 control (const std::string &_name, abst_control_provider *_cp, void *user_data)
 this constructor allows contruction from control_provider with user data or if the pointer to the control_provider is null, interpret the pointer to the user data as the value pointer and act as the previous constructor.
 
const T get_value () const
 return a reference to the current value
 
const T & get_new_value () const
 return the new value to the callbacks attached to the check_value signal
 
void set_new_value (const T &nv)
 set a different new value from the callbacks attached to the check_value signal
 
const T & get_old_value () const
 return the old value to the callbacks attached to the change_value signal
 
bool check_and_set_value (const T &nv)
 set new value only if check_value signal succeeds and send value_change signal. Return true if value has been changed.
 
bool controls (const void *ptr) const
 check whether the value represented by this element is pointing to the passed pointer
 
void attach_to_value_change (cgv::signal::functor_base *func)
 attach a functor to the value change signal
 
void attach_to_check_value (cgv::signal::functor_base *bool_func)
 attach a functor to the value change signal
 
- Public Member Functions inherited from cgv::gui::abst_control
 abst_control (const std::string &name)
 construct from name
 
bool shows (const void *ptr) const
 add default implementation passing the query to the controls() method
 
- Public Member Functions inherited from cgv::gui::abst_view
 abst_view (const std::string &name)
 pass name on to node, careful the implementation of this is in the source file control.cxx to avoid name clashes with view.cxx
 
 ~abst_view ()
 ensures detachment of view
 
void attach_to_reference (const void *ptr)
 links all views to a reference into a doubly linked list in order to allow controls of the reference to update all attached views
 
void detach_from_reference ()
 detach view again
 
void update_views ()
 calls the update method of all other attached views
 
- Public Member Functions inherited from cgv::base::node
 node (const std::string &name="")
 construct from name
 
node_ptr get_parent () const
 return the parent node
 
base_ptr get_root () const
 return the root node by traversing parents until no more parent is available
 
void set_parent (node_ptr _parent)
 set a new parent node
 
node_ptr get_node ()
 cast upward to node
 
const_node_ptr get_node_const ()
 cast upward to const node
 
std::string get_type_name () const
 overload to return the type name of this object
 
- Public Member Functions inherited from cgv::base::named
 named (const std::string &name="")
 construct from name
 
const std::string & get_name () const
 return the parent node
 
void set_name (const std::string &_name)
 set a new parent node
 
named_ptr get_named ()
 cast upward to named
 
const_named_ptr get_named_const ()
 cast upward to const named
 
- Public Member Functions inherited from cgv::base::base
virtual std::string get_default_options () const
 overload to provide default options for registration
 
std::string get_name_or_type_name () const
 determine name of instance by checking cgv::base::named interface and in failure fallback to get_type_name()
 
virtual void on_register ()
 overload to handle register events that is sent after the instance has been registered
 
virtual void unregister ()
 overload to handle unregistration of instances
 
virtual bool on_exit_request ()
 overload to handle the appication exit request, return true if exiting is allowed and false otherwise
 
virtual void stream_stats (std::ostream &)
 overload to show the content of this object
 
virtual data::ref_ptr< group, trueget_group ()
 perform downcast to group
 
virtual data::ref_ptr< const named, trueget_named_const () const
 perform downcast to const named
 
virtual data::ref_ptr< const node, trueget_node_const () const
 perform downcast to const node
 
virtual data::ref_ptr< const group, trueget_group_const () const
 perform downcast to const group
 
template<class T >
data::ref_ptr< T, truecast ()
 cast to arbitrary class, but use the casts to named, node and group from the interface
 
template<class T >
data::ref_ptr< const T, truecast_const ()
 const cast to arbitrary class, but use the casts to named, node and group from the interface
 
template<class T >
Tget_interface ()
 use dynamic type cast to check for the given interface
 
template<class T >
const Tget_const_interface () const
 use dynamic type cast to check for the given interface
 
virtual void update ()
 this virtual update allows for example to ask a view to update the viewed value. The default implementation is empty.
 
virtual voidget_user_data () const
 this virtual method allows to pass application specific data for internal purposes
 
virtual bool self_reflect (cgv::reflect::reflection_handler &)
 used for simple self reflection
 
virtual std::string get_property_declarations ()
 return a semicolon separated list of property declarations
 
virtual bool set_void (const std::string &property, const std::string &value_type, const void *value_ptr)
 abstract interface for the setter of a dynamic property.
 
virtual void on_set (void *member_ptr)
 this callback is called when the set_void method has changed a member and can be overloaded in derived class
 
virtual bool get_void (const std::string &property, const std::string &value_type, void *value_ptr)
 abstract interface for the getter of a dynamic property.
 
virtual bool call_void (const std::string &method, const std::vector< std::string > &param_value_types, const std::vector< const void * > &param_value_ptrs, const std::string &result_type="", void *result_value_ptr=0)
 abstract interface to call an action
 
void set (const std::string &property, const char *value)
 specialization of set method to support const char* as strings
 
template<typename T >
void set (const std::string &property, const T &value)
 set a property of the element to the given value and perform standard conversions if necessary.
 
template<typename T >
T get (const std::string &property)
 query a property of the element and perform standard conversions if necessary.
 
void multi_set (const std::string &property_assignments, bool report_error=true)
 set several properties
 
bool is_property (const std::string &property_name, std::string *type_name=0)
 check if the given name specifies a property.
 
voidfind_member_ptr (const std::string &property_name, std::string *type_name=0)
 find a member pointer by name.
 
- Public Member Functions inherited from cgv::data::ref_counted
int get_ref_count () const
 read access to current count
 

Public Attributes

cgv::signal::bool_signal< control< T > & > check_value
 this signal is sent when the user triggered a change of value in order to check whether the new value is valid.
 
cgv::signal::signal< control< T > & > value_change
 this signal is sent after the user triggered a change of value and the check_value succeeded.
 

Protected Member Functions

void set_value (const T &v)
 
const T * get_value_ptr () const
 
- Protected Member Functions inherited from cgv::base::base
virtual ~base ()
 make destructor virtual and not accessible from outside
 
- Protected Member Functions inherited from cgv::data::ref_counted
 ref_counted ()
 constructor initializes the count to 0
 
void set_ref_count (int c) const
 write access is also const to allow ref counted pointers to const instances
 

Additional Inherited Members

- Static Protected Member Functions inherited from cgv::base::base
template<class T >
static data::ref_ptr< T, truecast_dynamic (base *b)
 use dynamic cast for upcast to given class
 
- Protected Attributes inherited from cgv::gui::abst_view
abst_viewnext_in_list
 
abst_viewprev_in_list
 
const void * ptr
 
- Protected Attributes inherited from cgv::base::node
node_ptr parent
 store a pointer to the parent node
 
- Protected Attributes inherited from cgv::base::named
std::string name
 store the name as a string
 

Detailed Description

template<typename T>
class cgv::gui::control< T >

gui independent control of a value that has the type of the template argument. The value can either be specified as a reference or through the control_provider that implements a get and a set method.

Before the control changes a value, it emits the signal check_value to test if the new value is valid. The check_value signal has a boolean return value. All attached callbacks must return true in order for the check to be successful. The attached callbacks can also change the new value to a valid value. The check_value callbacks should use the get_new_value(), get_value() and set_new_value() methods of the control to update the new value and to access the current value that has not been changed yet.

If the validity check is successful, the value is changed to the new value and the value_change signal is emitted. The callbacks attached to this signal can not only query the current value with get_value() but also the old value with get_old_value(). Take care that the get_old_value() cannot be used in the callbacks attached to check_value and the get_new_value() method cannot be used in the callbacks attached to the value_change signal.

Definition at line 81 of file control.h.

Member Typedef Documentation

◆ value_change_signal_type

template<typename T >
typedef cgv::signal::signal<control<T>&> cgv::gui::control< T >::value_change_signal_type

type of the value change signal

Definition at line 103 of file control.h.

◆ value_check_signal_type

template<typename T >
typedef cgv::signal::bool_signal<control<T>&> cgv::gui::control< T >::value_check_signal_type

type of the value check signal

Definition at line 101 of file control.h.

Constructor & Destructor Documentation

◆ control() [1/3]

template<typename T >
cgv::gui::control< T >::control ( const std::string &  _name,
T &  _value 
)
inline

construct abstract element from reference to value

Definition at line 105 of file control.h.

◆ control() [2/3]

template<typename T >
cgv::gui::control< T >::control ( const std::string &  _name,
T *  _value 
)
inline

construct abstract element from control_provider

Definition at line 109 of file control.h.

◆ control() [3/3]

template<typename T >
cgv::gui::control< T >::control ( const std::string &  _name,
abst_control_provider _cp,
void *  user_data 
)
inline

this constructor allows contruction from control_provider with user data or if the pointer to the control_provider is null, interpret the pointer to the user data as the value pointer and act as the previous constructor.

Definition at line 118 of file control.h.

References cgv::gui::control_provider< T >::get_value().

Member Function Documentation

◆ attach_to_check_value()

template<typename T >
void cgv::gui::control< T >::attach_to_check_value ( cgv::signal::functor_base *  bool_func)
inlinevirtual

attach a functor to the value change signal

Implements cgv::gui::abst_control.

Definition at line 164 of file control.h.

◆ attach_to_value_change()

template<typename T >
void cgv::gui::control< T >::attach_to_value_change ( cgv::signal::functor_base *  func)
inlinevirtual

attach a functor to the value change signal

Implements cgv::gui::abst_control.

Definition at line 160 of file control.h.

◆ check_and_set_value()

template<typename T >
bool cgv::gui::control< T >::check_and_set_value ( const T &  nv)
inline

set new value only if check_value signal succeeds and send value_change signal. Return true if value has been changed.

Definition at line 146 of file control.h.

◆ controls()

template<typename T >
bool cgv::gui::control< T >::controls ( const void *  ptr) const
inlinevirtual

check whether the value represented by this element is pointing to the passed pointer

Implements cgv::gui::abst_control.

Definition at line 158 of file control.h.

References cgv::gui::control_provider< T >::controls().

◆ get_new_value()

template<typename T >
const T & cgv::gui::control< T >::get_new_value ( ) const
inline

return the new value to the callbacks attached to the check_value signal

Definition at line 140 of file control.h.

◆ get_old_value()

template<typename T >
const T & cgv::gui::control< T >::get_old_value ( ) const
inline

return the old value to the callbacks attached to the change_value signal

Definition at line 144 of file control.h.

◆ get_value()

template<typename T >
const T cgv::gui::control< T >::get_value ( ) const
inline

return a reference to the current value

Definition at line 138 of file control.h.

References cgv::gui::control_provider< T >::get_value().

◆ get_value_ptr()

template<typename T >
const T * cgv::gui::control< T >::get_value_ptr ( ) const
inlineprotected

Definition at line 98 of file control.h.

◆ set_new_value()

template<typename T >
void cgv::gui::control< T >::set_new_value ( const T &  nv)
inline

set a different new value from the callbacks attached to the check_value signal

Definition at line 142 of file control.h.

◆ set_value()

template<typename T >
void cgv::gui::control< T >::set_value ( const T &  v)
inlineprotected

Definition at line 89 of file control.h.

Member Data Documentation

◆ check_value

template<typename T >
cgv::signal::bool_signal<control<T>&> cgv::gui::control< T >::check_value

this signal is sent when the user triggered a change of value in order to check whether the new value is valid.

Use get_new_value() and set_new_value() to get and correct the new value. Return true if the new value is ok or could be corrected, false otherwise.

Definition at line 133 of file control.h.

◆ value_change

template<typename T >
cgv::signal::signal<control<T>&> cgv::gui::control< T >::value_change

this signal is sent after the user triggered a change of value and the check_value succeeded.

You can access the old value with get_old_value() method.

Definition at line 136 of file control.h.


The documentation for this class was generated from the following file: