on a7ea2a3 help sign in
unity8/tests/mocks/Unity/fake_filters.cpp
56 lines 1.9 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 auto optionFilter1 = new FakeOptionSelectorFilter("OSF1", "Tag1", "Which Cake you like More", false, QStringList() << "cheese" << "carrot" << "chocolate", this);
26 auto optionFilter2 = new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this);
27 m_filters << optionFilter1 << optionFilter2;
30int Filters::rowCount(const QModelIndex &parent) const
32 if (parent.isValid())
33 return 0;
35 return m_filters.count();
38QVariant Filters::data(const QModelIndex &index, int role) const
40 const int row = index.row();
41 if (row < 0 || row >= m_filters.count())
42 return QVariant();
44 unity::shell::scopes::FilterBaseInterface *filter = m_filters[row];
46 switch (role) {
47 case RoleFilterId:
48 return filter->filterId();
49 case RoleFilterType:
50 return filter->filterType();
51 case RoleFilter:
52 return QVariant::fromValue<unity::shell::scopes::FilterBaseInterface *>(filter);
53 default:
54 return QVariant();
55 }