KContacts

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

KDE's Doxygen guidelines are available online.