2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
16 * Author: Nick Dedekind <nick.dedekind@canonical.com>
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 + m_specialCategories.count();
35void Categories::addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject)
38 catData.categoryId = categoryId;
41 catData.rawTemplate = rawTemplate;
42 catData.countObject = countObject;
44 beginInsertRows(QModelIndex(), 0, 0);
45 m_specialCategories.prepend(catData);
49 connect(countObject, SIGNAL(countChanged()), this, SLOT(countChanged()));
53bool Categories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
55 qFatal("Using un-implemented Categories::overrideCategoryJson");
58void Categories::countChanged()
60 QObject* countObject = sender();
62 for (int i = 0; i < m_specialCategories.count(); ++i) {
63 const CategoryData &catData = m_specialCategories.at(i);
64 if (catData.countObject == countObject) {
66 roles.append(RoleCount);
68 QModelIndex changedIndex(index(i));
69 dataChanged(changedIndex, changedIndex, roles);
76Categories::data(const QModelIndex& index, int role) const
78 if (!index.isValid()) {
82 ResultsModel *resultsModel = m_resultsModels[index.row()];
84 resultsModel = new ResultsModel(15, index.row());
85 m_resultsModels[index.row()] = resultsModel;
87 if (index.row() < m_specialCategories.count()) {
88 const CategoryData &catData = m_specialCategories.at(index.row());
91 return catData.categoryId;
96 case RoleRawRendererTemplate:
97 return catData.rawTemplate;
101 if (index.row() % 2 == 0) {
102 map["category-layout"] = "grid";
104 map["category-layout"] = "carousel";
105 map["overlay"] = true;
107 map["card-size"] = "small";
112 QVariantMap map, artMap;
113 artMap["aspect-ratio"] = "1.0";
114 artMap["field"] = "art";
116 map["title"] = "HOLA";
124 return catData.countObject->property("count");
126 qFatal("Using un-implemented Categories role");
132 return QString("%1").arg(index.row());
134 return QString("Category %1").arg(index.row());
137 case RoleRawRendererTemplate:
138 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
143 if (index.row() % 2 == 0) {
144 map["category-layout"] = "grid";
146 map["category-layout"] = "carousel";
147 map["card-size"] = "medium";
148 map["overlay"] = true;
150 if (index.row() == 19) {
151 map["category-layout"] = "grid";
152 map["collapsed-rows"] = 0;
154 map["card-size"] = "small";
159 QVariantMap map, artMap;
160 if (index.row() % 2 != 0) {
161 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
163 artMap["aspect-ratio"] = "1.0";
165 artMap["field"] = "art";
167 map["title"] = "HOLA";
168 map["subtitle"] = "HOLA";
172 if (index.row() == 1 || index.row() == 4) {
173 return QString("scope://query/1");
177 return QVariant::fromValue(resultsModel);
179 return resultsModel->rowCount();
181 qFatal("Using un-implemented Categories role");
188Categories::data(int row, int role) const
190 return data(index(row, 0), role);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list