~mzanetti/unity8/fix-left-edge-on-spread

« back to all changes in this revision

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

  • Committer: Michael Zanetti
  • Date: 2015-01-12 11:21:17 UTC
  • mfrom: (1459.1.85 unity8)
  • Revision ID: michael.zanetti@canonical.com-20150112112117-0x9srs9dx0ndp60g
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    addScope(new Scope("MockScope1", "People", true, this));
53
53
    addScope(new Scope("MockScope2", "Music", false, this));
54
54
    addScope(new Scope("clickscope", "Apps", true, this));
55
 
    addScope(new Scope("MockScope5", "Videos", true, this));
 
55
    addScope(new Scope("MockScope5", "Videos this is long ab cd ef gh ij kl", true, this));
56
56
    addScope(new Scope("SingleCategoryScope", "Single", true, this, 1));
57
57
    addScope(new Scope("MockScope4", "MS4", true, this));
58
58
    addScope(new Scope("MockScope6", "MS6", true, this));
88
88
    }
89
89
}
90
90
 
 
91
void Scopes::clearFavorites()
 
92
{
 
93
    if (m_scopes.size() > 0) {
 
94
        beginRemoveRows(QModelIndex(), 0, m_scopes.count()-1);
 
95
        Q_FOREACH(Scope *scope, m_scopes) {
 
96
            m_scopesOverview->setFavorite(scope, false);
 
97
        }
 
98
        m_scopes.clear();
 
99
        endRemoveRows();
 
100
    }
 
101
}
 
102
 
91
103
void Scopes::load()
92
104
{
93
105
    timer.start();
165
177
    return m_scopesOverview;
166
178
}
167
179
 
168
 
QList<Scope*> Scopes::scopes() const
 
180
void Scopes::setFavorite(const QString& scopeId, bool favorite)
 
181
{
 
182
    if (favorite) {
 
183
        for (Scope *scope : m_scopes) {
 
184
            // Check it's not already there
 
185
            Q_ASSERT(scope->id() != scopeId);
 
186
        }
 
187
        for (Scope *scope : m_allScopes) {
 
188
            if (scope->id() == scopeId) {
 
189
                const int index = rowCount();
 
190
                beginInsertRows(QModelIndex(), index, index);
 
191
                m_scopes << scope;
 
192
                endInsertRows();
 
193
                m_scopesOverview->setFavorite(scope, true);
 
194
                return;
 
195
            }
 
196
        }
 
197
        Q_ASSERT(false && "Unknown scopeId");
 
198
    } else {
 
199
        for (Scope *scope : m_scopes) {
 
200
            if (scope->id() == scopeId) {
 
201
                const int index = m_scopes.indexOf(scope);
 
202
                beginRemoveRows(QModelIndex(), index, index);
 
203
                m_scopes.removeAt(index);
 
204
                endRemoveRows();
 
205
                m_scopesOverview->setFavorite(scope, false);
 
206
                return;
 
207
            }
 
208
        }
 
209
        Q_ASSERT(false && "Unknown scopeId");
 
210
    }
 
211
}
 
212
 
 
213
void Scopes::moveFavoriteTo(const QString& scopeId, int to)
 
214
{
 
215
    int from = -1;
 
216
    for (int i = 0; i < m_scopes.count(); ++i) {
 
217
        if (m_scopes[i]->id() == scopeId) {
 
218
            from = i;
 
219
            break;
 
220
        }
 
221
    }
 
222
    Q_ASSERT(from != -1);
 
223
    beginMoveRows(QModelIndex(), from, from, QModelIndex(), to + (to > from ? 1 : 0));
 
224
    m_scopes.move(from, to);
 
225
    endMoveRows();
 
226
    m_scopesOverview->moveFavoriteTo(m_scopes[to], to);
 
227
}
 
228
 
 
229
QList<Scope*> Scopes::favScopes() const
169
230
{
170
231
    return m_scopes;
171
232
}
172
233
 
173
 
QList<Scope*> Scopes::allScopes() const
 
234
QList<Scope*> Scopes::nonFavScopes() const
174
235
{
175
 
    return m_allScopes;
 
236
    QList<Scope*> res;
 
237
    for (Scope *scope : m_allScopes) {
 
238
        if (!m_scopes.contains(scope))
 
239
            res << scope;
 
240
    }
 
241
    return res;
176
242
}
177
243
 
178
244
void Scopes::addScope(Scope* scope)