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 class Akonadi::RelationPrivate : public QSharedData
16 {
17 public:
18  Item left;
19  Item right;
21  QByteArray remoteId;
22 };
23 
25  : d(new RelationPrivate)
26 {
27 }
28 
29 Relation::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 
37 Relation::Relation(const Relation &other) = default;
38 
39 Relation::Relation(Relation &&) noexcept = default;
40 
41 Relation::~Relation() = default;
42 
43 Relation &Relation::operator=(const Relation &) = default;
44 
45 Relation &Relation::operator=(Relation &&) noexcept = default;
46 
47 bool 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 
55 bool Relation::operator!=(const Relation &other) const
56 {
57  return !operator==(other);
58 }
59 
60 void Relation::setLeft(const Item &left)
61 {
62  d->left = left;
63 }
64 
66 {
67  return d->left;
68 }
69 
70 void Relation::setRight(const Item &right)
71 {
72  d->right = right;
73 }
74 
76 {
77  return d->right;
78 }
79 
80 void Relation::setType(const QByteArray &type)
81 {
82  d->type = type;
83 }
84 
86 {
87  return d->type;
88 }
89 
90 void Relation::setRemoteId(const QByteArray &remoteId)
91 {
92  d->remoteId = remoteId;
93 }
94 
96 {
97  return d->remoteId;
98 }
99 
100 bool 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 
105 uint Akonadi::qHash(const Relation &relation)
106 {
107  return (3 * qHash(relation.left()) + qHash(relation.right()) + qHash(relation.type()) + qHash(relation.remoteId()));
108 }
109 
110 QDebug &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 }
QTextStream & right(QTextStream &stream)
Item left() const
Returns the identifier of the left side of the relation.
Definition: relation.cpp:65
QTextStream & left(QTextStream &stream)
Relation()
Creates an invalid relation.
Definition: relation.cpp:24
QByteArray remoteId() const
Returns the remote id of the relation.
Definition: relation.cpp:95
void setType(const QByteArray &type)
Sets the type of the relation.
Definition: relation.cpp:80
QDataStream & operator<<(QDataStream &out, const KDateTime &dateTime)
An Akonadi Relation.
Definition: relation.h:39
QByteArray type() const
Returns the type of the relation.
Definition: relation.cpp:85
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
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
void setRight(const Akonadi::Item &item)
Sets the item of the right side of the relation.
Definition: relation.cpp:70
static const char * GENERIC
The GENERIC type represents a generic relation between two items.
Definition: relation.h:47
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
Id id() const
Returns the unique identifier of the item.
Definition: item.cpp:63
Item right() const
Returns the identifier of the right side of the relation.
Definition: relation.cpp:75
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.