on 053eaec help sign in
unity8/tests/mocks/Unity/fake_scopesoverview.cpp
149 lines 4.5 kB history raw
1/*
2 * Copyright (C) 2014 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 */
17#include "fake_scopesoverview.h"
19#include "fake_scopes.h"
21#include <paths.h>
23ScopesOverview::ScopesOverview(Scopes* parent)
24 : Scope("scopesOverview", "Scopes Overview", false, parent)
26 delete m_categories;
27 m_categories = new ScopesOverviewCategories(parent, this);
30ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
31 : unity::shell::scopes::CategoriesInterface(parent)
32 , m_scopes(scopes)
36int ScopesOverviewCategories::rowCount(const QModelIndex& /*parent*/) const
38 return 2;
41void ScopesOverviewCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
43 qFatal("Using un-implemented ScopesOverviewCategories::addSpecialCategory");
46bool ScopesOverviewCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
48 qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
51QVariant
52ScopesOverviewCategories::data(const QModelIndex& index, int role) const
54 if (!index.isValid()) {
55 return QVariant();
56 }
58 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
59 if (!resultsModel) {
60 QObject *that = const_cast<ScopesOverviewCategories*>(this);
61 resultsModel = new ScopesOverviewResultsModel(m_scopes, index.row() == 0, that);
62 m_resultsModels[index.row()] = resultsModel;
63 }
64 switch (role) {
65 case RoleCategoryId:
66 return index.row() == 0 ? "favourites" : "all";
67 case RoleName:
68 return index.row() == 0 ? "Favourites" : "All";
69 case RoleIcon:
70 return QVariant();
71 case RoleRawRendererTemplate:
72 qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
73 return QVariant();
74 case RoleRenderer:
75 {
76 QVariantMap map;
77 map["category-layout"] = "grid";
78 map["card-size"] = "small";
79 map["overlay"] = true;
80 return map;
81 }
82 case RoleComponents:
83 {
84 QVariantMap map, artMap;
85 artMap["aspect-ratio"] = "0.5";
86 artMap["field"] = "art";
87 map["art"] = artMap;
88 map["title"] = "HOLA";
89 return map;
90 }
91 case RoleResults:
92 return QVariant::fromValue(resultsModel);
93 case RoleCount:
94 return resultsModel->rowCount();
95 default:
96 qFatal("Using un-implemented Categories role");
97 return QVariant();
98 }
101ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent)
102 : unity::shell::scopes::ResultsModelInterface(parent)
103 , m_scopes(scopes)
104 , m_isFavoriteCategory(isFavoriteCategory)
108QString ScopesOverviewResultsModel::categoryId() const
110 return m_isFavoriteCategory ? "favourites" : "all";
113void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
115 qFatal("Calling un-implemented ScopesOverviewResultsModel::setCategoryId");
118int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
120 Q_UNUSED(parent);
122 return m_scopes->count(m_isFavoriteCategory);
125int ScopesOverviewResultsModel::count() const
127 return rowCount();
130QVariant
131ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
133 switch (role) {
134 case RoleUri:
135 case RoleCategoryId:
136 case RoleDndUri:
137 case RoleResult:
138 return QString();
139 case RoleTitle:
140 return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->name();
141 case RoleArt:
142 return qmlDirectory() + "graphics/applicationIcons/dash.png";
143 case RoleMascot:
144 case RoleEmblem:
145 case RoleSummary:
146 default:
147 return QVariant();
148 }