on 76feda2 help sign in
unity8/tests/mocks/Unity/fake_categories.cpp
158 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;
35bool Categories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
37 qFatal("Using un-implemented Categories::overrideCategoryJson");
40QVariant
41Categories::data(const QModelIndex& index, int role) const
43 if (!index.isValid()) {
44 return QVariant();
45 }
47 ResultsModel *resultsModel = resultModel(index.row());
48 switch (role) {
49 case RoleCategoryId:
50 if (index.row() == 6) {
51 return QString("predefined");
52 } else if (index.row() == 8) {
53 return QString("local");
54 } else {
55 return QString("%1").arg(index.row());
56 }
57 case RoleName:
58 return QString("Category %1").arg(index.row());
59 case RoleIcon:
60 return "gtk-apply";
61 case RoleRawRendererTemplate:
62 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
63 return QVariant();
64 case RoleRenderer:
65 {
66 QVariantMap map;
67 if (index.row() % 2 == 0) {
68 map["category-layout"] = "grid";
69 } else {
70 map["category-layout"] = "carousel";
71 }
72 if (index.row() == 18) {
73 map["category-layout"] = "horizontal-list";
74 }
75 if (index.row() == 19) {
76 map["category-layout"] = "grid";
77 map["collapsed-rows"] = 0;
78 }
79 map["card-size"] = "small";
81 map["category-layout"] = m_layouts.value(index.row(), map["category-layout"].toString());
83 if (map["category-layout"] == "carousel") {
84 map["overlay"] = true;
85 }
87 return map;
88 }
89 case RoleComponents:
90 {
91 QVariantMap map, artMap, attributeMap;
92 if (index.row() % 2 != 0) {
93 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
94 } else {
95 artMap["aspect-ratio"] = "1.0";
96 }
97 artMap["field"] = "art";
98 map["art"] = artMap;
99 map["title"] = "HOLA";
100 map["subtitle"] = "HOLA";
101 attributeMap["field"] = "attribute";
102 map["attributes"] = attributeMap;
103 return map;
104 }
105 case RoleHeaderLink:
106 {
107 QString res;
108 if (index.row() == 1 || index.row() == 4) {
109 res = QString("scope://query/1");
110 }
111 res = m_headerLinks.value(index.row(), res);
112 return res;
113 }
114 case RoleResults:
115 return QVariant::fromValue(resultsModel);
116 case RoleCount:
117 return resultsModel->rowCount();
118 default:
119 qFatal("Using un-implemented Categories role");
120 return QVariant();
121 }
124QVariant
125Categories::data(int row, int role) const
127 return data(index(row, 0), role);
130void Categories::setCount(int count)
132 if (m_category_count != count) {
133 beginResetModel(); // This is just for test setup so we can be lazy and reset
134 m_category_count = count;
135 endResetModel();
136 }
139ResultsModel* Categories::resultModel(int row) const
141 ResultsModel *result = m_resultsModels[row];
142 if (!result) {
143 Categories *that = const_cast<Categories*>(this);
144 result = new ResultsModel(25, row, that);
145 m_resultsModels[row] = result;
146 }
147 return result;
150void Categories::setLayout(int row, const QString &layout)
152 m_layouts[row] = layout;
155void Categories::setHeaderLink(int row, const QString &headerLink)
157 m_headerLinks[row] = headerLink;