Debian Codegraph @

templates/kioworker6/src/mydatasystem.cpp

raw
1 /*
2 SPDX-FileCopyrightText: %{CURRENT_YEAR} %{AUTHOR} <%{EMAIL}>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7 #include "mydatasystem.h"
8
9 QByteArray DataItem::data() const
10 {
11 // simulating content data fetched for the item
12 return QByteArrayLiteral("Hello world\n");
13 }
14
15
16 MyDataSystem::MyDataSystem()
17 // sample data simulating that in the exposed data system
18 : m_toplevelGroup({
19 { // subgroups
20 { QStringLiteral("Subgroup"), {
21 {}, // subgroups
22 { // items
23 { QStringLiteral("Item C") },
24 { QStringLiteral("Item D") },
25 { QStringLiteral("Item E") },
26 }
27 } }
28 },
29 { // items
30 { QStringLiteral("Item A") },
31 { QStringLiteral("Item B") },
32 }
33 })
34 {
35 }
36
37 const DataGroup* MyDataSystem::group(const QStringList& groupPath) const
38 {
39 const DataGroup* currentGroup = &m_toplevelGroup;
40 for (const QString &group : groupPath) {
41 auto it = currentGroup->subGroups.constFind(group);
42 if (it == currentGroup->subGroups.constEnd()) {
43 return nullptr;
44 }
45 currentGroup = &*it;
46 }
47 return currentGroup;
48 }
49
50 bool MyDataSystem::hasGroup(const QStringList& groupPath) const
51 {
52 return (group(groupPath) != nullptr);
53 }
54
55 QList<DataItem> MyDataSystem::items(const QStringList& groupPath) const
56 {
57 auto* group = this->group(groupPath);
58 return group ? group->items : QList<DataItem>();
59 }
60
61 DataItem MyDataSystem::item(const QStringList& groupPath, const QString &itemName) const
62 {
63 auto* group = this->group(groupPath);
64 if (group) {
65 for (auto &item : group->items) {
66 if (item.name == itemName) {
67 return item;
68 }
69 }
70 }
71 return DataItem();
72 }
73
74 QStringList MyDataSystem::subGroupNames(const QStringList& groupPath) const
75 {
76 auto* group = this->group(groupPath);
77 return group ? group->subGroups.keys() : QStringList();
78 }
79