Wt::WSignalMapper< T > Class Template Reference

Utility class to connect multiple senders to a single slot by associating additional information with each sender. More...

#include <WSignalMapper>

Inherits Wt::WObject.

Inheritance diagram for Wt::WSignalMapper< T >:

Inheritance graph
[legend]
List of all members.

Public Slots

void map ()
 Slot for connecting signals to be mapped.

Public Member Functions

 WSignalMapper (WObject *parent=0)
 Create a new WSignalMapper.
void setMapping (WObject *sender, const T &data)
 Associate data with a sender.
void mapConnect (SignalBase &signal, const T &data)
 Map a signal.

Public Attributes

Signal< T > mapped
 Signal emitted in response to a signal sent to the map() slot.

Detailed Description

template<typename T>
class Wt::WSignalMapper< T >

Utility class to connect multiple senders to a single slot by associating additional information with each sender.

This class is useful if you have to respond to the same signal of many objects or widgets, but need to identify the sender through some property.

For example, in the WMessageBox implementation we use a signal mapper to react to the several buttons with a single slot, and identifying each button use the WMessageBox::StandardButton enum.

The code looks like this:

  WSignalMapper<StandardButton> buttonMapper_
    = new WSignalMapper<StandardButton>(this);

  buttonMapper_->mapped.connect(SLOT(this, WMessageBox::onButtonClick));

  for (every button B) {
    WPushButton *b = new WPushButton(B.text, buttonContainer_);
    buttonMapper_->mapConnect(b->clicked, B.standardButton);
  }
 

The last statement connects the mapper to the clicked signal of the button, so that any event generated is propagated to the onButtonClick(StandardButton b) method of the WMessageBox with the given B.standardButton argument.

The type T may be any type that has proper copy semantics and a default constructor.


Member Function Documentation

template<typename T>
void Wt::WSignalMapper< T >::map (  )  [slot]

Slot for connecting signals to be mapped.

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.

template<typename T>
void Wt::WSignalMapper< T >::mapConnect ( SignalBase &  signal,
const T &  data 
)

Map a signal.

Connect the given signal with the slot, and associate the data when it is triggered.

template<typename T>
void Wt::WSignalMapper< T >::setMapping ( WObject sender,
const T &  data 
)

Associate data with a sender.

Associate data with a sender, which wel emitted by the mapped signal, when the corresponding sender triggers the map() slot.


Member Data Documentation

template<typename T>
Signal<T> Wt::WSignalMapper< T >::mapped

Signal emitted in response to a signal sent to the map() slot.

The argument propagated is the argument set previously with setMapping().


The documentation for this class was generated from the following file:
Generated on Sun Jul 1 19:37:18 2007 for Wt by doxygen 1.4.7