on 635b611 help sign in
unity8/tests/mocks/Unity/fake_filters.cpp
70 lines 2.2 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "fake_filters.h"
19#include "fake_optionselectorfilter.h"
20#include "fake_scope.h"
22Filters::Filters(Scope* parent)
23 : unity::shell::scopes::FiltersInterface(parent)
25 addFilter(new FakeOptionSelectorFilter("OSF1", "Tag1", "Which Cake you like More", false, QStringList() << "cheese" << "carrot" << "chocolate", this));
26 addFilter(new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this));
29void Filters::addFilter(FakeOptionSelectorFilter *f)
31 connect(f, &FakeOptionSelectorFilter::isActiveChanged, this, &Filters::activeFiltersCountChanged);
32 m_filters << f;
35int Filters::rowCount(const QModelIndex &parent) const
37 if (parent.isValid())
38 return 0;
40 return m_filters.count();
43QVariant Filters::data(const QModelIndex &index, int role) const
45 const int row = index.row();
46 if (row < 0 || row >= m_filters.count())
47 return QVariant();
49 unity::shell::scopes::FilterBaseInterface *filter = m_filters[row];
51 switch (role) {
52 case RoleFilterId:
53 return filter->filterId();
54 case RoleFilterType:
55 return filter->filterType();
56 case RoleFilter:
57 return QVariant::fromValue<unity::shell::scopes::FilterBaseInterface *>(filter);
58 default:
59 return QVariant();
60 }
63int Filters::activeFiltersCount() const
65 int active = 0;
66 Q_FOREACH(FakeOptionSelectorFilter *f, m_filters) {
67 if (f->isActive()) ++active;
68 }
69 return active;