Wt examples
3.3.12
build
witty-XWY8sd
witty-3.3.12+dfsg
examples
composer
OptionList.C
Go to the documentation of this file.
1
// This may look like C code, but it's really -*- C++ -*-
2
/*
3
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
4
*
5
* See the LICENSE file for terms of use.
6
*/
7
8
#include "
OptionList.h
"
9
#include "
Option.h
"
10
11
OptionList::OptionList
(WContainerWidget *parent)
12
: WContainerWidget(parent),
13
optionNeedReset_
(0)
14
{
15
resize(WLength::Auto, WLength(2.5, WLength::FontEx));
16
}
17
18
void
OptionList::add
(
Option
*option)
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
}
29
30
void
OptionList::update
()
31
{
32
if
(
optionNeedReset_
!= 0)
33
optionNeedReset_
->resetLearnedSlots();
34
35
optionNeedReset_
= 0;
36
}
37
38
void
OptionList::optionVisibilityChanged
(
Option
*opt,
bool
hidden)
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()) {
69
optionNeedReset_
=
options_
[j];
70
break
;
71
}
72
}
73
74
break
;
75
}
76
}
77
}
78
Option.h
OptionList::optionVisibilityChanged
void optionVisibilityChanged(Option *opt, bool hidden)
An option changed visibility: possibly update the separators inbetween.
Definition:
OptionList.C:38
OptionList::optionNeedReset_
Option * optionNeedReset_
The option that needs its stateless code updated.
Definition:
OptionList.h:61
OptionList::options_
std::vector< Option * > options_
The list of options.
Definition:
OptionList.h:58
OptionList::OptionList
OptionList(WContainerWidget *parent=0)
Create an OptionList.
Definition:
OptionList.C:11
Option
A clickable option.
Definition:
Option.h:31
Option::setOptionList
void setOptionList(OptionList *l)
Definition:
Option.C:28
OptionList::add
void add(Option *option)
Add an Option to the list.
Definition:
OptionList.C:18
OptionList::update
void update()
Updates the stateless implementations after an Option has been hidden or shown.
Definition:
OptionList.C:30
OptionList.h
Generated on Fri Apr 24 2020 for
the C++ Web Toolkit (Wt)
by
1.8.17