on xenial help sign in
The fake plugin provides better scopes overview scope search results
770ffe6Albert Astals
tests/mocks/Unity/fake_scopes.cpp+4−15
@@ -140,26 +140,15 @@ bool Scopes::loaded() const
140 return m_loaded;
140 return m_loaded;
141}
141}
142
142
143−int Scopes::count(bool onlyVisible) const
143+QList<unity::shell::scopes::ScopeInterface *> Scopes::scopes(bool onlyVisible) const
144{
144{
145− int count = 0;
145+ QList<unity::shell::scopes::ScopeInterface *> res;
146− for (Scope *scope : m_scopes) {
147− if (!onlyVisible || scope->visible())
148− count++;
149− }
150− return count;
151−}
152−
153−Scope *Scopes::scopeAt(int index, bool onlyVisible) const
154−{
155− int count = 0;
156 for (Scope *scope : m_scopes) {
146 for (Scope *scope : m_scopes) {
157 if (!onlyVisible || scope->visible()) {
147 if (!onlyVisible || scope->visible()) {
158− if (index == count) return scope;
148+ res << scope;
159− count++;
160 }
149 }
161 }
150 }
162− return nullptr;
151+ return res;
163}
152}
164
153
165void Scopes::addScope(Scope* scope)
154void Scopes::addScope(Scope* scope)
tests/mocks/Unity/fake_scopes.h+1−2
@@ -51,8 +51,7 @@ public:
51
51
52 bool loaded() const override;
52 bool loaded() const override;
53
53
54− int count(bool onlyVisible) const;
54+ QList<unity::shell::scopes::ScopeInterface *> scopes(bool onlyVisible) const;
55− Scope *scopeAt(int index, bool onlyVisible) const;
56
55
57private Q_SLOTS:
56private Q_SLOTS:
58 void updateScopes();
57 void updateScopes();
tests/mocks/Unity/fake_scopesoverview.cpp+95−11
@@ -23,8 +23,9 @@
23ScopesOverview::ScopesOverview(Scopes* parent)
23ScopesOverview::ScopesOverview(Scopes* parent)
24 : Scope("scopesOverview", "Scopes Overview", false, parent)
24 : Scope("scopesOverview", "Scopes Overview", false, parent)
25{
25{
26− m_searchCategories = m_categories; // save the usual categories as search result
26+ delete m_categories; // delete the usual categories, we're not going to use it
27 m_scopesOverviewCategories = new ScopesOverviewCategories(parent, this);
27 m_scopesOverviewCategories = new ScopesOverviewCategories(parent, this);
28+ m_searchCategories = new ScopesOverviewSearchCategories(parent, this);
28 m_categories = m_scopesOverviewCategories;
29 m_categories = m_scopesOverviewCategories;
29}
30}
30
31
@@ -69,15 +70,17 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
69 return QVariant();
70 return QVariant();
70 }
71 }
71
72
73+ const QString categoryId = index.row() == 0 ? "favorites" : "all";
74+
72 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
75 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
73 if (!resultsModel) {
76 if (!resultsModel) {
74 QObject *that = const_cast<ScopesOverviewCategories*>(this);
77 QObject *that = const_cast<ScopesOverviewCategories*>(this);
75− resultsModel = new ScopesOverviewResultsModel(m_scopes, index.row() == 0, that);
78+ resultsModel = new ScopesOverviewResultsModel(m_scopes->scopes(index.row() == 0), categoryId, that);
76 m_resultsModels[index.row()] = resultsModel;
79 m_resultsModels[index.row()] = resultsModel;
77 }
80 }
78 switch (role) {
81 switch (role) {
79 case RoleCategoryId:
82 case RoleCategoryId:
80− return index.row() == 0 ? "favorites" : "all";
83+ return categoryId;
81 case RoleName:
84 case RoleName:
82 return index.row() == 0 ? "Favorites" : "All";
85 return index.row() == 0 ? "Favorites" : "All";
83 case RoleIcon:
86 case RoleIcon:
@@ -114,16 +117,96 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
114
117
115
118
116
119
117−ScopesOverviewResultsModel::ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent)
120+ScopesOverviewSearchCategories::ScopesOverviewSearchCategories(Scopes *scopes, QObject* parent)
121+ : unity::shell::scopes::CategoriesInterface(parent)
122+ , m_scopes(scopes)
123+{
124+}
125+
126+int ScopesOverviewSearchCategories::rowCount(const QModelIndex& /*parent*/) const
127+{
128+ return 2;
129+}
130+
131+void ScopesOverviewSearchCategories::addSpecialCategory(QString const&, QString const&, QString const&, QString const&, QObject*)
132+{
133+ qFatal("Using un-implemented ScopesOverviewSearchCategories::addSpecialCategory");
134+}
135+
136+bool ScopesOverviewSearchCategories::overrideCategoryJson(QString const& /* categoryId */, QString const& /* json */)
137+{
138+ qFatal("Using un-implemented ScopesOverviewSearchCategories::overrideCategoryJson");
139+}
140+
141+QVariant
142+ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
143+{
144+ if (!index.isValid()) {
145+ return QVariant();
146+ }
147+
148+ const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
149+
150+ unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
151+ if (!resultsModel) {
152+ QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
153+ QList<unity::shell::scopes::ScopeInterface *> scopes;
154+ if (index.row() == 0) {
155+ scopes << m_scopes->getScope("clickscope") << nullptr << m_scopes->getScope("MockScope2");
156+ } else {
157+ scopes << nullptr << m_scopes->getScope("MockScope7") << nullptr << m_scopes->getScope("MockScope1");
158+ }
159+ resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
160+ m_resultsModels[index.row()] = resultsModel;
161+ }
162+ switch (role) {
163+ case RoleCategoryId:
164+ return categoryId;
165+ case RoleName:
166+ return index.row() == 0 ? "SearchA" : "SearchB";
167+ case RoleIcon:
168+ return QVariant();
169+ case RoleRawRendererTemplate:
170+ qFatal("Using un-implemented RoleRawRendererTemplate Categories role");
171+ return QVariant();
172+ case RoleRenderer:
173+ {
174+ QVariantMap map;
175+ map["category-layout"] = "grid";
176+ map["card-size"] = "small";
177+ map["overlay"] = true;
178+ return map;
179+ }
180+ case RoleComponents:
181+ {
182+ QVariantMap map, artMap;
183+ artMap["aspect-ratio"] = "1";
184+ artMap["field"] = "art";
185+ map["art"] = artMap;
186+ map["title"] = "HOLA";
187+ return map;
188+ }
189+ case RoleResults:
190+ return QVariant::fromValue(resultsModel);
191+ case RoleCount:
192+ return resultsModel->rowCount();
193+ default:
194+ qFatal("Using un-implemented Categories role");
195+ return QVariant();
196+ }
197+}
198+
199+
200+ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<unity::shell::scopes::ScopeInterface *> &scopes, const QString &categoryId, QObject* parent)
118 : unity::shell::scopes::ResultsModelInterface(parent)
201 : unity::shell::scopes::ResultsModelInterface(parent)
119 , m_scopes(scopes)
202 , m_scopes(scopes)
120− , m_isFavoriteCategory(isFavoriteCategory)
203+ , m_categoryId(categoryId)
121{
204{
122}
205}
123
206
124QString ScopesOverviewResultsModel::categoryId() const
207QString ScopesOverviewResultsModel::categoryId() const
125{
208{
126− return m_isFavoriteCategory ? "favorites" : "all";
209+ return m_categoryId;
127}
210}
128
211
129void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
212void ScopesOverviewResultsModel::setCategoryId(QString const& /*id*/)
@@ -135,7 +218,7 @@ int ScopesOverviewResultsModel::scopeIndex(QString const& id) const
135{
218{
136 const int scopeCount = count();
219 const int scopeCount = count();
137 for (int i = 0; i < scopeCount; ++i) {
220 for (int i = 0; i < scopeCount; ++i) {
138− if (m_scopes->scopeAt(i, m_isFavoriteCategory)->id() == id)
221+ if (m_scopes[i]->id() == id)
139 return i;
222 return i;
140 }
223 }
141 return -1;
224 return -1;
@@ -152,7 +235,7 @@ int ScopesOverviewResultsModel::rowCount(const QModelIndex& parent) const
152{
235{
153 Q_UNUSED(parent);
236 Q_UNUSED(parent);
154
237
155− return m_scopes->count(m_isFavoriteCategory);
238+ return m_scopes.count();
156}
239}
157
240
158int ScopesOverviewResultsModel::count() const
241int ScopesOverviewResultsModel::count() const
@@ -163,22 +246,23 @@ int ScopesOverviewResultsModel::count() const
163QVariant
246QVariant
164ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
247ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
165{
248{
249+ unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
166 switch (role) {
250 switch (role) {
167 case RoleUri:
251 case RoleUri:
168 case RoleCategoryId:
252 case RoleCategoryId:
169 case RoleDndUri:
253 case RoleDndUri:
170 return QString();
254 return QString();
171 case RoleResult:
255 case RoleResult:
172− return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
256+ return scope ? scope->id() : QString("Result.%1.%2").arg(categoryId()).arg(index.row());
173 case RoleTitle:
257 case RoleTitle:
174− return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->name();
258+ return scope ? scope->name() : QString("Title.%1.%2").arg(categoryId()).arg(index.row());
175 case RoleArt:
259 case RoleArt:
176 return qmlDirectory() + "graphics/applicationIcons/dash.png";
260 return qmlDirectory() + "graphics/applicationIcons/dash.png";
177 case RoleMascot:
261 case RoleMascot:
178 case RoleEmblem:
262 case RoleEmblem:
179 case RoleSummary:
263 case RoleSummary:
180 case RoleBackground + 1: // scopeId
264 case RoleBackground + 1: // scopeId
181− return m_scopes->scopeAt(index.row(), m_isFavoriteCategory)->id();
265+ return scope ? scope->id() : nullptr;
182 break;
266 break;
183 default:
267 default:
184 return QVariant();
268 return QVariant();
tests/mocks/Unity/fake_scopesoverview.h+22−3
@@ -55,12 +55,31 @@ private:
55 Scopes *m_scopes;
55 Scopes *m_scopes;
56};
56};
57
57
58+class ScopesOverviewSearchCategories : public unity::shell::scopes::CategoriesInterface
59+{
60+ Q_OBJECT
61+
62+public:
63+ ScopesOverviewSearchCategories(Scopes *scopes, QObject* parent = 0);
64+
65+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
66+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
67+
68+ Q_INVOKABLE void addSpecialCategory(QString const& categoryId, QString const& name, QString const& icon, QString const& rawTemplate, QObject* countObject) override;
69+ Q_INVOKABLE bool overrideCategoryJson(QString const& categoryId, QString const& json) override;
70+
71+private:
72+ mutable QHash<int, unity::shell::scopes::ResultsModelInterface*> m_resultsModels;
73+
74+ Scopes *m_scopes;
75+};
76+
58class ScopesOverviewResultsModel : public unity::shell::scopes::ResultsModelInterface
77class ScopesOverviewResultsModel : public unity::shell::scopes::ResultsModelInterface
59{
78{
60 Q_OBJECT
79 Q_OBJECT
61
80
62public:
81public:
63− explicit ScopesOverviewResultsModel(Scopes *scopes, bool isFavoriteCategory, QObject* parent = 0);
82+ explicit ScopesOverviewResultsModel(const QList<unity::shell::scopes::ScopeInterface *> &scopes, const QString &categoryId, QObject* parent = 0);
64
83
65 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
84 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
66 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
85 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
@@ -77,8 +96,8 @@ public:
77 QHash<int, QByteArray> roleNames() const override;
96 QHash<int, QByteArray> roleNames() const override;
78
97
79private:
98private:
80− Scopes *m_scopes;
99+ QList<unity::shell::scopes::ScopeInterface *> m_scopes;
81− bool m_isFavoriteCategory;
100+ QString m_categoryId;
82};
101};
83
102
84#endif // FAKE_SCOPESOVERVIEW_H
103#endif // FAKE_SCOPESOVERVIEW_H