File indexing completed on 2024-06-23 05:06:53
0001 /* 0002 SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadicore_export.h" 0010 #include <stddef.h> 0011 0012 namespace Akonadi 0013 { 0014 class Relation; 0015 0016 AKONADICORE_EXPORT size_t qHash(const Akonadi::Relation &, size_t seed = 0) noexcept; 0017 } 0018 0019 #include <QByteArray> 0020 #include <QDebug> 0021 #include <QSharedDataPointer> 0022 0023 namespace Akonadi 0024 { 0025 class Item; 0026 class RelationPrivate; 0027 0028 /** 0029 * An Akonadi Relation. 0030 * 0031 * A Relation object represents an relation between two Akonadi items. 0032 * 0033 * An example usecase could be a association of a note with an email. The note (that for instance contains personal notes for the email), 0034 * can be stored independently but is easily retrieved by asking for relations the email. 0035 * 0036 * The relation type allows to distinguish various types of relations that could for instance be bidirectional or not. 0037 * 0038 * @since 4.15 0039 */ 0040 class AKONADICORE_EXPORT Relation 0041 { 0042 public: 0043 using List = QList<Relation>; 0044 0045 /** 0046 * The GENERIC type represents a generic relation between two items. 0047 */ 0048 static const char *GENERIC; 0049 0050 /** 0051 * Creates an invalid relation. 0052 */ 0053 Relation(); 0054 0055 /** 0056 * Creates a relation 0057 */ 0058 explicit Relation(const QByteArray &type, const Item &left, const Item &right); 0059 0060 Relation(const Relation &); 0061 Relation(Relation &&) noexcept; 0062 ~Relation(); 0063 0064 Relation &operator=(const Relation &); 0065 Relation &operator=(Relation &&) noexcept; 0066 0067 bool operator==(const Relation &) const; 0068 bool operator!=(const Relation &) const; 0069 0070 /** 0071 * Sets the @p item of the left side of the relation. 0072 */ 0073 void setLeft(const Item &item); 0074 0075 /** 0076 * Returns the identifier of the left side of the relation. 0077 */ 0078 [[nodiscard]] Item left() const; 0079 0080 /** 0081 * Sets the @p item of the right side of the relation. 0082 */ 0083 void setRight(const Akonadi::Item &item); 0084 0085 /** 0086 * Returns the identifier of the right side of the relation. 0087 */ 0088 [[nodiscard]] Item right() const; 0089 0090 /** 0091 * Sets the type of the relation. 0092 */ 0093 void setType(const QByteArray &type); 0094 0095 /** 0096 * Returns the type of the relation. 0097 */ 0098 [[nodiscard]] QByteArray type() const; 0099 0100 /** 0101 * Sets the remote id of the relation. 0102 */ 0103 void setRemoteId(const QByteArray &type); 0104 0105 /** 0106 * Returns the remote id of the relation. 0107 */ 0108 [[nodiscard]] QByteArray remoteId() const; 0109 0110 [[nodiscard]] bool isValid() const; 0111 0112 private: 0113 QSharedDataPointer<RelationPrivate> d; 0114 }; 0115 0116 } 0117 0118 AKONADICORE_EXPORT QDebug &operator<<(QDebug &debug, const Akonadi::Relation &tag); 0119 0120 Q_DECLARE_METATYPE(Akonadi::Relation) 0121 Q_DECLARE_METATYPE(Akonadi::Relation::List) 0122 Q_DECLARE_METATYPE(QSet<Akonadi::Relation>) 0123 Q_DECLARE_TYPEINFO(Akonadi::Relation, Q_RELOCATABLE_TYPE);