KContacts

role.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 "role.h"
9 #include <QMap>
10 #include <QStringList>
11 #include <QDataStream>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN Role::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  role = other.role;
27  }
28 
29  QMap<QString, QStringList> parameters;
30  QString role;
31 };
32 
33 Role::Role()
34  : d(new Private)
35 {
36 }
37 
38 Role::Role(const Role &other)
39  : d(other.d)
40 {
41 }
42 
43 Role::Role(const QString &role)
44  : d(new Private)
45 {
46  d->role = role;
47 }
48 
49 Role::~Role()
50 {
51 }
52 
53 void Role::setRole(const QString &role)
54 {
55  d->role = role;
56 }
57 
58 QString Role::role() const
59 {
60  return d->role;
61 }
62 
63 bool Role::isValid() const
64 {
65  return !d->role.isEmpty();
66 }
67 
68 void Role::setParameters(const QMap<QString, QStringList> &params)
69 {
70  d->parameters = params;
71 }
72 
73 QMap<QString, QStringList> Role::parameters() const
74 {
75  return d->parameters;
76 }
77 
78 bool Role::operator==(const Role &other) const
79 {
80  return (d->parameters == other.parameters()) && (d->role == other.role());
81 }
82 
83 bool Role::operator!=(const Role &other) const
84 {
85  return !(other == *this);
86 }
87 
88 Role &Role::operator=(const Role &other)
89 {
90  if (this != &other) {
91  d = other.d;
92  }
93 
94  return *this;
95 }
96 
97 QString Role::toString() const
98 {
99  QString str = QLatin1String("Role {\n");
100  str += QStringLiteral(" role: %1\n").arg(d->role);
101  if (!d->parameters.isEmpty()) {
102  QString param;
103  QMap<QString, QStringList>::const_iterator it = d->parameters.constBegin();
104  const QMap<QString, QStringList>::const_iterator end = d->parameters.constEnd();
105  while (it != end) {
106  param += QStringLiteral("%1 %2").arg(it.key(), it.value().join(QLatin1Char(',')));
107  ++it;
108  }
109  str += QStringLiteral(" parameters: %1\n").arg(param);
110  }
111  str += QLatin1String("}\n");
112  return str;
113 }
114 
115 QDataStream &KContacts::operator<<(QDataStream &s, const Role &role)
116 {
117  return s << role.d->parameters << role.d->role;
118 }
119 
120 QDataStream &KContacts::operator>>(QDataStream &s, Role &role)
121 {
122  s >> role.d->parameters >> role.d->role;
123  return s;
124 }
Class that holds a Role for a contact.
Definition: role.h:20
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 Sat Aug 8 2020 22:53:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.