@@ -115,20 +115,32 @@ void Scopes::onScopesLoaded()
115115
116116void Scopes::onScopeRemoved(const unity::dash::Scope::Ptr& scope)
117117{
118− auto index = m_scopes.count();
119118 auto id = QString::fromStdString(scope->id);
120− beginRemoveRows(QModelIndex(), index, index);
121− auto removed_idx = removeUnityScope(id);
122− endRemoveRows();
119+ auto index = findScopeById(id);
120+ if (index >= 0) {
121+ beginRemoveRows(QModelIndex(), index, index);
122+ removeUnityScope(index);
123+ endRemoveRows();
123124
124− if (removed_idx >= 0) {
125− Q_EMIT scopeRemoved(id, removed_idx);
125+ Q_EMIT scopeRemoved(id, index);
126126 }
127127}
128128
129129void Scopes::onScopesReordered(const unity::dash::Scopes::ScopeList& scopes)
130130{
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();
132144}
133145
134146void Scopes::onScopePropertyChanged()
@@ -153,11 +165,10 @@ void Scopes::removeUnityScope(int index)
153165 delete scope;
154166}
155167
156−int Scopes::removeUnityScope(const QString& scope_id)
168+int Scopes::findScopeById(const QString& scope_id)
157169{
158170 for (int i=0; i<m_scopes.count(); i++) {
159171 if (m_scopes[i]->id() == scope_id) {
160− removeUnityScope(i);
161172 return i;
162173 }
163174 }