Unity Scopes API
PreviewWidget.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/util/NonCopyable.h>
22 #include <unity/util/DefinesPtrs.h>
23 #include <unity/scopes/Variant.h>
24 #include <string>
25 #include <memory>
26 #include <list>
27 
28 namespace unity
29 {
30 
31 namespace scopes
32 {
33  class VariantMapBuilder;
34 
35 namespace internal
36 {
37  class PreviewWidgetImpl;
38 }
39 
40 class PreviewWidget;
41 
45 typedef std::list<PreviewWidget> PreviewWidgetList;
46 
48 {
49 public:
51  UNITY_DEFINES_PTRS(PreviewWidget);
53 
59  PreviewWidget(std::string const& id, std::string const &widget_type);
60 
85  PreviewWidget(std::string const& definition);
86 
90  //{@
91  PreviewWidget(PreviewWidget const& other);
93  virtual ~PreviewWidget();
94 
95  PreviewWidget& operator=(PreviewWidget const& other);
96  PreviewWidget& operator=(PreviewWidget&& other);
98 
104  void add_attribute_value(std::string const& key, Variant const& value);
105 
117  void add_attribute_mapping(std::string const& key, std::string const& field_name);
118 
129  void add_widget(PreviewWidget const& widget);
130 
135  std::string id() const;
136 
141  std::string widget_type() const;
142 
149  std::map<std::string, std::string> attribute_mappings() const;
150 
158 
165  PreviewWidgetList widgets() const;
166 
171  std::string data() const;
172 
174  VariantMap serialize() const;
176 
177 private:
178  std::unique_ptr<internal::PreviewWidgetImpl> p;
179  PreviewWidget(internal::PreviewWidgetImpl *impl);
180  friend class internal::PreviewWidgetImpl;
181 };
182 
183 } // namespace scopes
184 
185 } // namespace unity
VariantMap attribute_values() const
Get the attributes of this widget.
std::string widget_type() const
Get type name of this widget.
Simple variant class that can hold an integer, boolean, string, double, dictionary, array or null value.
Definition: Variant.h:57
std::map< std::string, std::string > attribute_mappings() const
Get the components of this widget.
Top-level namespace for all things Unity-related.
Definition: Version.h:49
std::string id() const
Get the identifier of this widget.
std::map< std::string, Variant > VariantMap
A dictionary of (string, Variant) pairs.
Definition: Variant.h:38
void add_attribute_mapping(std::string const &key, std::string const &field_name)
Adds an attribute definition using a component mapping.
Definition: ActionMetadata.h:31
PreviewWidgetList widgets() const
Get widgets of 'expandable' widget.
std::string data() const
Get a JSON representation of this widget.
PreviewWidget(std::string const &id, std::string const &widget_type)
Create an empty widget definition with a specific id and type.
A widget for a preview.
Definition: PreviewWidget.h:47
std::list< PreviewWidget > PreviewWidgetList
List of preview widgets (see unity::scopes::PreviewWidget)
Definition: PreviewWidget.h:45
void add_attribute_value(std::string const &key, Variant const &value)
Adds an attribute definition and its value.
void add_widget(PreviewWidget const &widget)
Adds a widget into expandable widget.