~gerboland/unity8/initialSurfaceGeometry

« back to all changes in this revision

Viewing changes to tests/mocks/Unity/fake_scopes.cpp

  • Committer: Gerry Boland
  • Date: 2014-12-09 12:55:58 UTC
  • mfrom: (1139.1.343 unity8)
  • Revision ID: gerry.boland@canonical.com-20141209125558-d68labgupwxfz91r
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
    return m_scopesOverview;
166
166
}
167
167
 
168
 
QList<Scope*> Scopes::scopes() const
 
168
void Scopes::setFavorite(const QString& scopeId, bool favorite)
 
169
{
 
170
    if (favorite) {
 
171
        for (Scope *scope : m_scopes) {
 
172
            // Check it's not already there
 
173
            Q_ASSERT(scope->id() != scopeId);
 
174
        }
 
175
        for (Scope *scope : m_allScopes) {
 
176
            if (scope->id() == scopeId) {
 
177
                const int index = rowCount();
 
178
                beginInsertRows(QModelIndex(), index, index);
 
179
                m_scopes << scope;
 
180
                endInsertRows();
 
181
                m_scopesOverview->setFavorite(scope, true);
 
182
                return;
 
183
            }
 
184
        }
 
185
        Q_ASSERT(false && "Unknown scopeId");
 
186
    } else {
 
187
        for (Scope *scope : m_scopes) {
 
188
            if (scope->id() == scopeId) {
 
189
                const int index = m_scopes.indexOf(scope);
 
190
                beginRemoveRows(QModelIndex(), index, index);
 
191
                m_scopes.removeAt(index);
 
192
                endRemoveRows();
 
193
                m_scopesOverview->setFavorite(scope, false);
 
194
                return;
 
195
            }
 
196
        }
 
197
        Q_ASSERT(false && "Unknown scopeId");
 
198
    }
 
199
}
 
200
 
 
201
void Scopes::moveFavoriteTo(const QString& scopeId, int to)
 
202
{
 
203
    int from = -1;
 
204
    for (int i = 0; i < m_scopes.count(); ++i) {
 
205
        if (m_scopes[i]->id() == scopeId) {
 
206
            from = i;
 
207
            break;
 
208
        }
 
209
    }
 
210
    Q_ASSERT(from != -1);
 
211
    beginMoveRows(QModelIndex(), from, from, QModelIndex(), to + (to > from ? 1 : 0));
 
212
    m_scopes.move(from, to);
 
213
    endMoveRows();
 
214
    m_scopesOverview->moveFavoriteTo(m_scopes[to], to);
 
215
}
 
216
 
 
217
QList<Scope*> Scopes::favScopes() const
169
218
{
170
219
    return m_scopes;
171
220
}
172
221
 
173
 
QList<Scope*> Scopes::allScopes() const
 
222
QList<Scope*> Scopes::nonFavScopes() const
174
223
{
175
 
    return m_allScopes;
 
224
    QList<Scope*> res;
 
225
    for (Scope *scope : m_allScopes) {
 
226
        if (!m_scopes.contains(scope))
 
227
            res << scope;
 
228
    }
 
229
    return res;
176
230
}
177
231
 
178
232
void Scopes::addScope(Scope* scope)