~aacid/unity8/dash_overview

« back to all changes in this revision

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

  • Committer: Albert Astals
  • Date: 2014-08-07 15:27:32 UTC
  • mfrom: (1155.1.29 do_merged)
  • Revision ID: albert.astals@canonical.com-20140807152732-0zf22298f1lsxrz8
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    timer.setSingleShot(true);
35
35
    timer.setInterval(100);
36
36
    QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(updateScopes()));
 
37
 
 
38
    QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
 
39
    QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SIGNAL(countChanged()));
 
40
    QObject::connect(this, SIGNAL(modelReset()), this, SIGNAL(countChanged()));
 
41
 
37
42
    load();
38
43
}
39
44
 
68
73
    timer.stop();
69
74
    if (m_scopes.size() > 0) {
70
75
        beginRemoveRows(QModelIndex(), 0, m_scopes.count()-1);
71
 
        qDeleteAll(m_scopes);
 
76
        qDeleteAll(m_allScopes);
 
77
        m_allScopes.clear();
72
78
        m_scopes.clear();
73
79
        endRemoveRows();
74
80
    }
103
109
        return QVariant::fromValue(scope);
104
110
    } else if (role == Scopes::RoleId) {
105
111
        return QVariant::fromValue(scope->id());
106
 
    } else if (role == Scopes::RoleVisible) {
107
 
        return QVariant::fromValue(scope->visible());
108
112
    } else if (role == Scopes::RoleTitle) {
109
113
        return QVariant::fromValue(scope->name());
110
114
    } else {
123
127
 
124
128
unity::shell::scopes::ScopeInterface* Scopes::getScope(QString const &scope_id) const
125
129
{
 
130
    // According to mh3 Scopes::getScope should only return favorite scopes (i.e the ones in the model)
126
131
    for (Scope *scope : m_scopes) {
127
 
        // According to mh3 Scopes::getScope should only return non null for visible scopes
128
 
        if (scope->id() == scope_id && scope->visible())
 
132
        if (scope->id() == scope_id)
129
133
            return scope;
130
134
    }
131
135
    return nullptr;
132
136
}
133
137
 
134
 
unity::shell::scopes::ScopeInterface* Scopes::getScopeFromAll(const QString& scope_id) const
 
138
Scope* Scopes::getScopeFromAll(const QString& scope_id) const
135
139
{
136
 
    for (Scope *scope : m_scopes) {
 
140
    for (Scope *scope : m_allScopes) {
137
141
        if (scope->id() == scope_id)
138
142
            return scope;
139
143
    }
150
154
    return m_loaded;
151
155
}
152
156
 
 
157
int Scopes::count() const
 
158
{
 
159
    return rowCount();
 
160
}
 
161
 
153
162
unity::shell::scopes::ScopeInterface* Scopes::overviewScope() const
154
163
{
155
164
    return m_scopesOverview;
156
165
}
157
166
 
158
 
QList<unity::shell::scopes::ScopeInterface *> Scopes::scopes(bool onlyVisible) const
159
 
{
160
 
    QList<unity::shell::scopes::ScopeInterface *> res;
161
 
    for (Scope *scope : m_scopes) {
162
 
        if (!onlyVisible || scope->visible()) {
163
 
            res << scope;
164
 
        }
165
 
    }
166
 
    return res;
 
167
QList<Scope*> Scopes::scopes() const
 
168
{
 
169
    return m_scopes;
 
170
}
 
171
 
 
172
QList<Scope*> Scopes::allScopes() const
 
173
{
 
174
    return m_allScopes;
167
175
}
168
176
 
169
177
void Scopes::addScope(Scope* scope)
170
178
{
171
179
    int index = rowCount();
172
 
    beginInsertRows(QModelIndex(), index, index);
173
 
    m_scopes.append(scope);
174
 
    endInsertRows();
 
180
    if (scope->favorite()) {
 
181
        beginInsertRows(QModelIndex(), index, index);
 
182
        m_scopes.append(scope);
 
183
        endInsertRows();
 
184
    }
 
185
    m_allScopes.append(scope);
175
186
}