on xenial help sign in
implement the moveTo in the fake scopes backend
f163b26Albert Astals
tests/mocks/Unity/fake_scopes.cpp+17−1
@@ -49,9 +49,9 @@ Scopes::~Scopes()
49void Scopes::updateScopes()
49void Scopes::updateScopes()
50{
50{
51 clear();
51 clear();
52− addScope(new Scope("MockScope1", "People", true, this));
53 addScope(new Scope("MockScope2", "Music", false, this));
52 addScope(new Scope("MockScope2", "Music", false, this));
54 addScope(new Scope("clickscope", "Apps", true, this));
53 addScope(new Scope("clickscope", "Apps", true, this));
54+ addScope(new Scope("MockScope1", "People", true, this));
55 addScope(new Scope("MockScope5", "Videos", true, this));
55 addScope(new Scope("MockScope5", "Videos", true, this));
56 addScope(new Scope("SingleCategoryScope", "Single", true, this, 1));
56 addScope(new Scope("SingleCategoryScope", "Single", true, this, 1));
57 addScope(new Scope("MockScope4", "MS4", true, this));
57 addScope(new Scope("MockScope4", "MS4", true, this));
@@ -198,6 +198,22 @@ void Scopes::setFavorite(const QString& scopeId, bool favorite)
198 }
198 }
199}
199}
200
200
201+void Scopes::moveFavoriteTo(const QString& scopeId, int index)
202+{
203+ int origIndex = -1;
204+ for (int i = 0; i < m_scopes.count(); ++i) {
205+ if (m_scopes[i]->id() == scopeId) {
206+ origIndex = i;
207+ break;
208+ }
209+ }
210+ Q_ASSERT(origIndex != -1);
211+ beginMoveRows(QModelIndex(), origIndex, origIndex, QModelIndex(), index);
212+ m_scopes.move(origIndex, index);
213+ endMoveRows();
214+ m_scopesOverview->moveFavoriteTo(m_scopes[index], index);
215+}
216+
201QList<Scope*> Scopes::favScopes() const
217QList<Scope*> Scopes::favScopes() const
202{
218{
203 return m_scopes;
219 return m_scopes;
tests/mocks/Unity/fake_scopes.h+2−1
@@ -55,8 +55,9 @@ public:
55 int count() const override;
55 int count() const override;
56 unity::shell::scopes::ScopeInterface* overviewScope() const override;
56 unity::shell::scopes::ScopeInterface* overviewScope() const override;
57
57
58− // TODO This will go to the api, mark as override
58+ // TODO These will go to the api, mark as override
59 Q_INVOKABLE void setFavorite(const QString& scopeId, bool favorite);
59 Q_INVOKABLE void setFavorite(const QString& scopeId, bool favorite);
60+ Q_INVOKABLE void moveFavoriteTo(const QString& scopeId, int index);
60
61
61 // This is used as part of implementation of the other C++ code, not API
62 // This is used as part of implementation of the other C++ code, not API
62 QList<Scope*> favScopes() const;
63 QList<Scope*> favScopes() const;
tests/mocks/Unity/fake_scopesoverview.cpp+20−2
@@ -53,6 +53,11 @@ void ScopesOverview::setFavorite(Scope *scope, bool favorite)
53 m_scopesOverviewCategories->setFavorite(scope, favorite);
53 m_scopesOverviewCategories->setFavorite(scope, favorite);
54}
54}
55
55
56+void ScopesOverview::moveFavoriteTo(Scope *scope, int index)
57+{
58+ m_scopesOverviewCategories->moveFavoriteTo(scope, index);
59+}
60+
56ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
61ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
57 : unity::shell::scopes::CategoriesInterface(parent)
62 : unity::shell::scopes::CategoriesInterface(parent)
58 , m_scopes(scopes)
63 , m_scopes(scopes)
@@ -92,8 +97,12 @@ void ScopesOverviewCategories::setFavorite(Scope *scope, bool favorite)
92 }
97 }
93}
98}
94
99
95−QVariant
100+void ScopesOverviewCategories::moveFavoriteTo(Scope *scope, int index)
101+{
102+ m_resultsModels[0]->moveScopeTo(scope, index);
103+}
104+
96−ScopesOverviewCategories::data(const QModelIndex& index, int role) const
105+QVariant ScopesOverviewCategories::data(const QModelIndex& index, int role) const
97{
106{
98 if (!index.isValid()) {
107 if (!index.isValid()) {
99 return QVariant();
108 return QVariant();
@@ -323,3 +332,12 @@ void ScopesOverviewResultsModel::removeScope(Scope *scope)
323 endRemoveRows();
332 endRemoveRows();
324 Q_EMIT countChanged();
333 Q_EMIT countChanged();
325}
334}
335+
336+void ScopesOverviewResultsModel::moveScopeTo(Scope *scope, int index)
337+{
338+ const int origIndex = m_scopes.indexOf(scope);
339+ Q_ASSERT(origIndex != -1);
340+ beginMoveRows(QModelIndex(), origIndex, origIndex, QModelIndex(), index);
341+ m_scopes.move(origIndex, index);
342+ endMoveRows();
343+}
tests/mocks/Unity/fake_scopesoverview.h+3
@@ -36,6 +36,7 @@ public:
36
36
37 // This is implementation detail
37 // This is implementation detail
38 void setFavorite(Scope *scope, bool favorite);
38 void setFavorite(Scope *scope, bool favorite);
39+ void moveFavoriteTo(Scope *scope, int index);
39
40
40private:
41private:
41 ScopesOverviewCategories *m_scopesOverviewCategories;
42 ScopesOverviewCategories *m_scopesOverviewCategories;
@@ -57,6 +58,7 @@ public:
57
58
58 // This is implementation detail
59 // This is implementation detail
59 void setFavorite(Scope *scope, bool favorite);
60 void setFavorite(Scope *scope, bool favorite);
61+ void moveFavoriteTo(Scope *scope, int index);
60
62
61private:
63private:
62 mutable QHash<int, ScopesOverviewResultsModel*> m_resultsModels;
64 mutable QHash<int, ScopesOverviewResultsModel*> m_resultsModels;
@@ -107,6 +109,7 @@ public:
107 // This is implementation detail
109 // This is implementation detail
108 void appendScope(Scope *scope);
110 void appendScope(Scope *scope);
109 void removeScope(Scope *scope);
111 void removeScope(Scope *scope);
112+ void moveScopeTo(Scope *scope, int index);
110
113
111private:
114private:
112 QList<Scope *> m_scopes;
115 QList<Scope *> m_scopes;