]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/servicemodel.cpp
Merge remote-tracking branch 'origin/master' into frameworks
[dolphin.git] / src / settings / servicemodel.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "servicemodel.h"
21
22 ServiceModel::ServiceModel(QObject* parent) :
23 QAbstractListModel(parent),
24 m_items()
25 {
26 }
27
28 ServiceModel::~ServiceModel()
29 {
30 }
31
32 bool ServiceModel::insertRows(int row, int count, const QModelIndex& parent)
33 {
34 if (row > rowCount()) {
35 return false;
36 }
37
38 if (count <= 0) {
39 count = 1;
40 }
41
42 beginInsertRows(parent, row, row + count - 1);
43 for (int i = 0; i < count; ++i) {
44 ServiceItem item;
45 item.checked = false;
46 item.configurable = false;
47 m_items.insert(row, item);
48 }
49 endInsertRows();
50
51 return true;
52 }
53
54 bool ServiceModel::setData(const QModelIndex& index, const QVariant& value, int role)
55 {
56 const int row = index.row();
57 if (row >= rowCount()) {
58 return false;
59 }
60
61 switch (role) {
62 case Qt::CheckStateRole:
63 m_items[row].checked = value.toBool();
64 break;
65 case ConfigurableRole:
66 m_items[row].configurable = value.toBool();
67 break;
68 case Qt::DecorationRole:
69 m_items[row].icon = value.toString();
70 break;
71 case Qt::DisplayRole:
72 m_items[row].text = value.toString();
73 break;
74 case DesktopEntryNameRole:
75 m_items[row].desktopEntryName = value.toString();
76 break;
77 default:
78 return false;
79 }
80
81 emit dataChanged(index, index);
82 return true;
83 }
84
85 QVariant ServiceModel::data(const QModelIndex& index, int role) const
86 {
87 const int row = index.row();
88 if (row < rowCount()) {
89 switch (role) {
90 case ConfigurableRole: return m_items[row].configurable;
91 case Qt::CheckStateRole: return m_items[row].checked;
92 case Qt::DecorationRole: return m_items[row].icon;
93 case Qt::DisplayRole: return m_items[row].text;
94 case DesktopEntryNameRole: return m_items[row].desktopEntryName;
95 default: break;
96 }
97 }
98
99 return QVariant();
100 }
101
102 int ServiceModel::rowCount(const QModelIndex& parent) const
103 {
104 Q_UNUSED(parent);
105 return m_items.count();
106 }
107