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

KDE's Doxygen guidelines are available online.