Unity Scopes API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OptionSelectorFilter.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Pawel Stolowski <pawel.stolowski@canonical.com>
17  */
18 
19 #ifndef UNITY_SCOPES_OPTIONSELECTOR_H
20 #define UNITY_SCOPES_OPTIONSELECTOR_H
21 
22 #include <unity/scopes/FilterBase.h>
23 #include <unity/scopes/FilterOption.h>
24 #include <unity/scopes/Variant.h>
25 #include <string>
26 #include <list>
27 #include <set>
28 
29 namespace unity
30 {
31 
32 namespace scopes
33 {
34 class FilterState;
35 
36 namespace internal
37 {
38 class OptionSelectorFilterImpl;
39 class FilterBaseImpl;
40 }
41 
47 {
48 public:
50  UNITY_DEFINES_PTRS(OptionSelectorFilter);
52 
60  static OptionSelectorFilter::SPtr create(std::string const& id, std::string const& label, bool multi_select = false);
61 
66  std::string label() const;
67 
72  bool multi_select() const;
73 
78  FilterOption::SCPtr add_option(std::string const& id, std::string const& label);
79 
84  std::list<FilterOption::SCPtr> options() const;
85 
90  std::set<FilterOption::SCPtr> active_options(FilterState const& filter_state) const;
91 
98  void update_state(FilterState& filter_state, FilterOption::SCPtr option, bool active) const;
99 
106  static void update_state(FilterState& filter_state, std::string const& filter_id, std::string const& option_id, bool value);
107 
108 private:
109  OptionSelectorFilter(std::string const& id, std::string const& label, bool multi_select = false);
110  OptionSelectorFilter(VariantMap const& var);
111  internal::OptionSelectorFilterImpl* fwd() const;
112  friend class internal::FilterBaseImpl;
113 };
114 
115 } // namespace scopes
116 
117 } // namespace unity
118 
119 #endif
A selection filter that displays a list of choices and allows one or more of them to be selected...
Definition: OptionSelectorFilter.h:46
std::string label() const
Get the label of this filter.
Definition: OptionSelectorFilter.cpp:43
void update_state(FilterState &filter_state, FilterOption::SCPtr option, bool active) const
Marks given FilterOption of this filter instance as active (or not active) in a FilterState object...
Definition: OptionSelectorFilter.cpp:68
Base class for all implementations of filters.
Definition: FilterBase.h:47
bool multi_select() const
Check if this filter supports multiple options to be selected.
Definition: OptionSelectorFilter.cpp:48
std::list< FilterOption::SCPtr > options() const
Get all options of this filter, in the order they were added.
Definition: OptionSelectorFilter.cpp:58
FilterOption::SCPtr add_option(std::string const &id, std::string const &label)
Add a new option to this filter.
Definition: OptionSelectorFilter.cpp:53
std::map< std::string, Variant > VariantMap
A dictionary of (string, Variant) pairs.
Definition: Variant.h:39
Captures state of multiple filters.
Definition: FilterState.h:47
std::set< FilterOption::SCPtr > active_options(FilterState const &filter_state) const
Get active options from an instance of FilterState for this filter.
Definition: OptionSelectorFilter.cpp:63
static OptionSelectorFilter::SPtr create(std::string const &id, std::string const &label, bool multi_select=false)
Creates an OpionSelectorFilter.
Definition: OptionSelectorFilter.cpp:38