Akonadi

relation.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Christian Mollekopf <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "relation.h"
8 
9 #include "item.h"
10 
11 using namespace Akonadi;
12 
13 const char *Akonadi::Relation::GENERIC = "GENERIC";
14 
15 struct Q_DECL_HIDDEN Relation::Private : public QSharedData {
16  Item left;
17  Item right;
19  QByteArray remoteId;
20 };
21 
23  : d(new Private)
24 {
25 }
26 
27 Relation::Relation(const QByteArray &type, const Item &left, const Item &right)
28  : d(new Private)
29 {
30  d->left = left;
31  d->right = right;
32  d->type = type;
33 }
34 
35 Relation::Relation(const Relation &other) = default;
36 
37 Relation::Relation(Relation &&) noexcept = default;
38 
39 Relation::~Relation() = default;
40 
41 Relation &Relation::operator=(const Relation &) = default;
42 
43 Relation &Relation::operator=(Relation &&) noexcept = default;
44 
45 bool Relation::operator==(const Relation &other) const
46 {
47  if (isValid() && other.isValid()) {
48  return d->left == other.d->left
49  && d->right == other.d->right
50  && d->type == other.d->type
51  && d->remoteId == other.d->remoteId;
52  }
53  return false;
54 }
55 
56 bool Relation::operator!=(const Relation &other) const
57 {
58  return !operator==(other);
59 }
60 
61 void Relation::setLeft(const Item &left)
62 {
63  d->left = left;
64 }
65 
66 Item Relation::left() const
67 {
68  return d->left;
69 }
70 
71 void Relation::setRight(const Item &right)
72 {
73  d->right = right;
74 }
75 
76 Item Relation::right() const
77 {
78  return d->right;
79 }
80 
82 {
83  d->type = type;
84 }
85 
87 {
88  return d->type;
89 }
90 
92 {
93  d->remoteId = remoteId;
94 }
95 
97 {
98  return d->remoteId;
99 }
100 
101 bool Relation::isValid() const
102 {
103  return (d->left.isValid() || !d->left.remoteId().isEmpty()) && (d->right.isValid() || !d->right.remoteId().isEmpty()) && !d->type.isEmpty();
104 }
105 
106 uint Akonadi::qHash(const Relation &relation)
107 {
108  return (3 * qHash(relation.left()) + qHash(relation.right()) + qHash(relation.type()) + qHash(relation.remoteId()));
109 }
110 
111 QDebug &operator<<(QDebug &debug, const Relation &relation)
112 {
113  debug << "Akonadi::Relation( TYPE " << relation.type() << ", LEFT " << relation.left().id() << ", RIGHT " << relation.right().id() << ", REMOTEID " << relation.remoteId() << ")";
114  return debug;
115 }
Type type(const QString &mimeType)
void setType(const QByteArray &type)
Sets the type of the relation.
Definition: relation.cpp:81
An Akonadi Relation.
Definition: relation.h:39
Item left() const
Returns the identifier of the left side of the relation.
Definition: relation.cpp:66
Relation()
Creates an invalid relation.
Definition: relation.cpp:22
QTextStream & right(QTextStream &stream)
Item right() const
Returns the identifier of the right side of the relation.
Definition: relation.cpp:76
QByteArray type() const
Returns the type of the relation.
Definition: relation.cpp:86
QTextStream & left(QTextStream &stream)
void setRemoteId(const QByteArray &type)
Sets the remote id of the relation.
Definition: relation.cpp:91
QByteArray remoteId() const
Returns the remote id of the relation.
Definition: relation.cpp:96
void setLeft(const Item &item)
Sets the item of the left side of the relation.
Definition: relation.cpp:61
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
void setRight(const Akonadi::Item &item)
Sets the item of the right side of the relation.
Definition: relation.cpp:71
Helper integration between Akonadi and Qt.
static const char * GENERIC
The GENERIC type represents a generic relation between two items.
Definition: relation.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.