Wt examples  3.3.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
OptionList Class Reference

A list of options, separated by '|'. More...

#include <OptionList.h>

Inheritance diagram for OptionList:
Inheritance graph
[legend]

Public Member Functions

 OptionList (WContainerWidget *parent=0)
 Create an OptionList. More...
 
void add (Option *option)
 Add an Option to the list. More...
 
void update ()
 Updates the stateless implementations after an Option has been hidden or shown. More...
 

Private Member Functions

void optionVisibilityChanged (Option *opt, bool hidden)
 An option changed visibility: possibly update the separators inbetween. More...
 

Private Attributes

std::vector< Option * > options_
 The list of options. More...
 
OptionoptionNeedReset_
 The option that needs its stateless code updated. More...
 

Friends

class Option
 

Additional Inherited Members

- Protected Member Functions inherited from Wt::WWidget
virtual void enableAjax ()=0
 
virtual void propagateSetEnabled (bool enabled)=0
 
virtual void render (WFlags< RenderFlag > flags)
 

Detailed Description

A list of options, separated by '|'.

This widget is part of the Wt composer example.

An OptionList displays a list of Option widgets, which are separated by a '|' separator.

For example, Foo | Bar | Huu

When Options are hidden, the separators are adjusted so that there is no separator after the last visible option. However, this requires a call of update() each time an option is hidden or shown. This is because the removing of separators is optimized in stateless implementations, and thus in client-side JavaScript code. Since the behaviour is not entirely stateless, the update() method resets stateless implementations if necessary.

See Also
OptionList

Definition at line 40 of file OptionList.h.

Constructor & Destructor Documentation

OptionList::OptionList ( WContainerWidget parent = 0)

Create an OptionList.

Definition at line 11 of file OptionList.C.

12  : WContainerWidget(parent),
14 {
15  resize(WLength::Auto, WLength(2.5, WLength::FontEx));
16 }

Member Function Documentation

void OptionList::add ( Option option)

Add an Option to the list.

Definition at line 18 of file OptionList.C.

19 {
20  addWidget(option);
21  option->setOptionList(this);
22 
23  if (!options_.empty()) {
24  options_.back()->addSeparator();
25  }
26 
27  options_.push_back(option);
28 }
void OptionList::optionVisibilityChanged ( Option opt,
bool  hidden 
)
private

An option changed visibility: possibly update the separators inbetween.

Definition at line 38 of file OptionList.C.

39 {
40  /*
41  * Check if it was the last visible option, in that case the second last
42  * visible option loses its separator.
43  */
44  for (std::size_t i = options_.size() - 1; i > 0; --i) {
45  if (options_[i] == opt) {
46  for (int j = i - 1; j >= 0; --j) {
47  if (!options_[j]->isHidden()) {
48  if (hidden)
49  options_[j]->hideSeparator();
50  else
51  options_[j]->showSeparator();
52  break;
53  }
54  }
55  break;
56  } else
57  if (!options_[i]->isHidden())
58  break;
59  }
60 
61  /*
62  * The Option to the right needs to relearn its stateless
63  * slot code for hide() and show().
64  */
65  for (unsigned i = 0; i < options_.size(); ++i) {
66  if (options_[i] == opt) {
67  for (unsigned j = i + 1; j < options_.size(); ++j) {
68  if (!options_[j]->isHidden()) {
70  break;
71  }
72  }
73 
74  break;
75  }
76  }
77 }
void OptionList::update ( )

Updates the stateless implementations after an Option has been hidden or shown.

Definition at line 30 of file OptionList.C.

31 {
32  if (optionNeedReset_ != 0)
33  optionNeedReset_->resetLearnedSlots();
34 
35  optionNeedReset_ = 0;
36 }

Friends And Related Function Documentation

friend class Option
friend

Definition at line 66 of file OptionList.h.

Member Data Documentation

Option* OptionList::optionNeedReset_
private

The option that needs its stateless code updated.

Definition at line 61 of file OptionList.h.

std::vector<Option *> OptionList::options_
private

The list of options.

Definition at line 58 of file OptionList.h.


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

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1