Wt examples: OptionList Class Reference

Wt examples 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
OptionList Class Reference
Composer example

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

`#include <OptionList.h>`

Inheritance diagram for OptionList:
[legend]

## Public Member Functions
| OptionList ()
| Create an OptionList.
void | add (std::unique_ptr< 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

## 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::OptionList | ( |  | ) |

Create an OptionList.

Definition at line 11 of file OptionList.C.

12 : WContainerWidget(),
13 optionNeedReset_(0)
14{
15 resize(WLength::Auto, WLength(2.5, LengthUnit::FontEx));
16}
OptionList::optionNeedReset_
Option * optionNeedReset_
The option that needs its stateless code updated.
Definition OptionList.h:61

## Member Function Documentation

## ◆ add()

void OptionList::add | ( | std::unique_ptr< Option > | option | ) |

Add an Option to the list.

Definition at line 18 of file OptionList.C.

19{
20 Option *optionPtr = option.get();
21 addWidget(std::move(option));
22 optionPtr->setOptionList(this);
23
24 if (!options_.empty()) {
25 options_.back()->addSeparator();
26 }
27
28 options_.push_back(optionPtr);
29}
OptionList::options_
std::vector< Option * > options_
The list of options.
Definition OptionList.h:58
Option
A clickable option.
Definition Option.h:32
Option::setOptionList
void setOptionList(OptionList *l)
Definition Option.C:28

## ◆ optionVisibilityChanged()

void OptionList::optionVisibilityChanged | ( | Option * | opt,
|  | bool | hidden )
| private

An option changed visibility: possibly update the separators inbetween.

Definition at line 39 of file OptionList.C.

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

## ◆ update()

void OptionList::update | ( |  | ) |

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

Definition at line 31 of file OptionList.C.

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

## Friends And Related Symbol Documentation

## ◆ Option

friend class Option
| friend

Definition at line 66 of file OptionList.h.

## Member Data Documentation

## ◆ optionNeedReset_

Option* OptionList::optionNeedReset_
| private

The option that needs its stateless code updated.

Definition at line 61 of file OptionList.h.

## ◆ options_

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:

- composer/OptionList.h
- composer/OptionList.C