Kgapi

fieldmetadata.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 "fieldmetadata.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 FieldMetadata::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 source == other.source && sourcePrimary == other.sourcePrimary && primary == other.primary && verified == other.verified;
35 }
36
37 bool operator!=(const Private &other) const
38 {
39 return !(*this == other);
40 }
41
42 Source source{};
43 bool sourcePrimary{};
44 bool primary{};
45 bool verified{};
46};
47
49 : d(new Private)
50{
51}
52
54FieldMetadata::FieldMetadata(FieldMetadata &&) noexcept = default;
55FieldMetadata &FieldMetadata::operator=(const FieldMetadata &) = default;
56FieldMetadata &FieldMetadata::operator=(FieldMetadata &&) noexcept = default;
57FieldMetadata::~FieldMetadata() = default;
58
59bool FieldMetadata::operator==(const FieldMetadata &other) const
60{
61 return *d == *other.d;
62}
63
64bool FieldMetadata::operator!=(const FieldMetadata &other) const
65{
66 return !(*this == other);
67}
68
70{
71 return d->source;
72}
73
75{
76 d->source = value;
77}
79{
80 return d->sourcePrimary;
81}
82
84{
85 d->sourcePrimary = value;
86}
88{
89 return d->primary;
90}
92{
93 return d->verified;
94}
95
96FieldMetadata FieldMetadata::fromJSON(const QJsonObject &obj)
97{
98 FieldMetadata fieldMetadata;
99
100 if(!obj.isEmpty()) {
101 fieldMetadata.d->primary = obj.value(QStringLiteral("primary")).toBool();
102 fieldMetadata.d->sourcePrimary = obj.value(QStringLiteral("sourcePrimary")).toBool();
103 fieldMetadata.d->verified = obj.value(QStringLiteral("verified")).toBool();
104 fieldMetadata.d->source = Source::fromJSON(obj.value(QStringLiteral("source")).toObject());
105 }
106
107 return fieldMetadata;
108}
109
110QJsonValue FieldMetadata::toJSON() const
111{
112 QJsonObject obj;
113
114 PeopleUtils::addValueToJsonObjectIfValid(obj, "source", d->source.toJSON());
115 PeopleUtils::addValueToJsonObjectIfValid(obj, "sourcePrimary", d->sourcePrimary);
116 PeopleUtils::addValueToJsonObjectIfValid(obj, "primary", d->primary);
117 PeopleUtils::addValueToJsonObjectIfValid(obj, "verified", d->verified);
118 return obj;
119}
120
121} // namespace KGAPI2::People
Metadata about a field.
FieldMetadata()
Constructs a new FieldMetadata.
void setSourcePrimary(bool value)
Sets value of the sourcePrimary property.
bool verified() const
Output only.
void setSource(const Source &value)
Sets value of the source property.
bool sourcePrimary() const
True if the field is the primary field for the source.
bool primary() const
Output only.
Source source() const
The source of the field.
The source of a field.
Definition source.h:33
bool isEmpty() const const
QJsonValue value(QLatin1StringView key) const const
bool toBool(bool defaultValue) const const
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.