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 <QDataStream>
10 #include <QStringList>
11 
12 using namespace KContacts;
13 
14 class Q_DECL_HIDDEN Related::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  relatedTo = other.relatedTo;
26  }
27 
28  QMap<QString, QStringList> parameters;
29  QString relatedTo;
30 };
31 
32 Related::Related()
33  : d(new Private)
34 {
35 }
36 
37 Related::Related(const Related &other)
38  : d(other.d)
39 {
40 }
41 
42 Related::Related(const QString &relatedTo)
43  : d(new Private)
44 {
45  d->relatedTo = relatedTo;
46 }
47 
48 Related::~Related()
49 {
50 }
51 
52 void Related::setRelated(const QString &relatedTo)
53 {
54  d->relatedTo = relatedTo;
55 }
56 
57 QString Related::related() const
58 {
59  return d->relatedTo;
60 }
61 
62 bool Related::isValid() const
63 {
64  return !d->relatedTo.isEmpty();
65 }
66 
67 void Related::setParameters(const QMap<QString, QStringList> &params)
68 {
69  d->parameters = params;
70 }
71 
72 QMap<QString, QStringList> Related::parameters() const
73 {
74  return d->parameters;
75 }
76 
77 bool Related::operator==(const Related &other) const
78 {
79  return (d->parameters == other.parameters()) && (d->relatedTo == other.related());
80 }
81 
82 bool Related::operator!=(const Related &other) const
83 {
84  return !(other == *this);
85 }
86 
87 Related &Related::operator=(const Related &other)
88 {
89  if (this != &other) {
90  d = other.d;
91  }
92 
93  return *this;
94 }
95 
96 QString Related::toString() const
97 {
98  QString str = QLatin1String("Related {\n");
99  str += QStringLiteral(" relatedTo: %1\n").arg(d->relatedTo);
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 Related &related)
115 {
116  return s << related.d->parameters << related.d->relatedTo;
117 }
118 
119 QDataStream &KContacts::operator>>(QDataStream &s, Related &related)
120 {
121  s >> related.d->parameters >> related.d->relatedTo;
122  return s;
123 }
Descripes a relationship of an Addressee.
Definition: related.h:19
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 Thu Jun 17 2021 22:54:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.