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 <QDataStream>
11 #include <QStringList>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN FieldGroup::Private : public QSharedData
16 {
17 public:
18  Private()
19  {
20  }
21 
22  Private(const Private &other)
23  : QSharedData(other)
24  {
25  parameters = other.parameters;
26  fieldGroupName = other.fieldGroupName;
27  value = other.value;
28  }
29 
30  QMap<QString, QStringList> parameters;
31  QString fieldGroupName;
32  QString value;
33 };
34 
35 FieldGroup::FieldGroup()
36  : d(new Private)
37 {
38 }
39 
40 FieldGroup::FieldGroup(const FieldGroup &other)
41  : d(other.d)
42 {
43 }
44 
45 FieldGroup::FieldGroup(const QString &FieldGroupName)
46  : d(new Private)
47 {
48  d->fieldGroupName = FieldGroupName;
49 }
50 
51 FieldGroup::~FieldGroup()
52 {
53 }
54 
55 void FieldGroup::setFieldGroupName(const QString &fieldGroup)
56 {
57  d->fieldGroupName = fieldGroup;
58 }
59 
60 QString FieldGroup::fieldGroupName() const
61 {
62  return d->fieldGroupName;
63 }
64 
65 bool FieldGroup::isValid() const
66 {
67  return !d->fieldGroupName.isEmpty();
68 }
69 
70 void FieldGroup::setValue(const QString &value)
71 {
72  d->value = value;
73 }
74 
75 QString FieldGroup::value() const
76 {
77  return d->value;
78 }
79 
80 void FieldGroup::setParameters(const QMap<QString, QStringList> &params)
81 {
82  d->parameters = params;
83 }
84 
85 QMap<QString, QStringList> FieldGroup::parameters() const
86 {
87  return d->parameters;
88 }
89 
90 bool FieldGroup::operator==(const FieldGroup &other) const
91 {
92  return (d->parameters == other.parameters()) && (d->fieldGroupName == other.fieldGroupName()) && (d->value == other.value());
93 }
94 
95 bool FieldGroup::operator!=(const FieldGroup &other) const
96 {
97  return !(other == *this);
98 }
99 
100 FieldGroup &FieldGroup::operator=(const FieldGroup &other)
101 {
102  if (this != &other) {
103  d = other.d;
104  }
105 
106  return *this;
107 }
108 
109 QString FieldGroup::toString() const
110 {
111  QString str = QLatin1String("FieldGroup {\n");
112  str += QStringLiteral(" FieldGroupName: %1 Value %2\n").arg(d->fieldGroupName).arg(d->value);
113  if (!d->parameters.isEmpty()) {
114  QString param;
115  QMap<QString, QStringList>::const_iterator it = d->parameters.constBegin();
116  const QMap<QString, QStringList>::const_iterator end = d->parameters.constEnd();
117  while (it != end) {
118  param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(',')));
119  ++it;
120  }
121  str += QStringLiteral(" parameters: %1\n").arg(param);
122  }
123  str += QLatin1String("}\n");
124  return str;
125 }
126 
127 QDataStream &KContacts::operator<<(QDataStream &s, const FieldGroup &fieldGroup)
128 {
129  return s << fieldGroup.d->parameters << fieldGroup.d->fieldGroupName << fieldGroup.d->value;
130 }
131 
132 QDataStream &KContacts::operator>>(QDataStream &s, FieldGroup &fieldGroup)
133 {
134  s >> fieldGroup.d->parameters >> fieldGroup.d->fieldGroupName >> fieldGroup.d->value;
135  return s;
136 }
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-2021 The KDE developers.
Generated on Fri Sep 24 2021 22:55:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.