Wt::WSignalMapper< T, A1 > Class Template Reference
[Signal/slot system]

A utility class to connect multiple senders to a single slot. More...

#include <Wt/WSignalMapper>

Inheritance diagram for Wt::WSignalMapper< T, A1 >:

Inheritance graph
[legend]

List of all members.

Public Slots

void map ()
 Slot to which to connect the source signal.
void map1 (A1 a)
 Slot to which to connect the source signal, passing the argument to the receiver.

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 without arguments.
template<typename S>
void mapConnect1 (S &signal, const T &data)
 Map a signal with one argument.

Public Attributes

Signal< T, A1 > mapped
 Signal emitted in response to a signal sent to map() or map1().


Detailed Description

template<typename T, typename A1 = NoClass>
class Wt::WSignalMapper< T, A1 >

A utility class to connect multiple senders to a single slot.

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 corresponding Wt::StandardButton value.

The code looks like this:

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

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

  for (int i = 0; i < 9; ++i) {
    if (buttons_ & order_[i]) {
      WPushButton *b = new WPushButton(buttonText_[i],
                                       buttonContainer_);
      buttonMapper_->mapConnect(b->clicked, order_[i]);
    }
  }

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 order_[i] argument.

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().


Member Function Documentation

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

Associate data with a sender.

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

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

Map a signal without arguments.

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

template<typename T, typename A1>
template<typename S>
void Wt::WSignalMapper< T, A1 >::mapConnect1 ( S &  signal,
const T &  data 
) [inline]

Map 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.

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

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.

template<typename T, typename A1>
void Wt::WSignalMapper< T, A1 >::map1 ( A1  a  )  [inline, slot]

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.


Member Data Documentation

template<typename T, typename A1 = NoClass>
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.


Generated on Fri Jul 25 17:56:38 2008 for Wt by doxygen 1.5.3