on xenial help sign in
This should be the finished fake plugin work for scopesoverview, miss the ui to see it i did it right ^_^
commit58095ebd8c0f844c5b9d823f5ada403f565989a2 authorAlbert Astals <albert.astals@canonical.com> dateThu 10 Jul 2014, 11:56 (12 years ago) parent36aa9ae
4 files changed+246
tests/mocks/Unity/fake_scopes.cpp+22 tests/mocks/Unity/fake_scopes.h+3 tests/mocks/Unity/fake_scopesoverview.cpp+149 tests/mocks/Unity/fake_scopesoverview.h+72
tests/mocks/Unity/fake_scopes.cpp+22
@@ -130,6 +130,28 @@ bool Scopes::loaded() const
130130 return m_loaded;
131131}
132132
133+int Scopes::count(bool onlyVisible) const
134+{
135+ int count = 0;
136+ for (Scope *scope : m_scopes) {
137+ if (!onlyVisible || scope->visible())
138+ count++;
139+ }
140+ return count;
141+}
142+
143+Scope *Scopes::scopeAt(int index, bool onlyVisible) const
144+{
145+ int count = 0;
146+ for (Scope *scope : m_scopes) {
147+ if (!onlyVisible || scope->visible()) {
148+ if (index == count) return scope;
149+ count++;
150+ }
151+ }
152+ return nullptr;
153+}
154+
133155void Scopes::addScope(Scope* scope)
134156{
135157 int index = rowCount();
tests/mocks/Unity/fake_scopes.h+3
@@ -51,6 +51,9 @@ public:
5151
5252 bool loaded() const override;
5353
54+ int count(bool onlyVisible) const;
55+ Scope *scopeAt(int index, bool onlyVisible) const;
56+
5457private Q_SLOTS:
5558 void updateScopes();
5659
tests/mocks/Unity/fake_scopesoverview.cppnew file+149
@@ -0,0 +1,149 @@
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+ */
16+
17+#include "fake_scopesoverview.h"
18+
19+#include "fake_scopes.h"
20+
21+#include <paths.h>
22+
23+ScopesOverview::ScopesOverview(Scopes* parent)
24+ : Scope("scopesOverview", "Scopes Overview", false, parent)
25+{
26+ delete m_categories;
27+ m_categories = new ScopesOverviewCategories(this);
28+}
29+
30+ScopesOverviewCategories::ScopesOverviewCategories(QObject* parent)
31+ : unity::shell::scopes::CategoriesInterface(parent)
32+{
33+}
34+
35+int ScopesOverviewCategories::rowCount(const QModelIndex& /*parent*/) const
36+{
37+ return 2;
38+}
39+
40+void ScopesOverviewCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
41+{
42+ qFatal("Using un-implemented ScopesOverviewCategories::addSpecialCategory");
43+}
44+
45+bool ScopesOverviewCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
46+{
47+ qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
48+}
49+
50+QVariant
51+ScopesOverviewCategories::data(const QModelIndex& index, int role) const
52+{
53+ if (!index.isValid()) {
54+ return QVariant();
55+ }
56+
57+ return QVariant();
58+ unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
59+ if (!resultsModel) {
60+ QObject *that = const_cast<ScopesOverviewCategories*>(this);
61+ resultsModel = new ScopesOverviewResultsModel(static_cast<Scopes*>(parent()), 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"] = "medium";
79+ map["overlay"] = true;
80+ return map;
81+ }
82+ case RoleComponents:
83+ {
84+ QVariantMap map, artMap;
85+ artMap["aspect-ratio"] = "1.0";
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+ }
99+}
100+
101+ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent)
102+ : unity::shell::scopes::ResultsModelInterface(parent)
103+ , m_scopes(scopes)
104+ , m_isFavoriteCategory(isFavoriteCategory)
105+{
106+}
107+
108+QString ScopesOverviewResultsModel::categoryId() const
109+{
110+ return m_isFavoriteCategory ? "favourites" : "all";
111+}
112+
113+void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
114+{
115+ qFatal("Calling un-implemented ScopesOverviewResultsModel::setCategoryId");
116+}
117+
118+int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
119+{
120+ Q_UNUSED(parent);
121+
122+ return m_scopes->count(m_isFavoriteCategory);
123+}
124+
125+int ScopesOverviewResultsModel::count() const
126+{
127+ return rowCount();
128+}
129+
130+QVariant
131+ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
132+{
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+ }
149+}
tests/mocks/Unity/fake_scopesoverview.hnew file+72
@@ -0,0 +1,72 @@
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+ */
16+
17+#ifndef FAKE_SCOPESOVERVIEW_H
18+#define FAKE_SCOPESOVERVIEW_H
19+
20+#include "fake_scope.h"
21+#include <unity/shell/scopes/ResultsModelInterface.h>
22+
23+class Scopes;
24+
25+class ScopesOverview : public Scope
26+{
27+ Q_OBJECT
28+
29+public:
30+ ScopesOverview(Scopes* parent = 0);
31+};
32+
33+class ScopesOverviewCategories : public unity::shell::scopes::CategoriesInterface
34+{
35+ Q_OBJECT
36+
37+public:
38+ ScopesOverviewCategories(QObject* parent = 0);
39+
40+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
41+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
42+
43+ Q_INVOKABLE void addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject) override;
44+ Q_INVOKABLE bool overrideCategoryJson(QString const& categoryId, QString const& json) override;
45+
46+private:
47+ mutable QHash<int, unity::shell::scopes::ResultsModelInterface*> m_resultsModels;
48+};
49+
50+class ScopesOverviewResultsModel : public unity::shell::scopes::ResultsModelInterface
51+{
52+ Q_OBJECT
53+
54+public:
55+ explicit ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent = 0);
56+
57+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
58+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
59+
60+ /* getters */
61+ QString categoryId() const override;
62+ int count() const override;
63+
64+ /* setters */
65+ void setCategoryId(QString const& id) override;
66+
67+private:
68+ Scopes *m_scopes;
69+ bool m_isFavoriteCategory;
70+};
71+
72+#endif // FAKE_SCOPESOVERVIEW_H