File indexing completed on 2024-05-12 05:22:30
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only 0005 * SPDX-License-Identifier: LGPL-3.0-only 0006 * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "relationshipinterest.h" 0010 0011 #include "fieldmetadata.h" 0012 #include "peopleservice.h" 0013 0014 #include <QJsonArray> 0015 #include <QJsonObject> 0016 #include <QJsonValue> 0017 #include <QSharedData> 0018 0019 #include <algorithm> 0020 0021 namespace KGAPI2::People 0022 { 0023 class RelationshipInterest::Private : public QSharedData 0024 { 0025 public: 0026 explicit Private() = default; 0027 Private(const Private &) = default; 0028 Private(Private &&) noexcept = delete; 0029 Private &operator=(const Private &) = delete; 0030 Private &operator=(Private &&) noexcept = delete; 0031 ~Private() = default; 0032 0033 bool operator==(const Private &other) const 0034 { 0035 return formattedValue == other.formattedValue && metadata == other.metadata && value == other.value; 0036 } 0037 0038 bool operator!=(const Private &other) const 0039 { 0040 return !(*this == other); 0041 } 0042 0043 QString formattedValue{}; 0044 FieldMetadata metadata{}; 0045 QString value{}; 0046 }; 0047 0048 RelationshipInterest::RelationshipInterest() 0049 : d(new Private) 0050 { 0051 } 0052 0053 RelationshipInterest::RelationshipInterest(const RelationshipInterest &) = default; 0054 RelationshipInterest::RelationshipInterest(RelationshipInterest &&) noexcept = default; 0055 RelationshipInterest &RelationshipInterest::operator=(const RelationshipInterest &) = default; 0056 RelationshipInterest &RelationshipInterest::operator=(RelationshipInterest &&) noexcept = default; 0057 RelationshipInterest::~RelationshipInterest() = default; 0058 0059 bool RelationshipInterest::operator==(const RelationshipInterest &other) const 0060 { 0061 return *d == *other.d; 0062 } 0063 0064 bool RelationshipInterest::operator!=(const RelationshipInterest &other) const 0065 { 0066 return !(*this == other); 0067 } 0068 0069 QString RelationshipInterest::formattedValue() const 0070 { 0071 return d->formattedValue; 0072 } 0073 FieldMetadata RelationshipInterest::metadata() const 0074 { 0075 return d->metadata; 0076 } 0077 0078 void RelationshipInterest::setMetadata(const FieldMetadata &value) 0079 { 0080 d->metadata = value; 0081 } 0082 QString RelationshipInterest::value() const 0083 { 0084 return d->value; 0085 } 0086 0087 void RelationshipInterest::setValue(const QString &value) 0088 { 0089 d->value = value; 0090 } 0091 0092 RelationshipInterest RelationshipInterest::fromJSON(const QJsonObject &obj) 0093 { 0094 Q_UNUSED(obj); 0095 return RelationshipInterest(); 0096 } 0097 0098 QJsonValue RelationshipInterest::toJSON() const 0099 { 0100 QJsonObject obj; 0101 0102 // Output only -> PeopleUtils::addValueToJsonObjectIfValid(obj, "formattedValue", d->formattedValue); 0103 // Skip, field metadata is only useful for receiving -> PeopleUtils::addValueToJsonObjectIfValid(obj, "metadata", d->metadata.toJSON()); 0104 PeopleUtils::addValueToJsonObjectIfValid(obj, "value", d->value); 0105 return obj; 0106 } 0107 0108 } // namespace KGAPI2::People