KContacts

related.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2015-2019 Laurent Montel <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "related.h"
9 #include <QMap>
10 #include <QStringList>
11 #include <QDataStream>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN Related::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  relatedTo = other.relatedTo;
27  }
28 
29  QMap<QString, QStringList> parameters;
30  QString relatedTo;
31 };
32 
33 Related::Related()
34  : d(new Private)
35 {
36 }
37 
38 Related::Related(const Related &other)
39  : d(other.d)
40 {
41 }
42 
43 Related::Related(const QString &relatedTo)
44  : d(new Private)
45 {
46  d->relatedTo = relatedTo;
47 }
48 
49 Related::~Related()
50 {
51 }
52 
53 void Related::setRelated(const QString &relatedTo)
54 {
55  d->relatedTo = relatedTo;
56 }
57 
58 QString Related::related() const
59 {
60  return d->relatedTo;
61 }
62 
63 bool Related::isValid() const
64 {
65  return !d->relatedTo.isEmpty();
66 }
67 
68 void Related::setParameters(const QMap<QString, QStringList> &params)
69 {
70  d->parameters = params;
71 }
72 
73 QMap<QString, QStringList> Related::parameters() const
74 {
75  return d->parameters;
76 }
77 
78 bool Related::operator==(const Related &other) const
79 {
80  return (d->parameters == other.parameters()) && (d->relatedTo == other.related());
81 }
82 
83 bool Related::operator!=(const Related &other) const
84 {
85  return !(other == *this);
86 }
87 
88 Related &Related::operator=(const Related &other)
89 {
90  if (this != &other) {
91  d = other.d;
92  }
93 
94  return *this;
95 }
96 
97 QString Related::toString() const
98 {
99  QString str = QLatin1String("Related {\n");
100  str += QStringLiteral(" relatedTo: %1\n").arg(d->relatedTo);
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 Related &related)
116 {
117  return s << related.d->parameters << related.d->relatedTo;
118 }
119 
120 QDataStream &KContacts::operator>>(QDataStream &s, Related &related)
121 {
122  s >> related.d->parameters >> related.d->relatedTo;
123  return s;
124 }
Descripes a relationship of an Addressee.
Definition: related.h:18
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 Wed Aug 12 2020 22:55:05 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.