on xenial help sign in
implement the moveTo in the fake scopes backend
commitf163b265437abd442a88e3bf35fa1672475b02fc authorAlbert Astals <albert.astals@canonical.com> dateFri 26 Sep 2014, 13:21 (12 years ago) parentc732dcc
4 files changed+42−4
tests/mocks/Unity/fake_scopes.cpp+17−1 tests/mocks/Unity/fake_scopes.h+2−1 tests/mocks/Unity/fake_scopesoverview.cpp+20−2 tests/mocks/Unity/fake_scopesoverview.h+3
tests/mocks/Unity/fake_scopes.cpp+17−1
@@ -49,9 +49,9 @@ Scopes::~Scopes()
4949void Scopes::updateScopes()
5050{
5151 clear();
52− addScope(new Scope("MockScope1", "People", true, this));
5352 addScope(new Scope("MockScope2", "Music", false, this));
5453 addScope(new Scope("clickscope", "Apps", true, this));
54+ addScope(new Scope("MockScope1", "People", true, this));
5555 addScope(new Scope("MockScope5", "Videos", true, this));
5656 addScope(new Scope("SingleCategoryScope", "Single", true, this, 1));
5757 addScope(new Scope("MockScope4", "MS4", true, this));
@@ -198,6 +198,22 @@ void Scopes::setFavorite(const QString& scopeId, bool favorite)
198198 }
199199}
200200
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+
201217QList<Scope*> Scopes::favScopes() const
202218{
203219 return m_scopes;
tests/mocks/Unity/fake_scopes.h+2−1
@@ -55,8 +55,9 @@ public:
5555 int count() const override;
5656 unity::shell::scopes::ScopeInterface* overviewScope() const override;
5757
58− // TODO This will go to the api, mark as override
58+ // TODO These will go to the api, mark as override
5959 Q_INVOKABLE void setFavorite(const QString& scopeId, bool favorite);
60+ Q_INVOKABLE void moveFavoriteTo(const QString& scopeId, int index);
6061
6162 // This is used as part of implementation of the other C++ code, not API
6263 QList<Scope*> favScopes() const;
tests/mocks/Unity/fake_scopesoverview.cpp+20−2
@@ -53,6 +53,11 @@ void ScopesOverview::setFavorite(Scope *scope, bool favorite)
5353 m_scopesOverviewCategories->setFavorite(scope, favorite);
5454}
5555
56+void ScopesOverview::moveFavoriteTo(Scope *scope, int index)
57+{
58+ m_scopesOverviewCategories->moveFavoriteTo(scope, index);
59+}
60+
5661ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
5762 : unity::shell::scopes::CategoriesInterface(parent)
5863 , m_scopes(scopes)
@@ -92,8 +97,12 @@ void ScopesOverviewCategories::setFavorite(Scope *scope, bool favorite)
9297 }
9398}
9499
95−QVariant
96−ScopesOverviewCategories::data(const QModelIndex& index, int role) const
100+void ScopesOverviewCategories::moveFavoriteTo(Scope *scope, int index)
101+{
102+ m_resultsModels[0]->moveScopeTo(scope, index);
103+}
104+
105+QVariant ScopesOverviewCategories::data(const QModelIndex& index, int role) const
97106{
98107 if (!index.isValid()) {
99108 return QVariant();
@@ -323,3 +332,12 @@ void ScopesOverviewResultsModel::removeScope(Scope *scope)
323332 endRemoveRows();
324333 Q_EMIT countChanged();
325334}
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:
3636
3737 // This is implementation detail
3838 void setFavorite(Scope *scope, bool favorite);
39+ void moveFavoriteTo(Scope *scope, int index);
3940
4041private:
4142 ScopesOverviewCategories *m_scopesOverviewCategories;
@@ -57,6 +58,7 @@ public:
5758
5859 // This is implementation detail
5960 void setFavorite(Scope *scope, bool favorite);
61+ void moveFavoriteTo(Scope *scope, int index);
6062
6163private:
6264 mutable QHash<int, ScopesOverviewResultsModel*> m_resultsModels;
@@ -107,6 +109,7 @@ public:
107109 // This is implementation detail
108110 void appendScope(Scope *scope);
109111 void removeScope(Scope *scope);
112+ void moveScopeTo(Scope *scope, int index);
110113
111114private:
112115 QList<Scope *> m_scopes;