unity.scopes.qt.QPreviewWidget
Widget used in Preview. More...
#include <unity/scopes/qt/QPreviewWidget.h>
Public Member Functions | |
QPreviewWidget (QString const &id, QString const &widget_type) | |
Create an empty widget definition with a specific id and type. More... | |
QPreviewWidget (QString const &definition) | |
Create a widget from a JSON definition. More... | |
void | add_attribute_value (QString const &key, QVariant const &value) |
Adds an attribute definition and its value. More... | |
void | add_attribute_mapping (QString const &key, QString const &field_name) |
Adds an attribute definition using a component mapping. More... | |
void | add_widget (QPreviewWidget const &widget) |
Adds a widget into expandable widget. More... | |
QString | id () const |
Get the identifier of this widget. More... | |
QString | widget_type () const |
Get type name of this widget. More... | |
QMap< QString, QString > | attribute_mappings () const |
Get the components of this widget. More... | |
QVariantMap | attribute_values () const |
Get the attributes of this widget. More... | |
QPreviewWidgetList | widgets () const |
Get widgets of 'expandable' widget. More... | |
QString | data () const |
Get a JSON representation of this widget. More... | |
Copy and assignment | |
Copy and assignment operators (move and non-move versions) have the usual value semantics. | |
QPreviewWidget (QPreviewWidget const &other) | |
QPreviewWidget (QPreviewWidget &&other) | |
virtual | ~QPreviewWidget () |
QPreviewWidget & | operator= (QPreviewWidget const &other) |
QPreviewWidget & | operator= (QPreviewWidget &&other) |
Detailed Description
Widget used in Preview.
Constructor & Destructor Documentation
unity::scopes::qt::QPreviewWidget::QPreviewWidget | ( | QString const & | id, |
QString const & | widget_type | ||
) |
Create an empty widget definition with a specific id and type.
- Parameters
-
id The unique widget identifier. widget_type The type of the widget.
unity::scopes::qt::QPreviewWidget::QPreviewWidget | ( | QString const & | definition | ) |
Create a widget from a JSON definition.
The JSON definition must be a dictionary that includes widget "id" and all the values of attributes required by desired widget type. For example, a definition of image widget may look as follows:
PreviewWidget img(R<span class="stringliteral">"({"id": "img", "type": "image", "source": "http://imageuri"})");</span>
For cases where attribute mappings are to be used instead of direct values, they need to be enclosed in the "components" dictionary, e.g.
PreviewWidget img(R<span class="stringliteral">"({"id": "img", "type": "image", "components": { "source": "screenshot-url" } })");</span>
(this example assumes "screenshot-url" value is either available in the result object that's being previewed, or it will be pushed with unity::scopes::PreviewReply::push() method)
- Note
- It is recommended to create widgets via unity::scopes::PreviewWidget(QString const&, QString const&) constructor and unity::scopes::PreviewWidget::add_attribute_value() / unity::scopes::PreviewWidget::add_attribute_mapping() methods, rather than via JSON definition.
- Parameters
-
definition The JSON definition.
Member Function Documentation
void unity::scopes::qt::QPreviewWidget::add_attribute_mapping | ( | QString const & | key, |
QString const & | field_name | ||
) |
Adds an attribute definition using a component mapping.
If an attribute value is either not known, or the value is already present in a result field, this method creates a mapping between the attribute name and given the field name.
If an attribute value is not known, the scope is expected to push the attribute value using unity::scopes::PreviewReply::push(); otherwise, the value is automatically mapped from the result.
void unity::scopes::qt::QPreviewWidget::add_attribute_value | ( | QString const & | key, |
QVariant const & | value | ||
) |
Adds an attribute definition and its value.
- Parameters
-
key The name of the attribute. value The value of the attribute.
void unity::scopes::qt::QPreviewWidget::add_widget | ( | QPreviewWidget const & | widget | ) |
Adds a widget into expandable widget.
Adds a widget into this widget, which needs to be of 'expandable' type. This method throws if adding a widget into any other widget type. Also, adding an 'expandable' widget into another 'expandable' is not allowed.
- Exceptions
-
unity::LogicException if type of this widget is other than 'expandable', or when adding 'expandable' to 'expandable'.
QMap<QString, QString> unity::scopes::qt::QPreviewWidget::attribute_mappings | ( | ) | const |
Get the components of this widget.
The returned map is a dictionary of (key, field name) pairs, as defined by calls to add_attribute_mapping().
- Returns
- The components map.
QVariantMap unity::scopes::qt::QPreviewWidget::attribute_values | ( | ) | const |
Get the attributes of this widget.
The returned map is a dictionary of (key, value) pairs, as defined by calls to add_attribute_value().
- Returns
- The attribute map.
QString unity::scopes::qt::QPreviewWidget::data | ( | ) | const |
Get a JSON representation of this widget.
- Returns
- The JSON string.
QString unity::scopes::qt::QPreviewWidget::id | ( | ) | const |
Get the identifier of this widget.
- Returns
- The widget identifier.
QString unity::scopes::qt::QPreviewWidget::widget_type | ( | ) | const |
Get type name of this widget.
- Returns
- The widget type.
QPreviewWidgetList unity::scopes::qt::QPreviewWidget::widgets | ( | ) | const |
Get widgets of 'expandable' widget.
Returns the list of widget attached to this widget, which must be of 'expandable' type. This list is always empty for other widget types.