Akonadi

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

KDE's Doxygen guidelines are available online.