Wt examples
3.2.2
|
A list of options, separated by '|'. More...
#include <OptionList.h>
Public Member Functions | |
OptionList (WContainerWidget *parent=0) | |
Create an OptionList. | |
void | add (Option *option) |
Add an Option to the list. | |
void | update () |
Updates the stateless implementations after an Option has been hidden or shown. | |
Private Member Functions | |
void | optionVisibilityChanged (Option *opt, bool hidden) |
An option changed visibility: possibly update the separators inbetween. | |
Private Attributes | |
std::vector< Option * > | options_ |
The list of options. | |
Option * | optionNeedReset_ |
The option that needs its stateless code updated. | |
Friends | |
class | Option |
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.
Definition at line 40 of file OptionList.h.
OptionList::OptionList | ( | WContainerWidget * | parent = 0 | ) |
Create an OptionList.
Definition at line 11 of file OptionList.C.
: WContainerWidget(parent), optionNeedReset_(0) { resize(WLength::Auto, WLength(2.5, WLength::FontEx)); }
void OptionList::add | ( | Option * | option | ) |
Add an Option to the list.
Definition at line 18 of file OptionList.C.
{ addWidget(option); option->setOptionList(this); if (!options_.empty()) { options_.back()->addSeparator(); } options_.push_back(option); }
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.
{ /* * Check if it was the last visible option, in that case the second last * visible option loses its separator. */ for (std::size_t i = options_.size() - 1; i > 0; --i) { if (options_[i] == opt) { for (int j = i - 1; j >= 0; --j) { if (!options_[j]->isHidden()) { if (hidden) options_[j]->hideSeparator(); else options_[j]->showSeparator(); break; } } break; } else if (!options_[i]->isHidden()) break; } /* * The Option to the right needs to relearn its stateless * slot code for hide() and show(). */ for (unsigned i = 0; i < options_.size(); ++i) { if (options_[i] == opt) { for (unsigned j = i + 1; j < options_.size(); ++j) { if (!options_[j]->isHidden()) { optionNeedReset_ = options_[j]; break; } } break; } } }
void OptionList::update | ( | ) |
Updates the stateless implementations after an Option has been hidden or shown.
Definition at line 30 of file OptionList.C.
{ if (optionNeedReset_ != 0) optionNeedReset_->resetLearnedSlots(); optionNeedReset_ = 0; }
friend class Option [friend] |
Definition at line 66 of file OptionList.h.
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.