~gerboland/unity8/initialSurfaceGeometry

« back to all changes in this revision

Viewing changes to tests/mocks/Unity/fake_scopesoverview.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:
44
44
Q_INVOKABLE void ScopesOverview::activate(QVariant const& result)
45
45
{
46
46
    Scopes *scopes = dynamic_cast<Scopes*>(parent());
47
 
    m_openScope = scopes->getScopeFromAll(result.toString());
48
 
    Q_EMIT openScope(m_openScope);
 
47
    if (scopes->getScope(result.toString())) {
 
48
        Q_EMIT gotoScope(result.toString());
 
49
    } else {
 
50
        m_openScope = scopes->getScopeFromAll(result.toString());
 
51
        Q_EMIT openScope(m_openScope);
 
52
    }
 
53
}
 
54
 
 
55
void ScopesOverview::setFavorite(Scope *scope, bool favorite)
 
56
{
 
57
    m_scopesOverviewCategories->setFavorite(scope, favorite);
 
58
}
 
59
 
 
60
void ScopesOverview::moveFavoriteTo(Scope *scope, int index)
 
61
{
 
62
    m_scopesOverviewCategories->moveFavoriteTo(scope, index);
49
63
}
50
64
 
51
65
ScopesOverviewCategories::ScopesOverviewCategories(Scopes *scopes, QObject* parent)
69
83
    qFatal("Using un-implemented ScopesOverviewCategories::overrideCategoryJson");
70
84
}
71
85
 
72
 
QVariant
73
 
ScopesOverviewCategories::data(const QModelIndex& index, int role) const
 
86
void ScopesOverviewCategories::setFavorite(Scope *scope, bool favorite)
 
87
{
 
88
    if (m_resultsModels.value(0)) {
 
89
        if (favorite) {
 
90
            m_resultsModels[0]->appendScope(scope);
 
91
        } else {
 
92
            m_resultsModels[0]->removeScope(scope);
 
93
        }
 
94
    }
 
95
    if (m_resultsModels.value(1)) {
 
96
        if (favorite) {
 
97
            m_resultsModels[1]->removeScope(scope);
 
98
        } else {
 
99
            m_resultsModels[1]->appendScope(scope);
 
100
        }
 
101
    }
 
102
}
 
103
 
 
104
void ScopesOverviewCategories::moveFavoriteTo(Scope *scope, int index)
 
105
{
 
106
    m_resultsModels[0]->moveScopeTo(scope, index);
 
107
}
 
108
 
 
109
QVariant ScopesOverviewCategories::data(const QModelIndex& index, int role) const
74
110
{
75
111
    if (!index.isValid()) {
76
112
        return QVariant();
77
113
    }
78
114
 
79
 
    const QString categoryId = index.row() == 0 ? "favorites" : "all";
 
115
    const QString categoryId = index.row() == 0 ? "favorites" : "other";
80
116
 
81
 
    unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
 
117
    ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
82
118
    if (!resultsModel) {
83
119
        QObject *that = const_cast<ScopesOverviewCategories*>(this);
84
 
        QList<Scope*> scopes = index.row() == 0 ? m_scopes->scopes() : m_scopes->allScopes();
 
120
        QList<Scope*> scopes = index.row() == 0 ? m_scopes->favScopes() : m_scopes->nonFavScopes();
85
121
        resultsModel = new ScopesOverviewResultsModel(scopes, categoryId, that);
86
122
        m_resultsModels[index.row()] = resultsModel;
87
123
    }
89
125
        case RoleCategoryId:
90
126
            return categoryId;
91
127
        case RoleName:
92
 
            return index.row() == 0 ? "Favorites" : "All";
 
128
            return index.row() == 0 ? "Favorites" : "Non Favorites";
93
129
        case RoleIcon:
94
130
            return QVariant();
95
131
        case RoleRawRendererTemplate:
157
193
 
158
194
    const QString categoryId = index.row() == 0 ? "searchA" : "searchB";
159
195
 
160
 
    unity::shell::scopes::ResultsModelInterface *resultsModel = m_resultsModels[index.row()];
 
196
    ScopesOverviewResultsModel *resultsModel = m_resultsModels[index.row()];
161
197
    if (!resultsModel) {
162
198
        QObject *that = const_cast<ScopesOverviewSearchCategories*>(this);
163
199
        QList<Scope *> scopes;
256
292
    return rowCount();
257
293
}
258
294
 
259
 
QVariant
260
 
ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
 
295
QVariant ScopesOverviewResultsModel::data(const QModelIndex& index, int role) const
261
296
{
262
297
    unity::shell::scopes::ScopeInterface *scope = m_scopes[index.row()];
263
298
    switch (role) {
269
304
            return scope ? scope->id() : QString("Result.%1.%2").arg(categoryId()).arg(index.row());
270
305
        case RoleTitle:
271
306
            return scope ? scope->name() : QString("Title.%1.%2").arg(categoryId()).arg(index.row());
 
307
        case RoleSubtitle:
 
308
            return scope && scope->name() == "Videos" ? "tube, movies, cinema" : QString();
272
309
        case RoleArt:
273
310
            return qmlDirectory() + "graphics/applicationIcons/dash.png";
274
311
        case RoleMascot:
281
318
            return QVariant();
282
319
    }
283
320
}
 
321
 
 
322
void ScopesOverviewResultsModel::appendScope(Scope *scope)
 
323
{
 
324
    Q_ASSERT(!m_scopes.contains(scope));
 
325
    const int index = rowCount();
 
326
    beginInsertRows(QModelIndex(), index, index);
 
327
    m_scopes << scope;
 
328
    endInsertRows();
 
329
    Q_EMIT countChanged();
 
330
}
 
331
 
 
332
void ScopesOverviewResultsModel::removeScope(Scope *scope)
 
333
{
 
334
    const int index = m_scopes.indexOf(scope);
 
335
    Q_ASSERT(index != -1);
 
336
    beginRemoveRows(QModelIndex(), index, index);
 
337
    m_scopes.removeAt(index);
 
338
    endRemoveRows();
 
339
    Q_EMIT countChanged();
 
340
}
 
341
 
 
342
void ScopesOverviewResultsModel::moveScopeTo(Scope *scope, int to)
 
343
{
 
344
    const int from = m_scopes.indexOf(scope);
 
345
    Q_ASSERT(from!= -1);
 
346
    beginMoveRows(QModelIndex(), from, from, QModelIndex(), to + (to > from ? 1 : 0));
 
347
    m_scopes.move(from, to);
 
348
    endMoveRows();
 
349
}