on e57efda help sign in
unity8/tests/mocks/Unity/fake_categories.cpp
157 lines 4.7 kB history raw
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 General Public License as published by
6 * the Free Software Foundation; version 3.
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 General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Nick Dedekind <nick.dedekind@canonical.com>
17 */
19// self
20#include "fake_categories.h"
22#include "fake_resultsmodel.h"
24Categories::Categories(int category_count, QObject* parent)
25 : unity::shell::scopes::CategoriesInterface(parent)
26 , m_category_count(category_count)
30int Categories::rowCount(const QModelIndex& /*parent*/) const
32 return m_category_count;
35void Categories::addSpecialCategory(QString const& /*categoryId*/, QString const& /*name*/, QString const& /*icon*/, QString const& /*rawTemplate*/, QObject* /*countObject*/)
37 qFatal("Using un-implemented Categories::addSpecialCategory");
40bool Categories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
42 qFatal("Using un-implemented Categories::overrideCategoryJson");
45QVariant
46Categories::data(const QModelIndex& index, int role) const
48 if (!index.isValid()) {
49 return QVariant();
50 }
52 ResultsModel *resultsModel = resultModel(index.row());
53 switch (role) {
54 case RoleCategoryId:
55 return QString("%1").arg(index.row());
56 case RoleName:
57 return QString("Category %1").arg(index.row());
58 case RoleIcon:
59 return "gtk-apply";
60 case RoleRawRendererTemplate:
61 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
62 return QVariant();
63 case RoleRenderer:
64 {
65 QVariantMap map;
66 if (index.row() % 2 == 0) {
67 map["category-layout"] = "grid";
68 } else {
69 map["category-layout"] = "carousel";
70 }
71 if (index.row() == 18) {
72 map["category-layout"] = "horizontal-list";
73 }
74 if (index.row() == 19) {
75 map["category-layout"] = "grid";
76 map["collapsed-rows"] = 0;
77 }
78 map["card-size"] = "small";
80 map["category-layout"] = m_layouts.value(index.row(), map["category-layout"].toString());
82 if (map["category-layout"] == "carousel") {
83 map["overlay"] = true;
84 }
86 return map;
87 }
88 case RoleComponents:
89 {
90 QVariantMap map, artMap, attributeMap;
91 if (index.row() % 2 != 0) {
92 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
93 } else {
94 artMap["aspect-ratio"] = "1.0";
95 }
96 artMap["field"] = "art";
97 map["art"] = artMap;
98 map["title"] = "HOLA";
99 map["subtitle"] = "HOLA";
100 attributeMap["field"] = "attribute";
101 map["attributes"] = attributeMap;
102 return map;
103 }
104 case RoleHeaderLink:
105 {
106 QString res;
107 if (index.row() == 1 || index.row() == 4) {
108 res = QString("scope://query/1");
109 }
110 res = m_headerLinks.value(index.row(), res);
111 return res;
112 }
113 case RoleResults:
114 return QVariant::fromValue(resultsModel);
115 case RoleCount:
116 return resultsModel->rowCount();
117 default:
118 qFatal("Using un-implemented Categories role");
119 return QVariant();
120 }
123QVariant
124Categories::data(int row, int role) const
126 return data(index(row, 0), role);
129void Categories::setCount(int count)
131 if (m_category_count != count) {
132 beginResetModel(); // This is just for test setup so we can be lazy and reset
133 m_category_count = count;
134 endResetModel();
135 }
138ResultsModel* Categories::resultModel(int row) const
140 ResultsModel *result = m_resultsModels[row];
141 if (!result) {
142 Categories *that = const_cast<Categories*>(this);
143 result = new ResultsModel(15, row, that);
144 m_resultsModels[row] = result;
145 }
146 return result;
149void Categories::setLayout(int row, const QString &layout)
151 m_layouts[row] = layout;
154void Categories::setHeaderLink(int row, const QString &headerLink)
156 m_headerLinks[row] = headerLink;