on xenial help sign in
Implemented onScopesReordered handler, fixed onScopeRemoved.
04e6eb6Pawel Stolowski
plugins/Unity/scopes.cpp+20−9
@@ -115,20 +115,32 @@ void Scopes::onScopesLoaded()
115
115
116void Scopes::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
116void Scopes::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
117{
117{
118− auto index = m_scopes.count();
119 auto id = QString::fromStdString(scope->id);
118 auto id = QString::fromStdString(scope->id);
119+ auto index = findScopeById(id);
120+ if (index >= 0) {
120− beginRemoveRows(QModelIndex(), index, index);
121+ beginRemoveRows(QModelIndex(), index, index);
121− auto removed_idx = removeUnityScope(id);
122+ removeUnityScope(index);
122− endRemoveRows();
123+ endRemoveRows();
123
124
124− if (removed_idx >= 0) {
125− Q_EMIT scopeRemoved(id, removed_idx);
125+ Q_EMIT scopeRemoved(id, index);
126 }
126 }
127}
127}
128
128
129void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
129void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
130{
130{
131− //TODO
131+ // is this QML-friendly? Shall it be more robust (beginMoveRows)?
132+ beginResetModel();
133+
134+ // remove existing scopes
135+ for (auto i=m_scopes.count()-1; i>=0; i--) {
136+ removeUnityScope(i);
137+ }
138+
139+ // re-create scopes
140+ for (uint i=0; i<scopes.size(); i++) {
141+ addUnityScope(scopes[i]);
142+ }
143+ endResetModel();
132}
144}
133
145
134void Scopes::onScopePropertyChanged()
146void Scopes::onScopePropertyChanged()
@@ -153,11 +165,10 @@ void Scopes::removeUnityScope(int index)
153 delete scope;
165 delete scope;
154}
166}
155
167
156−int Scopes::removeUnityScope(const QString& scope_id)
168+int Scopes::findScopeById(const QString& scope_id)
157{
169{
158 for (int i=0; i<m_scopes.count(); i++) {
170 for (int i=0; i<m_scopes.count(); i++) {
159 if (m_scopes[i]->id() == scope_id) {
171 if (m_scopes[i]->id() == scope_id) {
160− removeUnityScope(i);
161 return i;
172 return i;
162 }
173 }
163 }
174 }
plugins/Unity/scopes.h+1−1
@@ -88,7 +88,7 @@ private:
88
88
89 void addUnityScope(const unity::dash::Scope::Ptr& unity_scope);
89 void addUnityScope(const unity::dash::Scope::Ptr& unity_scope);
90 void removeUnityScope(int index);
90 void removeUnityScope(int index);
91− int removeUnityScope(const QString& scope_id);
91+ int findScopeById(const QString& scope_id);
92};
92};
93
93
94#endif // SCOPES_H
94#endif // SCOPES_H