Kgapi

groupclientdata.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
3 * SPDX-FileCopyrightText: 2022 Claudio Cambra <claudio.cambra@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only
6 * SPDX-License-Identifier: LGPL-3.0-only
7 * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL
8 */
9
10#include "groupclientdata.h"
11#include "peopleservice.h"
12
13#include <QJsonArray>
14#include <QJsonObject>
15#include <QJsonValue>
16#include <QSharedData>
17
18#include <algorithm>
19
20namespace KGAPI2::People
21{
22class GroupClientData::Private : public QSharedData
23{
24public:
25 explicit Private() = default;
26 Private(const Private &) = default;
27 Private(Private &&) noexcept = delete;
28 Private &operator=(const Private &) = delete;
29 Private &operator=(Private &&) noexcept = delete;
30 ~Private() = default;
31
32 bool operator==(const Private &other) const
33 {
34 return key == other.key && value == other.value;
35 }
36
37 bool operator!=(const Private &other) const
38 {
39 return !(*this == other);
40 }
41
42 QString key{};
43 QString value{};
44};
45
47 : d(new Private)
48{
49}
50
53GroupClientData &GroupClientData::operator=(const GroupClientData &) = default;
54GroupClientData &GroupClientData::operator=(GroupClientData &&) noexcept = default;
56
57bool GroupClientData::operator==(const GroupClientData &other) const
58{
59 return *d == *other.d;
60}
61
62bool GroupClientData::operator!=(const GroupClientData &other) const
63{
64 return !(*this == other);
65}
66
68{
69 return d->key;
70}
71
73{
74 d->key = value;
75}
77{
78 return d->value;
79}
80
82{
83 d->value = value;
84}
85
86GroupClientData GroupClientData::fromJSON(const QJsonObject &obj)
87{
88 GroupClientData groupClientData;
89
90 if (!obj.isEmpty()) {
91 groupClientData.setKey(obj.value(QStringLiteral("key")).toString());
92 groupClientData.setValue(obj.value(QStringLiteral("value")).toString());
93 }
94
95 return groupClientData;
96}
97
98QList<GroupClientData> GroupClientData::fromJSONArray(const QJsonArray &data)
99{
100 QList<GroupClientData> returnGroupClientData;
101
102 for(const auto &groupClientData : data) {
103 if(groupClientData.isObject()) {
104 const auto objectifiedGroupClientData = groupClientData.toObject();
105 returnGroupClientData.append(fromJSON(objectifiedGroupClientData));
106 }
107 }
108
109 return returnGroupClientData;
110}
111
112QJsonValue GroupClientData::toJSON() const
113{
114 QJsonObject obj;
115
116 PeopleUtils::addValueToJsonObjectIfValid(obj, "key", d->key);
117 PeopleUtils::addValueToJsonObjectIfValid(obj, "value", d->value);
118 return obj;
119}
120
121} // namespace KGAPI2::People
Arbitrary client data that is populated by clients.
void setValue(const QString &value)
Sets value of the value property.
QString value() const
The client specified value of the client data.
GroupClientData()
Constructs a new GroupClientData.
QString key() const
The client specified key of the client data.
void setKey(const QString &value)
Sets value of the key property.
bool isEmpty() const const
QJsonValue value(QLatin1StringView key) const const
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.