Changeset View
Changeset View
Standalone View
Standalone View
kcms/icons/iconsizecategorymodel.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2019 Benjamin Port <benjamin.port@enioka.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 Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "iconsizecategorymodel.h" | ||||
20 | #include <KLocalizedString> | ||||
21 | | ||||
22 | IconSizeCategoryModel::IconSizeCategoryModel(QObject *parent) | ||||
23 | : QAbstractListModel(parent) | ||||
24 | , m_data({ | ||||
25 | {QStringLiteral("desktopSize"), I18N_NOOP("Desktop"), QStringLiteral("Desktop")}, | ||||
26 | {QStringLiteral("toolbarSize"), I18N_NOOP("Toolbar"), QStringLiteral("Toolbar")}, | ||||
27 | {QStringLiteral("mainToolbarSize"), I18N_NOOP("Main Toolbar"), QStringLiteral("MainToolbar")}, | ||||
28 | {QStringLiteral("smallSize"), I18N_NOOP("Small Icons"), QStringLiteral("Small")}, | ||||
29 | {QStringLiteral("panelSize"), I18N_NOOP("Panel"), QStringLiteral("Panel")}, | ||||
30 | {QStringLiteral("dialogSize"), I18N_NOOP("Dialogs"), QStringLiteral("Dialog")} | ||||
31 | }) | ||||
32 | { | ||||
33 | } | ||||
34 | | ||||
35 | IconSizeCategoryModel::~IconSizeCategoryModel() = default; | ||||
36 | | ||||
37 | int IconSizeCategoryModel::rowCount(const QModelIndex &parent) const | ||||
38 | { | ||||
39 | if (parent.isValid()) { | ||||
40 | return 0; | ||||
41 | } | ||||
42 | | ||||
43 | return m_data.count(); | ||||
44 | } | ||||
45 | | ||||
46 | QVariant IconSizeCategoryModel::data(const QModelIndex &index, int role) const | ||||
47 | { | ||||
48 | if (!index.isValid() || index.row() >= m_data.count()) { | ||||
49 | return QVariant(); | ||||
50 | } | ||||
51 | | ||||
52 | const auto &item = m_data.at(index.row()); | ||||
53 | | ||||
54 | switch (role) { | ||||
55 | case Qt::DisplayRole: | ||||
56 | return item.display; | ||||
57 | case ConfigKeyRole: | ||||
58 | return item.configKey; | ||||
59 | case ConfigSectionRole: | ||||
60 | return item.configSection; | ||||
61 | } | ||||
62 | | ||||
63 | return QVariant(); | ||||
64 | } | ||||
65 | | ||||
66 | QHash<int, QByteArray> IconSizeCategoryModel::roleNames() const | ||||
67 | { | ||||
68 | QHash<int, QByteArray> roleNames = QAbstractListModel::roleNames(); | ||||
69 | roleNames[ConfigKeyRole] = QByteArrayLiteral("configKey"); | ||||
70 | roleNames[ConfigSectionRole] = QByteArrayLiteral("configSectionRole"); | ||||
71 | return roleNames; | ||||
72 | } |