Wt
3.3.8
|
A utility class to connect multiple senders to a single slot. More...
#include <Wt/WSignalMapper>
Public Member Functions | |
WSignalMapper (WObject *parent=0) | |
Creates a new WSignalMapper. | |
void | setMapping (WObject *sender, const T &data) |
Associates data with a sender. More... | |
Wt::Signals::connection | mapConnect (SignalBase &signal, const T &data) |
Maps a signal without arguments. More... | |
template<typename S > | |
Wt::Signals::connection | mapConnect1 (S &signal, const T &data) |
Maps a signal with one argument. More... | |
Signal< T, A1 > & | mapped () |
Signal emitted in response to a signal sent to map() or map1(). More... | |
void | map () |
Slot to which to connect the source signal. More... | |
void | map1 (A1 a) |
Slot to which to connect the source signal, passing the argument to the receiver. More... | |
void | removeMapping (WObject *sender) |
Removes the mapping of an object. More... | |
Public Member Functions inherited from Wt::WObject | |
WObject (WObject *parent=0) | |
Create a WObject with a given parent object. More... | |
virtual | ~WObject () |
Destructor. More... | |
virtual const std::string | id () const |
Returns the (unique) identifier for this object. More... | |
virtual void | setObjectName (const std::string &name) |
Sets an object name. More... | |
virtual std::string | objectName () const |
Returns the object name. More... | |
void | resetLearnedSlots () |
Resets learned stateless slot implementations. More... | |
template<class T > | |
void | resetLearnedSlot (void(T::*method)()) |
Resets a learned stateless slot implementation. More... | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)()) |
Declares a slot to be stateless and learn client-side behaviour on first invocation. More... | |
template<class T > | |
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
Declares a slot to be stateless and learn client-side behaviour in advance. More... | |
void | isNotStateless () |
Marks the current function as not stateless. More... | |
template<class T > | |
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
Provides a JavaScript implementation for a method. More... | |
void | addChild (WObject *child) |
Adds a child object. More... | |
virtual void | removeChild (WObject *child) |
Removes a child object. More... | |
const std::vector< WObject * > & | children () const |
Returns the children. | |
WObject * | parent () const |
Returns the parent object. | |
Additional Inherited Members | |
Public Types inherited from Wt::WObject | |
typedef void(WObject::* | Method) () |
Typedef for a WObject method without arguments. | |
Protected Member Functions inherited from Wt::WObject | |
virtual WStatelessSlot * | getStateless (Method method) |
On-demand stateless slot implementation. More... | |
Static Protected Member Functions inherited from Wt::WObject | |
static WObject * | sender () |
Returns the sender of the current slot call. More... | |
A utility class to connect multiple senders to a single slot.
This class is useful if you would like to respond to signals of many objects or widgets within a single slot, but need to identify the particular sender through some property.
Usage example:
The type T may be any type that has proper copy semantics and a default constructor. The mapper may pass one extra argument (type A1) from the original signal to the mapped() signal. In that case, you must connect the original signal to the map1() slot, or use mapConnect1().
The mapper uses signal.sender() to attribute ownership of a signal to a sender.
You may want to consider to boost::bind() (or std::bind()) instead, which is simpler and achieves the same in a more direct way:
void Wt::WSignalMapper< T, A1 >::map | ( | ) |
Slot to which to connect the source signal.
When a signal triggers the slot, the sender is identified and used to find corresponding data set with setMapping(), which is then use to propagate further in the mapped() signal.
void Wt::WSignalMapper< T, A1 >::map1 | ( | A1 | a | ) |
Slot to which to connect the source signal, passing the argument to the receiver.
When a signal triggers the slot, the sender is identified and used to find corresponding data set with setMapping(), which is then use to propagate further in the mapped() signal. The additional argument a
is passed as the second argument to the mapped() signal.
Wt::Signals::connection Wt::WSignalMapper< T, A1 >::mapConnect | ( | SignalBase & | signal, |
const T & | data | ||
) |
Maps a signal without arguments.
Connect the given signal with the slot, and associate the data when it is triggered.
is equivalent to:
Wt::Signals::connection Wt::WSignalMapper< T, A1 >::mapConnect1 | ( | S & | signal, |
const T & | data | ||
) |
Maps a signal with one argument.
Connect the given signal with the slot, and associate the data when it is triggered. The signal argument will be passed to the mapped() signal.
is equivalent to:
Signal<T, A1>& Wt::WSignalMapper< T, A1 >::mapped | ( | ) |
Signal emitted in response to a signal sent to map() or map1().
The first argument propagated is the data that is associated with the specific sender, set in setMapping() or mapConnect(). The second argument is an argument passed from the originating signal.
void Wt::WSignalMapper< T, A1 >::removeMapping | ( | WObject * | sender | ) |
Removes the mapping of an object.
This method does not disconnect any signals; that is the responsability of the user of WSignalMapper. If no mapping of for an object exits, the mapper will ignore the signal, and not emit the mapped signal.
void Wt::WSignalMapper< T, A1 >::setMapping | ( | WObject * | sender, |
const T & | data | ||
) |