on 0f274c8 help sign in
unity8/tests/mocks/Unity/fake_optionselectoroptions.cpp
63 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_optionselectoroptions.h"
19#include "fake_optionselectorfilter.h"
21FakeOptionSelectorOptions::FakeOptionSelectorOptions(const QStringList &optionLabels, FakeOptionSelectorFilter* parent)
22 : unity::shell::scopes::OptionSelectorOptionsInterface(parent),
23 m_optionLabels(optionLabels)
27int FakeOptionSelectorOptions::rowCount(const QModelIndex &parent) const
29 if (parent.isValid())
30 return 0;
32 return m_optionLabels.count();
35QVariant FakeOptionSelectorOptions::data(const QModelIndex &index, int role) const
37 const int row = index.row();
38 if (row < 0 || row >= m_optionLabels.count())
39 return QVariant();
41 switch (role) {
42 case RoleOptionId:
43 return static_cast<FakeOptionSelectorFilter*>(parent())->filterId() + QString::number(row);
44 case RoleOptionLabel:
45 return m_optionLabels[row];
46 case RoleOptionChecked:
47 return m_checkedIndexes.contains(row);
48 default:
49 return QVariant();
50 }
54void FakeOptionSelectorOptions::setChecked(int row, bool checked)
56 if (checked) {
57 m_checkedIndexes << row;
58 } else {
59 m_checkedIndexes.remove(row);
60 }
61 const QModelIndex idx = index(row, 0);
62 Q_EMIT dataChanged(idx, idx, QVector<int>() << RoleOptionChecked);