Unity Scopes API
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 #pragma once
20 
21 #include <unity/scopes/FilterBase.h>
22 #include <unity/scopes/FilterOption.h>
23 #include <unity/scopes/Variant.h>
24 #include <string>
25 #include <list>
26 #include <set>
27 
28 namespace unity
29 {
30 
31 namespace scopes
32 {
33 class FilterState;
34 
35 namespace internal
36 {
37 class OptionSelectorFilterImpl;
38 class FilterBaseImpl;
39 }
40 
46 {
47 public:
49  UNITY_DEFINES_PTRS(OptionSelectorFilter);
51 
59  static OptionSelectorFilter::UPtr create(std::string const& id, std::string const& label, bool multi_select = false);
60 
65  std::string label() const;
66 
71  bool multi_select() const;
72 
77  FilterOption::SCPtr add_option(std::string const& id, std::string const& label);
78 
83  std::list<FilterOption::SCPtr> options() const;
84 
90  bool has_active_option(FilterState const& filter_state) const;
91 
96  std::set<FilterOption::SCPtr> active_options(FilterState const& filter_state) const;
97 
104  void update_state(FilterState& filter_state, FilterOption::SCPtr option, bool active) const;
105 
112  static void update_state(FilterState& filter_state, std::string const& filter_id, std::string const& option_id, bool value);
113 
114 private:
115  OptionSelectorFilter(internal::OptionSelectorFilterImpl*);
116  internal::OptionSelectorFilterImpl* fwd() const;
117  friend class internal::OptionSelectorFilterImpl;
118 };
119 
120 } // namespace scopes
121 
122 } // namespace unity
A selection filter that displays a list of choices and allows one or more of them to be selected...
Definition: OptionSelectorFilter.h:45
std::string label() const
Get the label of this filter.
Definition: OptionSelectorFilter.cpp:38
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:46
Top-level namespace for all things Unity-related.
Definition: Version.h:49
bool multi_select() const
Check if this filter supports multiple options to be selected.
Definition: OptionSelectorFilter.cpp:43
std::list< FilterOption::SCPtr > options() const
Get all options of this filter, in the order they were added.
Definition: OptionSelectorFilter.cpp:53
FilterOption::SCPtr add_option(std::string const &id, std::string const &label)
Add a new option to this filter.
Definition: OptionSelectorFilter.cpp:48
Definition: ActionMetadata.h:31
Captures state of multiple filters.
Definition: FilterState.h:46
bool has_active_option(FilterState const &filter_state) const
Check if an option is active for this filter.
Definition: OptionSelectorFilter.cpp:58
static OptionSelectorFilter::UPtr create(std::string const &id, std::string const &label, bool multi_select=false)
Creates an OpionSelectorFilter.
Definition: OptionSelectorFilter.cpp:33
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