on xenial help sign in
Compile
67f6aa9Albert Astals
tests/mocks/Unity/fake_scope.cpp+1−1
@@ -19,7 +19,7 @@
19
19
20#include "fake_scope.h"
20#include "fake_scope.h"
21
21
22−include "fake_navigation.h"
22+#include "fake_navigation.h"
23#include "fake_resultsmodel.h"
23#include "fake_resultsmodel.h"
24#include "fake_scopes.h"
24#include "fake_scopes.h"
25
25
tests/mocks/Unity/fake_scope.h+1−1
@@ -31,7 +31,7 @@ class Scope : public unity::shell::scopes::ScopeInterface
31 Q_OBJECT
31 Q_OBJECT
32
32
33public:
33public:
34− Scope(QObject* parent = 0);
34+ Scope(Scopes* parent = 0);
35 Scope(QString const& id, QString const& name, bool favorite, Scopes* parent = 0, int categories = 20);
35 Scope(QString const& id, QString const& name, bool favorite, Scopes* parent = 0, int categories = 20);
36
36
37 /* getters */
37 /* getters */
tests/mocks/Unity/fake_scopes.cpp+19−16
@@ -73,7 +73,8 @@ void Scopes::clear()
73 timer.stop();
73 timer.stop();
74 if (m_scopes.size() > 0) {
74 if (m_scopes.size() > 0) {
75 beginRemoveRows(QModelIndex(), 0, m_scopes.count()-1);
75 beginRemoveRows(QModelIndex(), 0, m_scopes.count()-1);
76− qDeleteAll(m_scopes);
76+ qDeleteAll(m_allScopes);
77+ m_allScopes.clear();
77 m_scopes.clear();
78 m_scopes.clear();
78 endRemoveRows();
79 endRemoveRows();
79 }
80 }
@@ -126,17 +127,17 @@ unity::shell::scopes::ScopeInterface* Scopes::getScope(int row) const
126
127
127unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
128unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
128{
129{
130+ // According to mh3 Scopes::getScope should only return favorite scopes (i.e the ones in the model)
129 for (Scope *scope : m_scopes) {
131 for (Scope *scope : m_scopes) {
130− // According to mh3 Scopes::getScope should only return non null for visible scopes
131− if (scope->id() == scope_id && scope->visible())
132+ if (scope->id() == scope_id)
132 return scope;
133 return scope;
133 }
134 }
134 return nullptr;
135 return nullptr;
135}
136}
136
137
137−unity::shell::scopes::ScopeInterface* Scopes::getScopeFromAll(const QString& scope_id) const
138+Scope* Scopes::getScopeFromAll(const QString& scope_id) const
138{
139{
139− for (Scope *scope : m_scopes) {
140+ for (Scope *scope : m_allScopes) {
140 if (scope->id() == scope_id)
141 if (scope->id() == scope_id)
141 return scope;
142 return scope;
142 }
143 }
@@ -163,21 +164,23 @@ unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
163 return m_scopesOverview;
164 return m_scopesOverview;
164}
165}
165
166
166−QList<unity::shell::scopes::ScopeInterface *> Scopes::scopes(bool onlyVisible) const
167+QList<Scope*> Scopes::scopes() const
167{
168{
168− QList<unity::shell::scopes::ScopeInterface *> res;
169+ return m_scopes;
169− for (Scope *scope : m_scopes) {
170+}
170− if (!onlyVisible || scope->visible()) {
171+
171− res << scope;
172+QList<Scope*> Scopes::allScopes() const
172− }
173+{
173− }
174− return res;
174+ return m_allScopes;
175}
175}
176
176
177void Scopes::addScope(Scope* scope)
177void Scopes::addScope(Scope* scope)
178{
178{
179 int index = rowCount();
179 int index = rowCount();
180+ if (scope->favorite()) {
180− beginInsertRows(QModelIndex(), index, index);
181+ beginInsertRows(QModelIndex(), index, index);
181− m_scopes.append(scope);
182+ m_scopes.append(scope);
182− endInsertRows();
183+ endInsertRows();
184+ }
185+ m_allScopes.append(scope);
183}
186}
tests/mocks/Unity/fake_scopes.h+5−3
@@ -54,14 +54,16 @@ public:
54 unity::shell::scopes::ScopeInterface* overviewScope() const override;
54 unity::shell::scopes::ScopeInterface* overviewScope() const override;
55
55
56 // This is used as part of implementation of the other C++ code, not API
56 // This is used as part of implementation of the other C++ code, not API
57− QList<unity::shell::scopes::ScopeInterface *> scopes(bool onlyVisible) const;
57+ QList<Scope*> scopes() const;
58+ QList<Scope*> allScopes() const;
58− unity::shell::scopes::ScopeInterface* getScopeFromAll(const QString& scope_id) const;
59+ Scope* getScopeFromAll(const QString& scope_id) const;
59
60
60private Q_SLOTS:
61private Q_SLOTS:
61 void updateScopes();
62 void updateScopes();
62
63
63private:
64private:
64− QList<Scope*> m_scopes;
65+ QList<Scope*> m_scopes; // the favorite ones
66+ QList<Scope*> m_allScopes;
65 Scope *m_scopesOverview;
67 Scope *m_scopesOverview;
66 bool m_loaded;
68 bool m_loaded;
67 QTimer timer;
69 QTimer timer;
tests/mocks/Unity/fake_scopesoverview.cpp+4−3
@@ -81,7 +81,8 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
81 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
81 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
82 if (!resultsModel) {
82 if (!resultsModel) {
83 QObject *that = const_cast<ScopesOverviewCategories*>(this);
83 QObject *that = const_cast<ScopesOverviewCategories*>(this);
84− resultsModel = new ScopesOverviewResultsModel(m_scopes->scopes(index.row() == 0), categoryId, that);
84+ QList<Scope*> scopes = index.row() == 0 ? m_scopes->scopes() : m_scopes->allScopes();
85+ resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
85 m_resultsModels[index.row()] = resultsModel;
86 m_resultsModels[index.row()] = resultsModel;
86 }
87 }
87 switch (role) {
88 switch (role) {
@@ -158,7 +159,7 @@ ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
158 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
159 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
159 if (!resultsModel) {
160 if (!resultsModel) {
160 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
161 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
161− QList<unity::shell::scopes::ScopeInterface *> scopes;
162+ QList<Scope *> scopes;
162 if (index.row() == 0) {
163 if (index.row() == 0) {
163 scopes << m_scopes->getScopeFromAll("clickscope") << nullptr << m_scopes->getScopeFromAll("MockScope2");
164 scopes << m_scopes->getScopeFromAll("clickscope") << nullptr << m_scopes->getScopeFromAll("MockScope2");
164 } else {
165 } else {
@@ -207,7 +208,7 @@ ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
207}
208}
208
209
209
210
210−ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<unity::shell::scopes::ScopeInterface *> &scopes, const QString &categoryId, QObject* parent)
211+ScopesOverviewResultsModel::ScopesOverviewResultsModel(const QList<Scope *> &scopes, const QString &categoryId, QObject* parent)
211 : unity::shell::scopes::ResultsModelInterface(parent)
212 : unity::shell::scopes::ResultsModelInterface(parent)
212 , m_scopes(scopes)
213 , m_scopes(scopes)
213 , m_categoryId(categoryId)
214 , m_categoryId(categoryId)
tests/mocks/Unity/fake_scopesoverview.h+2−2
@@ -80,7 +80,7 @@ class ScopesOverviewResultsModel : public unity::shell::scopes::ResultsModelInte
80 Q_OBJECT
80 Q_OBJECT
81
81
82public:
82public:
83− explicit ScopesOverviewResultsModel(const QList<unity::shell::scopes::ScopeInterface *> &scopes, const QString &categoryId, QObject* parent = 0);
83+ explicit ScopesOverviewResultsModel(const QList<Scope *> &scopes, const QString &categoryId, QObject* parent = 0);
84
84
85 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
85 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
86 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
86 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
@@ -97,7 +97,7 @@ public:
97 QHash<int, QByteArray> roleNames() const override;
97 QHash<int, QByteArray> roleNames() const override;
98
98
99private:
99private:
100− QList<unity::shell::scopes::ScopeInterface *> m_scopes;
100+ QList<Scope *> m_scopes;
101 QString m_categoryId;
101 QString m_categoryId;
102};
102};
103
103