1 | /* |
---|---|
2 | This file is part of the KContacts framework. |
3 | SPDX-FileCopyrightText: 2016-2019 Laurent Montel <montel@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #include "fieldgroup.h" |
9 | #include "parametermap_p.h" |
10 | |
11 | #include <QDataStream> |
12 | #include <QStringList> |
13 | |
14 | using namespace KContacts; |
15 | |
16 | class Q_DECL_HIDDEN FieldGroup::Private : public QSharedData |
17 | { |
18 | public: |
19 | Private() |
20 | { |
21 | } |
22 | |
23 | Private(const Private &other) |
24 | : QSharedData(other) |
25 | { |
26 | mParamMap = other.mParamMap; |
27 | fieldGroupName = other.fieldGroupName; |
28 | value = other.value; |
29 | } |
30 | |
31 | ParameterMap mParamMap; |
32 | QString fieldGroupName; |
33 | QString value; |
34 | }; |
35 | |
36 | FieldGroup::FieldGroup() |
37 | : d(new Private) |
38 | { |
39 | } |
40 | |
41 | FieldGroup::FieldGroup(const FieldGroup &other) |
42 | : d(other.d) |
43 | { |
44 | } |
45 | |
46 | FieldGroup::FieldGroup(const QString &FieldGroupName) |
47 | : d(new Private) |
48 | { |
49 | d->fieldGroupName = FieldGroupName; |
50 | } |
51 | |
52 | FieldGroup::~FieldGroup() |
53 | { |
54 | } |
55 | |
56 | void FieldGroup::setFieldGroupName(const QString &fieldGroup) |
57 | { |
58 | d->fieldGroupName = fieldGroup; |
59 | } |
60 | |
61 | QString FieldGroup::fieldGroupName() const |
62 | { |
63 | return d->fieldGroupName; |
64 | } |
65 | |
66 | bool FieldGroup::isValid() const |
67 | { |
68 | return !d->fieldGroupName.isEmpty(); |
69 | } |
70 | |
71 | void FieldGroup::setValue(const QString &value) |
72 | { |
73 | d->value = value; |
74 | } |
75 | |
76 | QString FieldGroup::value() const |
77 | { |
78 | return d->value; |
79 | } |
80 | |
81 | void FieldGroup::setParams(const ParameterMap ¶ms) |
82 | { |
83 | d->mParamMap = params; |
84 | } |
85 | |
86 | ParameterMap FieldGroup::params() const |
87 | { |
88 | return d->mParamMap; |
89 | } |
90 | |
91 | bool FieldGroup::operator==(const FieldGroup &other) const |
92 | { |
93 | return (d->mParamMap == other.d->mParamMap) && (d->fieldGroupName == other.fieldGroupName()) && (d->value == other.value()); |
94 | } |
95 | |
96 | bool FieldGroup::operator!=(const FieldGroup &other) const |
97 | { |
98 | return !(other == *this); |
99 | } |
100 | |
101 | FieldGroup &FieldGroup::operator=(const FieldGroup &other) |
102 | { |
103 | if (this != &other) { |
104 | d = other.d; |
105 | } |
106 | |
107 | return *this; |
108 | } |
109 | |
110 | QString FieldGroup::toString() const |
111 | { |
112 | QString str = QLatin1String("FieldGroup {\n"); |
113 | str += QStringLiteral(" FieldGroupName: %1 Value %2\n").arg(a: d->fieldGroupName).arg(a: d->value); |
114 | str += d->mParamMap.toString(); |
115 | str += QLatin1String("}\n"); |
116 | return str; |
117 | } |
118 | |
119 | QDataStream &KContacts::operator<<(QDataStream &s, const FieldGroup &fieldGroup) |
120 | { |
121 | return s << fieldGroup.d->mParamMap << fieldGroup.d->fieldGroupName << fieldGroup.d->value; |
122 | } |
123 | |
124 | QDataStream &KContacts::operator>>(QDataStream &s, FieldGroup &fieldGroup) |
125 | { |
126 | s >> fieldGroup.d->mParamMap >> fieldGroup.d->fieldGroupName >> fieldGroup.d->value; |
127 | return s; |
128 | } |
129 |