Warning, file /system/dolphin/src/settings/servicemodel.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "servicemodel.h"
0008 
0009 #include <QIcon>
0010 
0011 ServiceModel::ServiceModel(QObject *parent)
0012     : QAbstractListModel(parent)
0013     , m_items()
0014 {
0015 }
0016 
0017 ServiceModel::~ServiceModel()
0018 {
0019 }
0020 
0021 bool ServiceModel::insertRows(int row, int count, const QModelIndex &parent)
0022 {
0023     if (row > rowCount()) {
0024         return false;
0025     }
0026 
0027     if (count <= 0) {
0028         count = 1;
0029     }
0030 
0031     beginInsertRows(parent, row, row + count - 1);
0032     for (int i = 0; i < count; ++i) {
0033         ServiceItem item;
0034         item.checked = Qt::Unchecked;
0035         m_items.insert(row, item);
0036     }
0037     endInsertRows();
0038 
0039     return true;
0040 }
0041 
0042 bool ServiceModel::setData(const QModelIndex &index, const QVariant &value, int role)
0043 {
0044     const int row = index.row();
0045     if (row >= rowCount()) {
0046         return false;
0047     }
0048 
0049     switch (role) {
0050     case Qt::CheckStateRole:
0051         m_items[row].checked = value.value<Qt::CheckState>();
0052         break;
0053     case Qt::DecorationRole:
0054         m_items[row].icon = value.toString();
0055         break;
0056     case Qt::DisplayRole:
0057         m_items[row].text = value.toString();
0058         break;
0059     case DesktopEntryNameRole:
0060         m_items[row].desktopEntryName = value.toString();
0061         break;
0062     default:
0063         return false;
0064     }
0065 
0066     Q_EMIT dataChanged(index, index);
0067     return true;
0068 }
0069 
0070 QVariant ServiceModel::data(const QModelIndex &index, int role) const
0071 {
0072     const int row = index.row();
0073     if (row < rowCount()) {
0074         switch (role) {
0075         case Qt::CheckStateRole:
0076             return m_items[row].checked;
0077         case Qt::DecorationRole:
0078             return QIcon::fromTheme(m_items[row].icon);
0079         case Qt::DisplayRole:
0080             return m_items[row].text;
0081         case DesktopEntryNameRole:
0082             return m_items[row].desktopEntryName;
0083         default:
0084             break;
0085         }
0086     }
0087 
0088     return QVariant();
0089 }
0090 
0091 int ServiceModel::rowCount(const QModelIndex &parent) const
0092 {
0093     Q_UNUSED(parent)
0094     return m_items.count();
0095 }
0096 
0097 void ServiceModel::clear()
0098 {
0099     beginRemoveRows(QModelIndex(), 0, m_items.count());
0100     m_items.clear();
0101     endRemoveRows();
0102 }
0103 
0104 Qt::ItemFlags ServiceModel::flags(const QModelIndex &index) const
0105 {
0106     return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable;
0107 }
0108 
0109 #include "moc_servicemodel.cpp"