on e4400a2 help sign in
unity8/tests/mocks/Unity/fake_previewwidgetmodel.cpp
97 lines 3.1 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * Authors:
5 * Michał Sawicz <michal.sawicz@canonical.com>
6 * Michal Hruby <michal.hruby@canonical.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 3.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
21// self
22#include "fake_previewwidgetmodel.h"
24// Qt
25#include <QVariantMap>
27struct PreviewData
29 QString id;
30 QString type;
31 QVariantMap data;
33 PreviewData(QString const& id_, QString const& type_, QVariantMap const& data_): id(id_), type(type_), data(data_)
34 {
35 }
36};
38PreviewWidgetModel::PreviewWidgetModel(QObject* parent)
39 : unity::shell::scopes::PreviewWidgetModelInterface(parent)
41 populateWidgets();
44void PreviewWidgetModel::populateWidgets()
46 beginResetModel();
47 m_previewWidgets.clear();
48 for (int i = 0; i <= 20; i++) {
49 // FIXME: the API will expose nicer getters soon, use those!
50 QVariantMap attributes;
51 attributes["text"] = QVariant::fromValue(QString("Widget %1").arg(i));
52 attributes["title"] = QVariant::fromValue(QString("Title %1").arg(i));
53 PreviewData* preview_data = new PreviewData(QString("widget-%1").arg(i), QString("text"), attributes);
54 m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
55 }
57 {
58 QVariantMap attributes;
59 attributes["source"] = QVariant("qrc:///Unity/Application/screenshots/browser@12.png");
60 PreviewData* preview_data = new PreviewData(QString("widget-22"), QString("image"), attributes);
61 m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
62 }
64 {
65 QVariantMap attributes;
66 QVariantMap buttonData;
67 buttonData["label"] = "Button";
68 buttonData["id"] = "open_click";
69 QVariantList buttons;
70 buttons << buttonData << buttonData << buttonData;
71 attributes["actions"] = QVariant::fromValue(buttons);
72 PreviewData* preview_data = new PreviewData(QString("widget-21"), QString("actions"), attributes);
73 m_previewWidgets.append(QSharedPointer<PreviewData>(preview_data));
74 }
76 endResetModel();
79int PreviewWidgetModel::rowCount(const QModelIndex&) const
81 return m_previewWidgets.size();
84QVariant PreviewWidgetModel::data(const QModelIndex& index, int role) const
86 auto widget_data = m_previewWidgets.at(index.row());
87 switch (role) {
88 case RoleWidgetId:
89 return widget_data->id;
90 case RoleType:
91 return widget_data->type;
92 case RoleProperties:
93 return widget_data->data;
94 default:
95 return QVariant();
96 }