on 6337d13 help sign in
unity8/tests/mocks/Unity/fake_categories.cpp
163 lines 4.9 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 if (index.row() == 6) {
56 return QString("predefined");
57 } else if (index.row() == 8) {
58 return QString("local");
59 } else {
60 return QString("%1").arg(index.row());
61 }
62 case RoleName:
63 return QString("Category %1").arg(index.row());
64 case RoleIcon:
65 return "gtk-apply";
66 case RoleRawRendererTemplate:
67 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
68 return QVariant();
69 case RoleRenderer:
70 {
71 QVariantMap map;
72 if (index.row() % 2 == 0) {
73 map["category-layout"] = "grid";
74 } else {
75 map["category-layout"] = "carousel";
76 }
77 if (index.row() == 18) {
78 map["category-layout"] = "horizontal-list";
79 }
80 if (index.row() == 19) {
81 map["category-layout"] = "grid";
82 map["collapsed-rows"] = 0;
83 }
84 map["card-size"] = "small";
86 map["category-layout"] = m_layouts.value(index.row(), map["category-layout"].toString());
88 if (map["category-layout"] == "carousel") {
89 map["overlay"] = true;
90 }
92 return map;
93 }
94 case RoleComponents:
95 {
96 QVariantMap map, artMap, attributeMap;
97 if (index.row() % 2 != 0) {
98 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
99 } else {
100 artMap["aspect-ratio"] = "1.0";
101 }
102 artMap["field"] = "art";
103 map["art"] = artMap;
104 map["title"] = "HOLA";
105 map["subtitle"] = "HOLA";
106 attributeMap["field"] = "attribute";
107 map["attributes"] = attributeMap;
108 return map;
109 }
110 case RoleHeaderLink:
111 {
112 QString res;
113 if (index.row() == 1 || index.row() == 4) {
114 res = QString("scope://query/1");
115 }
116 res = m_headerLinks.value(index.row(), res);
117 return res;
118 }
119 case RoleResults:
120 return QVariant::fromValue(resultsModel);
121 case RoleCount:
122 return resultsModel->rowCount();
123 default:
124 qFatal("Using un-implemented Categories role");
125 return QVariant();
126 }
129QVariant
130Categories::data(int row, int role) const
132 return data(index(row, 0), role);
135void Categories::setCount(int count)
137 if (m_category_count != count) {
138 beginResetModel(); // This is just for test setup so we can be lazy and reset
139 m_category_count = count;
140 endResetModel();
141 }
144ResultsModel* Categories::resultModel(int row) const
146 ResultsModel *result = m_resultsModels[row];
147 if (!result) {
148 Categories *that = const_cast<Categories*>(this);
149 result = new ResultsModel(15, row, that);
150 m_resultsModels[row] = result;
151 }
152 return result;
155void Categories::setLayout(int row, const QString &layout)
157 m_layouts[row] = layout;
160void Categories::setHeaderLink(int row, const QString &headerLink)
162 m_headerLinks[row] = headerLink;