KContacts

fieldgroup.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2016-2019 Laurent Montel <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "fieldgroup.h"
9 
10 #include <QMap>
11 #include <QStringList>
12 #include <QDataStream>
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  parameters = other.parameters;
27  fieldGroupName = other.fieldGroupName;
28  value = other.value;
29  }
30 
31  QMap<QString, QStringList> parameters;
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::setParameters(const QMap<QString, QStringList> &params)
82 {
83  d->parameters = params;
84 }
85 
86 QMap<QString, QStringList> FieldGroup::parameters() const
87 {
88  return d->parameters;
89 }
90 
91 bool FieldGroup::operator==(const FieldGroup &other) const
92 {
93  return (d->parameters == other.parameters()) && (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(d->fieldGroupName).arg(d->value);
114  if (!d->parameters.isEmpty()) {
115  QString param;
116  QMap<QString, QStringList>::const_iterator it = d->parameters.constBegin();
117  const QMap<QString, QStringList>::const_iterator end = d->parameters.constEnd();
118  while (it != end) {
119  param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(',')));
120  ++it;
121  }
122  str += QStringLiteral(" parameters: %1\n").arg(param);
123  }
124  str += QLatin1String("}\n");
125  return str;
126 }
127 
128 QDataStream &KContacts::operator<<(QDataStream &s, const FieldGroup &fieldGroup)
129 {
130  return s << fieldGroup.d->parameters << fieldGroup.d->fieldGroupName << fieldGroup.d->value;
131 }
132 
133 QDataStream &KContacts::operator>>(QDataStream &s, FieldGroup &fieldGroup)
134 {
135  s >> fieldGroup.d->parameters >> fieldGroup.d->fieldGroupName >> fieldGroup.d->value;
136  return s;
137 }
Class that holds a FieldGroup for a contact.
Definition: fieldgroup.h:21
virtual QString value(const KContacts::Addressee &addressee)
Returns a string representation of the value the field has in the given Addressee.
Definition: field.cpp:236
const Key key(const T &value, const Key &defaultKey) const const
const QList< QKeySequence > & end()
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
const T value(const Key &key, const T &defaultValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 4 2020 22:53:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.