on e4400a2 help sign in
unity8/tests/mocks/Unity/fake_settingsmodel.cpp
95 lines 2.7 kB history raw
1/*
2 * Copyright (C) 2014 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_settingsmodel.h"
19SettingsModel::SettingsModel(QObject* parent) :
20 SettingsModelInterface(parent) {
21 {
22 QVariantMap parameters;
23 m_data << QSharedPointer<Data>(new Data("boolean-setting", "Boolean Setting", "boolean", parameters, true));
24 }
25 {
26 QVariantMap parameters;
27 parameters["values"] = QVariantList() << "First" << "Second" << "Third";
28 m_data << QSharedPointer<Data>(new Data("list-setting", "List Setting", "list", parameters, 1));
29 }
30 {
31 QVariantMap parameters;
32 m_data << QSharedPointer<Data>(new Data("number-setting", "Number Setting", "number", parameters, 1.23));
33 }
34 {
35 QVariantMap parameters;
36 m_data << QSharedPointer<Data>(new Data("string-setting", "String Setting", "string", parameters, "flibble"));
37 }
40QVariant SettingsModel::data(const QModelIndex& index, int role) const {
41 int row = index.row();
42 QVariant result;
44 if (row < m_data.size()) {
45 auto data = m_data[row];
47 switch (role) {
48 case Roles::RoleSettingId:
49 result = data->id;
50 break;
51 case Roles::RoleDisplayName:
52 result = data->displayName;
53 break;
54 case Roles::RoleType:
55 result = data->type;
56 break;
57 case Roles::RoleProperties:
58 result = data->properties;
59 break;
60 case Roles::RoleValue: {
61 result = data->value;
62 break;
63 }
64 default:
65 break;
66 }
67 }
69 return result;
72bool SettingsModel::setData(const QModelIndex &index, const QVariant &value, int role) {
73 int row = index.row();
74 if (row < m_data.size()) {
75 switch (role) {
76 case SettingsModelInterface::RoleValue: {
77 auto data = m_data[row];
78 data->value = value;
79 return true;
80 }
81 default:
82 break;
83 }
84 }
86 return false;
89int SettingsModel::rowCount(const QModelIndex&) const {
90 return count();
93int SettingsModel::count() const {
94 return m_data.size();