@@ -29,25 +29,12 @@ Categories::Categories(int category_count, QObject* parent)
30int Categories::rowCount(const QModelIndex& /*parent*/) const
30int Categories::rowCount(const QModelIndex& /*parent*/) const
32− return m_category_count + m_specialCategories.count();
32+ return m_category_count;
35−void Categories::addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject)
35+void Categories::addSpecialCategory(QString const& /*categoryId*/, QString const& /*name*/, QString const& /*icon*/, QString const& /*rawTemplate*/, QObject* /*countObject*/)
37− CategoryData catData;
37+ qFatal("Using un-implemented Categories::addSpecialCategory");
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 */)
40bool Categories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
@@ -55,23 +42,6 @@ bool Categories::overrideCategoryJson(QString const& /* categoryId */, QString c
55 qFatal("Using un-implemented Categories::overrideCategoryJson");
42 qFatal("Using un-implemented Categories::overrideCategoryJson");
58−void 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
46Categories::data(const QModelIndex& index, int role) const
@@ -79,115 +49,74 @@ Categories::data(const QModelIndex& index, int role) const
79 return QVariant();
49 return QVariant();
82− ResultsModel *resultsModel = m_resultsModels[index.row()];
52+ ResultsModel *resultsModel = resultModel(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());
89− switch (role) {
53+ switch (role) {
90− case RoleCategoryId:
54+ case RoleCategoryId:
91− return catData.categoryId;
55+ return QString("%1").arg(index.row());
92− case RoleName:
56+ case RoleName:
93− return catData.name;
57+ return QString("Category %1").arg(index.row());
94− case RoleIcon:
58+ case RoleIcon:
95− return catData.icon;
59+ return "gtk-apply";
96− case RoleRawRendererTemplate:
60+ case RoleRawRendererTemplate:
97− return catData.rawTemplate;
61+ qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
98− case RoleRenderer:
63+ case RoleRenderer:
100− QVariantMap map;
65+ QVariantMap map;
101− if (index.row() % 2 == 0) {
66+ if (index.row() % 2 == 0) {
102− map["category-layout"] = "grid";
67+ map["category-layout"] = "grid";
103− } else {
68+ } else {
104− map["category-layout"] = "carousel";
69+ map["category-layout"] = "carousel";
105− map["overlay"] = true;
107− map["card-size"] = "small";
110− case RoleComponents:
71+ if (index.row() == 18) {
111− {
72+ map["category-layout"] = "horizontal-list";
112− QVariantMap map, artMap, attributeMap;
73+ }
113− artMap["aspect-ratio"] = "1.0";
74+ if (index.row() == 19) {
114− artMap["field"] = "art";
75+ map["category-layout"] = "grid";
115− map["art"] = artMap;
76+ map["collapsed-rows"] = 0;
116− map["title"] = "HOLA";
77+ }
117− attributeMap["field"] = "attribute";
78+ map["card-size"] = "small";
118− map["attributes"] = attributeMap;
79+
119− return map;
80+ map["category-layout"] = m_layouts.value(index.row(), map["category-layout"].toString());
82+ if (map["category-layout"] == "carousel") {
83+ map["overlay"] = true;
121− case RoleHeaderLink:
85+
124− return QVariant();
86+ return map;
126− return catData.countObject->property("count");
128− qFatal("Using un-implemented Categories role");
131− } else {
88+ case RoleComponents:
133− case RoleCategoryId:
134− return QString("%1").arg(index.row());
136− return QString("Category %1").arg(index.row());
139− case RoleRawRendererTemplate:
140− qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
144− QVariantMap map;
90+ QVariantMap map, artMap, attributeMap;
145− if (index.row() % 2 == 0) {
91+ if (index.row() % 2 != 0) {
146− map["category-layout"] = "grid";
92+ artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
147− } else {
93+ } else {
148− map["category-layout"] = "carousel";
94+ artMap["aspect-ratio"] = "1.0";
149− map["card-size"] = "medium";
150− map["overlay"] = true;
152− if (index.row() == 18) {
153− map["category-layout"] = "horizontal-list";
155− if (index.row() == 19) {
156− map["category-layout"] = "grid";
157− map["collapsed-rows"] = 0;
159− map["card-size"] = "small";
162− case RoleComponents:
164− QVariantMap map, artMap, attributeMap;
165− if (index.row() % 2 != 0) {
166− artMap["aspect-ratio"] = QString("1.%1").arg(index.row());
168− artMap["aspect-ratio"] = "1.0";
170− artMap["field"] = "art";
96+ artMap["field"] = "art";
171− map["art"] = artMap;
97+ map["art"] = artMap;
172− map["title"] = "HOLA";
98+ map["title"] = "HOLA";
173− map["subtitle"] = "HOLA";
99+ map["subtitle"] = "HOLA";
174− attributeMap["field"] = "attribute";
100+ attributeMap["field"] = "attribute";
175− map["attributes"] = attributeMap;
101+ map["attributes"] = attributeMap;
176− return map;
102+ return map;
104+ case RoleHeaderLink:
107+ if (index.row() == 1 || index.row() == 4) {
108+ res = QString("scope://query/1");
178− case RoleHeaderLink:
110+ res = m_headerLinks.value(index.row(), res);
179− if (index.row() == 1 || index.row() == 4) {
180− return QString("scope://query/1");
184− return QVariant::fromValue(resultsModel);
186− return resultsModel->rowCount();
188− qFatal("Using un-implemented Categories role");
189− return QVariant();
111+ return res;
114+ return QVariant::fromValue(resultsModel);
116+ return resultsModel->rowCount();
118+ qFatal("Using un-implemented Categories role");
@@ -196,3 +125,32 @@ Categories::data(int row, int role) const
197 return data(index(row, 0), role);
126 return data(index(row, 0), role);
129+void Categories::setCount(int count)
131+ if (m_category_count != count) {
132+ beginResetModel(); // This is just for test setup so we can be lazy and reset
133+ m_category_count = count;
138+ResultsModel* Categories::resultModel(int row) const
140+ ResultsModel *result = m_resultsModels[row];
142+ result = new ResultsModel(15, row);
143+ m_resultsModels[row] = result;
148+void Categories::setLayout(int row, const QString &layout)
150+ m_layouts[row] = layout;
153+void Categories::setHeaderLink(int row, const QString &headerLink)
155+ m_headerLinks[row] = headerLink;