]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/servicemodel.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #include "servicemodel.h"
22 ServiceModel::ServiceModel(QObject
* parent
) :
23 QAbstractListModel(parent
),
28 ServiceModel::~ServiceModel()
32 bool ServiceModel::insertRows(int row
, int count
, const QModelIndex
& parent
)
34 if (row
> rowCount()) {
42 beginInsertRows(parent
, row
, row
+ count
- 1);
43 for (int i
= 0; i
< count
; ++i
) {
46 item
.configurable
= false;
47 m_items
.insert(row
, item
);
54 bool ServiceModel::setData(const QModelIndex
& index
, const QVariant
& value
, int role
)
56 const int row
= index
.row();
57 if (row
>= rowCount()) {
62 case Qt::CheckStateRole
:
63 m_items
[row
].checked
= value
.toBool();
65 case ConfigurableRole
:
66 m_items
[row
].configurable
= value
.toBool();
68 case Qt::DecorationRole
:
69 m_items
[row
].icon
= value
.toString();
72 m_items
[row
].text
= value
.toString();
74 case DesktopEntryNameRole
:
75 m_items
[row
].desktopEntryName
= value
.toString();
81 emit
dataChanged(index
, index
);
85 QVariant
ServiceModel::data(const QModelIndex
& index
, int role
) const
87 const int row
= index
.row();
88 if (row
< rowCount()) {
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
;
102 int ServiceModel::rowCount(const QModelIndex
& parent
) const
105 return m_items
.count();