@@ -115,20 +115,32 @@ void Scopes::onScopesLoaded()
116void Scopes::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
116void Scopes::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
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− beginRemoveRows(QModelIndex(), index, index);
121+ beginRemoveRows(QModelIndex(), index, index);
121− auto removed_idx = removeUnityScope(id);
122+ removeUnityScope(index);
122− endRemoveRows();
123+ endRemoveRows();
124− if (removed_idx >= 0) {
125− Q_EMIT scopeRemoved(id, removed_idx);
125+ Q_EMIT scopeRemoved(id, index);
129void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
129void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
131− //TODO
131+ // is this QML-friendly? Shall it be more robust (beginMoveRows)?
134+ // remove existing scopes
135+ for (auto i=m_scopes.count()-1; i>=0; i--) {
136+ removeUnityScope(i);
140+ for (uint i=0; i<scopes.size(); i++) {
141+ addUnityScope(scopes[i]);
134void Scopes::onScopePropertyChanged()
146void Scopes::onScopePropertyChanged()
@@ -153,11 +165,10 @@ void Scopes::removeUnityScope(int index)
153 delete scope;
165 delete scope;
156−int Scopes::removeUnityScope(const QString& scope_id)
168+int Scopes::findScopeById(const QString& scope_id)
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;