]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/servicemodel.cpp
2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "servicemodel.h"
9 ServiceModel::ServiceModel(QObject
*parent
)
10 : QAbstractListModel(parent
)
15 ServiceModel::~ServiceModel()
19 bool ServiceModel::insertRows(int row
, int count
, const QModelIndex
&parent
)
21 if (row
> rowCount()) {
29 beginInsertRows(parent
, row
, row
+ count
- 1);
30 for (int i
= 0; i
< count
; ++i
) {
33 item
.configurable
= false;
34 m_items
.insert(row
, item
);
41 bool ServiceModel::setData(const QModelIndex
&index
, const QVariant
&value
, int role
)
43 const int row
= index
.row();
44 if (row
>= rowCount()) {
49 case Qt::CheckStateRole
:
50 m_items
[row
].checked
= value
.toBool();
52 case ConfigurableRole
:
53 m_items
[row
].configurable
= value
.toBool();
55 case Qt::DecorationRole
:
56 m_items
[row
].icon
= value
.toString();
59 m_items
[row
].text
= value
.toString();
61 case DesktopEntryNameRole
:
62 m_items
[row
].desktopEntryName
= value
.toString();
68 Q_EMIT
dataChanged(index
, index
);
72 QVariant
ServiceModel::data(const QModelIndex
&index
, int role
) const
74 const int row
= index
.row();
75 if (row
< rowCount()) {
77 case ConfigurableRole
:
78 return m_items
[row
].configurable
;
79 case Qt::CheckStateRole
:
80 return m_items
[row
].checked
;
81 case Qt::DecorationRole
:
82 return m_items
[row
].icon
;
84 return m_items
[row
].text
;
85 case DesktopEntryNameRole
:
86 return m_items
[row
].desktopEntryName
;
95 int ServiceModel::rowCount(const QModelIndex
&parent
) const
98 return m_items
.count();
101 void ServiceModel::clear()
103 beginRemoveRows(QModelIndex(), 0, m_items
.count());