]>
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 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
: return m_items
[row
].configurable
;
78 case Qt::CheckStateRole
: return m_items
[row
].checked
;
79 case Qt::DecorationRole
: return m_items
[row
].icon
;
80 case Qt::DisplayRole
: return m_items
[row
].text
;
81 case DesktopEntryNameRole
: return m_items
[row
].desktopEntryName
;
89 int ServiceModel::rowCount(const QModelIndex
& parent
) const
92 return m_items
.count();
95 void ServiceModel::clear()
97 beginRemoveRows(QModelIndex(), 0, m_items
.count());