Wt: Wt::WButtonGroup Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions
Wt::WButtonGroup Class Reference

A class for grouping radio buttons logically together. More...

`#include <Wt/WButtonGroup>`

Inheritance diagram for Wt::WButtonGroup:
[legend]

List of all members.

## Public Member Functions
| WButtonGroup (WObject *parent=0)
| Creates a new empty button group.
| ~WButtonGroup ()
| Destructor.
void | addButton (WRadioButton *button, int id=-1)
| Adds a radio button to the group.
void | addButton (Ext::RadioButton *button, int id=-1)
| Adds a radio button to the group.
void | removeButton (WRadioButton *button)
| Removes a radio button from the group.
void | removeButton (Ext::RadioButton *button)
| Removes a radio button from the group.
WRadioButton * | button (int id) const
| Returns the button for the given id.
int | id (WRadioButton *button) const
| Returns the id for the given button.
virtual const std::string | id () const
| Returns the (unique) identifier for this object.
std::vector< WRadioButton * > | buttons () const
| Returns the buttons in this group.
int | count () const
| Returns the number of radiobuttons in this group.
int | checkedId () const
| Returns the id of the checked button.
void | setCheckedButton (WRadioButton *button)
| Sets the currently checked radiobutton.
WRadioButton * | checkedButton () const
| Returns the checked radiobutton.
void | setSelectedButtonIndex (int idx)
| Sets the currently checked radiobutton.
int | selectedButtonIndex () const
| Returns the index of the checked radiobutton.
Signal< WRadioButton * > & | checkedChanged ()
| Signal emitted when a button was checked.

## Detailed Description

A class for grouping radio buttons logically together.

A button group manages a set of radio buttons, making them exclusive of each other.

It is not a widget, but instead provides only a logical grouping. Radio buttons are aware of the group in which they have been added, see WRadioButton::group(). When a button is deleted, it is automatically removed its button group.

It allows you to associate id's with each button, which you may use to identify a particular button. The special value of -1 is reserved to indicate no button.

Usage example:

     enum Vote { Republican = 1, Democrate = 2, NoVote = 10 };

     // use a group box as widget container for 3 radio buttons, with a title
     Wt::WGroupBox *container = new Wt::WGroupBox("USA elections vote");

     // use a button group to logically group the 3 options
     Wt::WButtonGroup *group = new Wt::WButtonGroup(this);

     Wt::WRadioButton *button;
     button = new Wt::WRadioButton("I voted Republican", container);
     new Wt::WBreak(container);
     group->addButton(button, Republican);

     button = new Wt::WRadioButton("I voted Democrat", container);
     new Wt::WBreak(container);
     group->addButton(button, Democrate);

     button = new Wt::WRadioButton("I didn't vote", container);
     new Wt::WBreak(container);
     group->addButton(button, NoVote);

     group->setCheckedButton(group->button(NoVote));

See also:
  WRadioButton, Ext::RadioButton

## Constructor & Destructor Documentation

Wt::WButtonGroup::~WButtonGroup | ( |  | ) |

Destructor.

This does not delete the radio buttons, but simply removes them from the group.

## Member Function Documentation

void Wt::WButtonGroup::addButton | ( | WRadioButton * | button,
|  | int | id = `-1`
| ) |  |

Adds a radio button to the group.

You can assign an id to the button. If `id` is -1, then a unique id will be generated.

See also:
  removeButton(WRadioButton *)

void Wt::WButtonGroup::addButton | ( | Ext::RadioButton * | button,
|  | int | id = `-1`
| ) |  |

Adds a radio button to the group.

You can assign an id to the button. If `id` is -1, then a unique id will be generated.

See also:
  removeButton(Ext::RadioButton *)

WRadioButton * Wt::WButtonGroup::button | ( | int | id | ) | const

Returns the button for the given id.

See also:
  id(), addButton()

WRadioButton * Wt::WButtonGroup::checkedButton | ( |  | ) | const

Returns the checked radiobutton.

If there is no radiobutton currently checked this function returns `0`.

See also:
  setCheckedButton(), selectedButtonIndex()

Signal< WRadioButton * > & Wt::WButtonGroup::checkedChanged | ( |  | ) |

Signal emitted when a button was checked.

The argument passed is the new checkedButton().

int Wt::WButtonGroup::checkedId | ( |  | ) | const

Returns the id of the checked button.

Returns the id of the currently checked button, or -1 if no button is currently checked.

int Wt::WButtonGroup::id | ( | WRadioButton * | button | ) | const

Returns the id for the given button.

See also:
  button(), addButton()

virtual const std::string Wt::WButtonGroup::id | ( |  | ) | const`[virtual]`

Returns the (unique) identifier for this object.

For a WWidget, this corresponds to the id of the DOM element that represents the widget. This is not entirely unique, since a composite widget shares the same id as its implementation.

By default, the id is auto-generated, unless a custom id is set for a widget using WWidget::setId(). The auto-generated id is created by concatenating objectName() with a unique number.

See also:
  WWidget::jsRef()

Reimplemented from Wt::WObject.

void Wt::WButtonGroup::removeButton | ( | WRadioButton * | button | ) |

Removes a radio button from the group.

See also:
  addButton(WRadioButton *, int)

void Wt::WButtonGroup::removeButton | ( | Ext::RadioButton * | button | ) |

Removes a radio button from the group.

See also:
  addButton(Ext::RadioButton *, int)

int Wt::WButtonGroup::selectedButtonIndex | ( |  | ) | const

Returns the index of the checked radiobutton.

The index reflects the order in which the buttons have been added to the button group. Use checkedId() if you want to know the id of the button that is currently checked. If there is no radiobutton selected this function returns -1.

See also:
  checkedId()

void Wt::WButtonGroup::setCheckedButton | ( | WRadioButton * | button | ) |

Sets the currently checked radiobutton.

The button `button` of this group is checked. A value of `0` will uncheck all radiobuttons.

Initially, no button is checked.

See also:
  checkedId()

void Wt::WButtonGroup::setSelectedButtonIndex | ( | int | idx | ) |

Sets the currently checked radiobutton.

Sets the `idx'th` radiobutton checked. A value of -1 will uncheck all radiobuttons.

Initially, no button is checked.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator