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";
122 return catData.countObject->property("count");
124 qFatal("Using un-implemented Categories role");
130 return QString("%1").arg(index.row());
132 return QString("Category %1").arg(index.row());
135 case RoleRawRendererTemplate:
136 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
141 if (index.row() % 2 == 0) {
142 map["category-layout"] = "grid";
144 map["category-layout"] = "carousel";
145 map["card-size"] = "medium";
146 map["collapsed-rows"] = 2;
147 map["overlay"] = true;
149 map["card-size"] = "small";
154 QVariantMap map, artMap;
155 if (index.row() % 2 != 0) {
156 artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
158 artMap["aspect-ratio"] = "1.0";
160 artMap["field"] = "art";
162 map["title"] = "HOLA";
163 map["subtitle"] = "HOLA";
167 return QVariant::fromValue(resultsModel);
169 return resultsModel->rowCount();
171 qFatal("Using un-implemented Categories 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