on xenial help sign in
Compile
commit67f6aa9477fb721a3ad0da031817ab000fbef47e authorAlbert Astals <albert.astals@canonical.com> dateThu 7 Aug 2014, 10:52 (12 years ago) parent141d911
6 files changed+32−26
tests/mocks/Unity/fake_scope.cpp+1−1 tests/mocks/Unity/fake_scope.h+1−1 tests/mocks/Unity/fake_scopes.cpp+19−16 tests/mocks/Unity/fake_scopes.h+5−3 tests/mocks/Unity/fake_scopesoverview.cpp+4−3 tests/mocks/Unity/fake_scopesoverview.h+2−2
tests/mocks/Unity/fake_scope.cpp+1−1
@@ -19,7 +19,7 @@
1919
2020#include "fake_scope.h"
2121
22−include "fake_navigation.h"
22+#include "fake_navigation.h"
2323#include "fake_resultsmodel.h"
2424#include "fake_scopes.h"
2525
tests/mocks/Unity/fake_scope.h+1−1
@@ -31,7 +31,7 @@ class Scope : public unity::shell::scopes::ScopeInterface
3131 Q_OBJECT
3232
3333public:
34− Scope(QObject* parent = 0);
34+ Scope(Scopes* parent = 0);
3535 Scope(QString const& id, QString const& name, bool favorite, Scopes* parent = 0, int categories = 20);
3636
3737 /* getters */
tests/mocks/Unity/fake_scopes.cpp+19−16
@@ -73,7 +73,8 @@ void Scopes::clear()
7373 timer.stop();
7474 if (m_scopes.size() > 0) {
7575 beginRemoveRows(QModelIndex(), 0, m_scopes.count()-1);
76− qDeleteAll(m_scopes);
76+ qDeleteAll(m_allScopes);
77+ m_allScopes.clear();
7778 m_scopes.clear();
7879 endRemoveRows();
7980 }
@@ -126,17 +127,17 @@ unity::shell::scopes::ScopeInterface* Scopes::getScope(int row) const
126127
127128unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
128129{
130+ // According to mh3 Scopes::getScope should only return favorite scopes (i.e the ones in the model)
129131 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)
132133 return scope;
133134 }
134135 return nullptr;
135136}
136137
137−unity::shell::scopes::ScopeInterface* Scopes::getScopeFromAll(const QString& scope_id) const
138+Scope* Scopes::getScopeFromAll(const QString& scope_id) const
138139{
139− for (Scope *scope : m_scopes) {
140+ for (Scope *scope : m_allScopes) {
140141 if (scope->id() == scope_id)
141142 return scope;
142143 }
@@ -163,21 +164,23 @@ unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
163164 return m_scopesOverview;
164165}
165166
166−QList<unity::shell::scopes::ScopeInterface *> Scopes::scopes(bool onlyVisible) const
167+QList<Scope*> Scopes::scopes() const
167168{
168− QList<unity::shell::scopes::ScopeInterface *> res;
169− for (Scope *scope : m_scopes) {
170− if (!onlyVisible || scope->visible()) {
171− res << scope;
172− }
173− }
174− return res;
169+ return m_scopes;
170+}
171+
172+QList<Scope*> Scopes::allScopes() const
173+{
174+ return m_allScopes;
175175}
176176
177177void Scopes::addScope(Scope* scope)
178178{
179179 int index = rowCount();
180− beginInsertRows(QModelIndex(), index, index);
181− m_scopes.append(scope);
182− endInsertRows();
180+ if (scope->favorite()) {
181+ beginInsertRows(QModelIndex(), index, index);
182+ m_scopes.append(scope);
183+ endInsertRows();
184+ }
185+ m_allScopes.append(scope);
183186}
tests/mocks/Unity/fake_scopes.h+5−3
@@ -54,14 +54,16 @@ public:
5454 unity::shell::scopes::ScopeInterface* overviewScope() const override;
5555
5656 // This is used as part of implementation of the other C++ code, not API
57− QList<unity::shell::scopes::ScopeInterface *> scopes(bool onlyVisible) const;
58− unity::shell::scopes::ScopeInterface* getScopeFromAll(const QString& scope_id) const;
57+ QList<Scope*> scopes() const;
58+ QList<Scope*> allScopes() const;
59+ Scope* getScopeFromAll(const QString& scope_id) const;
5960
6061private Q_SLOTS:
6162 void updateScopes();
6263
6364private:
64− QList<Scope*> m_scopes;
65+ QList<Scope*> m_scopes; // the favorite ones
66+ QList<Scope*> m_allScopes;
6567 Scope *m_scopesOverview;
6668 bool m_loaded;
6769 QTimer timer;
tests/mocks/Unity/fake_scopesoverview.cpp+4−3
@@ -81,7 +81,8 @@ ScopesOverviewCategories::data(const QModelIndex& index, int role) const
8181 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
8282 if (!resultsModel) {
8383 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);
8586 m_resultsModels[index.row()] = resultsModel;
8687 }
8788 switch (role) {
@@ -158,7 +159,7 @@ ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
158159 unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
159160 if (!resultsModel) {
160161 QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
161− QList<unity::shell::scopes::ScopeInterface *> scopes;
162+ QList<Scope *> scopes;
162163 if (index.row() == 0) {
163164 scopes << m_scopes->getScopeFromAll("clickscope") << nullptr << m_scopes->getScopeFromAll("MockScope2");
164165 } else {
@@ -207,7 +208,7 @@ ScopesOverviewSearchCategories::data(const QModelIndex& index, int role) const
207208}
208209
209210
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)
211212 : unity::shell::scopes::ResultsModelInterface(parent)
212213 , m_scopes(scopes)
213214 , m_categoryId(categoryId)
tests/mocks/Unity/fake_scopesoverview.h+2−2
@@ -80,7 +80,7 @@ class ScopesOverviewResultsModel : public unity::shell::scopes::ResultsModelInte
8080 Q_OBJECT
8181
8282public:
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);
8484
8585 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
8686 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
@@ -97,7 +97,7 @@ public:
9797 QHash<int, QByteArray> roleNames() const override;
9898
9999private:
100− QList<unity::shell::scopes::ScopeInterface *> m_scopes;
100+ QList<Scope *> m_scopes;
101101 QString m_categoryId;
102102};
103103