Unity Scopes API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 #ifndef UNITY_SCOPES_PREVIEW_WIDGET_H
20 #define UNITY_SCOPES_PREVIEW_WIDGET_H
21 
22 #include <unity/util/NonCopyable.h>
23 #include <unity/util/DefinesPtrs.h>
24 #include <unity/scopes/Variant.h>
25 #include <string>
26 #include <memory>
27 #include <list>
28 
29 namespace unity
30 {
31 
32 namespace scopes
33 {
34  class VariantMapBuilder;
35 
36 namespace internal
37 {
38  class PreviewWidgetImpl;
39 }
40 
42 {
43 public:
45  UNITY_DEFINES_PTRS(PreviewWidget);
47 
53  PreviewWidget(std::string const& id, std::string const &widget_type);
54 
59  PreviewWidget(std::string const& definition);
60 
64  //{@
65  PreviewWidget(PreviewWidget const& other);
67  virtual ~PreviewWidget();
68 
69  PreviewWidget& operator=(PreviewWidget const& other);
70  PreviewWidget& operator=(PreviewWidget&& other);
72 
78  void add_attribute_value(std::string const& key, Variant const& value);
79 
91  void add_attribute_mapping(std::string const& key, std::string const& field_name);
92 
97  std::string id() const;
98 
103  std::string widget_type() const;
104 
111  std::map<std::string, std::string> attribute_mappings() const;
112 
120 
125  std::string data() const;
126 
128  VariantMap serialize() const;
130 
131 private:
132  std::unique_ptr<internal::PreviewWidgetImpl> p;
133  PreviewWidget(internal::PreviewWidgetImpl *impl);
134  friend class internal::PreviewWidgetImpl;
135 };
136 
140 typedef std::list<PreviewWidget> PreviewWidgetList;
141 
142 } // namespace scopes
143 
144 } // namespace unity
145 
146 #endif
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:58
std::map< std::string, std::string > attribute_mappings() const
Get the components of this widget.
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:39
void add_attribute_mapping(std::string const &key, std::string const &field_name)
Adds an attribute definition using a component mapping.
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:41
std::list< PreviewWidget > PreviewWidgetList
List of preview widgets (see unity::scopes::PreviewWidget)
Definition: PreviewWidget.h:140
void add_attribute_value(std::string const &key, Variant const &value)
Adds an attribute definition and its value.