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 : QAbstractListModel(parent)
26 , m_category_count(category_count)
28 m_roles[Categories::RoleCategoryId] = "categoryId";
29 m_roles[Categories::RoleName] = "name";
30 m_roles[Categories::RoleIcon] = "icon";
31 m_roles[Categories::RoleRawRendererTemplate] = "rawRendererTemplate";
32 m_roles[Categories::RoleRenderer] = "renderer";
33 m_roles[Categories::RoleComponents] = "components";
34 m_roles[Categories::RoleProgressSource] = "progressSource";
35 m_roles[Categories::RoleResults] = "results";
36 m_roles[Categories::RoleCount] = "count";
40Categories::roleNames() const
45int Categories::rowCount(const QModelIndex& /*parent*/) const
47 return m_category_count + m_specialCategories.count();
50void Categories::addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject)
53 catData.categoryId = categoryId;
56 catData.rawTemplate = rawTemplate;
57 catData.countObject = countObject;
59 beginInsertRows(QModelIndex(), 0, 0);
60 m_specialCategories.prepend(catData);
64 connect(countObject, SIGNAL(countChanged()), this, SLOT(countChanged()));
68void Categories::countChanged()
70 QObject* countObject = sender();
72 for (int i = 0; i < m_specialCategories.count(); ++i) {
73 const CategoryData &catData = m_specialCategories.at(i);
74 if (catData.countObject == countObject) {
76 roles.append(RoleCount);
78 QModelIndex changedIndex(index(i));
79 dataChanged(changedIndex, changedIndex, roles);
86Categories::data(const QModelIndex& index, int role) const
88 if (!index.isValid()) {
92 ResultsModel *resultsModel = m_resultsModels[index.row()];
94 resultsModel = new ResultsModel(15, index.row());
95 m_resultsModels[index.row()] = resultsModel;
97 if (index.row() < m_specialCategories.count()) {
98 const CategoryData &catData = m_specialCategories.at(index.row());
101 return catData.categoryId;
106 case RoleRawRendererTemplate:
107 return catData.rawTemplate;
111 map["category-layout"] = index.row() % 2 == 0 ? "grid" : "carousel";
112 map["card-size"] = "small";
117 QVariantMap map, artMap;
118 artMap["aspect-ratio"] = "1.0";
119 artMap["field"] = "art";
121 map["title"] = "HOLA";
124 case RoleProgressSource:
125 qFatal("Using un-implemented RoleProgressSource Categories role");
130 return catData.countObject->property("count");
132 qFatal("Using un-implemented Categories role");
138 return QString("%1").arg(index.row());
140 return QString("Category %1").arg(index.row());
143 case RoleRawRendererTemplate:
144 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
149 map["category-layout"] = index.row() % 2 == 0 ? "grid" : "carousel";
150 map["card-size"] = "small";
155 QVariantMap map, artMap;
156 artMap["aspect-ratio"] = "1.0";
157 artMap["field"] = "art";
159 map["title"] = "HOLA";
162 case RoleProgressSource:
163 qFatal("Using un-implemented RoleProgressSource Categories role");
166 return QVariant::fromValue(resultsModel);
168 return resultsModel->rowCount();
170 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