Kgapi

residence.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 * SPDX-License-Identifier: LGPL-3.0-only
6 * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "residence.h"
10
11#include "fieldmetadata.h"
12#include "peopleservice.h"
13
14#include <QJsonArray>
15#include <QJsonObject>
16#include <QJsonValue>
17#include <QSharedData>
18
19#include <algorithm>
20
21namespace KGAPI2::People
22{
23class Residence::Private : public QSharedData
24{
25public:
26 explicit Private() = default;
27 Private(const Private &) = default;
28 Private(Private &&) noexcept = delete;
29 Private &operator=(const Private &) = delete;
30 Private &operator=(Private &&) noexcept = delete;
31 ~Private() = default;
32
33 bool operator==(const Private &other) const
34 {
35 return value == other.value && metadata == other.metadata && current == other.current;
36 }
37
38 bool operator!=(const Private &other) const
39 {
40 return !(*this == other);
41 }
42
43 QString value{};
44 FieldMetadata metadata{};
45 bool current{};
46};
47
49 : d(new Private)
50{
51}
52
53Residence::Residence(const Residence &) = default;
54Residence::Residence(Residence &&) noexcept = default;
55Residence &Residence::operator=(const Residence &) = default;
56Residence &Residence::operator=(Residence &&) noexcept = default;
57Residence::~Residence() = default;
58
59bool Residence::operator==(const Residence &other) const
60{
61 return *d == *other.d;
62}
63
64bool Residence::operator!=(const Residence &other) const
65{
66 return !(*this == other);
67}
68
70{
71 return d->value;
72}
73
74void Residence::setValue(const QString &value)
75{
76 d->value = value;
77}
79{
80 return d->metadata;
81}
82
84{
85 d->metadata = value;
86}
88{
89 return d->current;
90}
91
92void Residence::setCurrent(bool value)
93{
94 d->current = value;
95}
96
97Residence Residence::fromJSON(const QJsonObject &obj)
98{
99 Q_UNUSED(obj);
100 return Residence();
101}
102
103QJsonValue Residence::toJSON() const
104{
105 QJsonObject obj;
106
107 PeopleUtils::addValueToJsonObjectIfValid(obj, "value", d->value);
108 // Skip, field metadata is only useful for receiving -> PeopleUtils::addValueToJsonObjectIfValid(obj, "metadata", d->metadata.toJSON());
109 PeopleUtils::addValueToJsonObjectIfValid(obj, "current", d->current);
110 return obj;
111}
112
113} // namespace KGAPI2::People
Metadata about a field.
DEPRECATED: Please use person.locations instead.
Definition residence.h:33
void setCurrent(bool value)
Sets value of the current property.
Definition residence.cpp:92
void setMetadata(const FieldMetadata &value)
Sets value of the metadata property.
Definition residence.cpp:83
bool current() const
True if the residence is the person's current residence; false if the residence is a past residence.
Definition residence.cpp:87
void setValue(const QString &value)
Sets value of the value property.
Definition residence.cpp:74
Residence()
Constructs a new Residence.
Definition residence.cpp:48
QString value() const
The address of the residence.
Definition residence.cpp:69
FieldMetadata metadata() const
Metadata about the residence.
Definition residence.cpp:78
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.