8#include "akonadicore_debug.h"
11#include "tagattribute.h"
20size_t Akonadi::qHash(
const Tag &tag,
size_t seed)
noexcept
22 return ::qHash(tag.id(), seed);
26 : d_ptr(new TagPrivate)
31 : d_ptr(new TagPrivate)
37 : d_ptr(new TagPrivate)
39 d_ptr->gid = name.toUtf8();
43Tag::Tag(
const Tag &) =
default;
44Tag::Tag(
Tag &&) noexcept = default;
47Tag &
Tag::operator=(const
Tag &) = default;
48Tag &
Tag::operator=(
Tag &&) noexcept = default;
50bool Tag::operator==(const
Tag &other)
const
53 if (isValid() && other.isValid()) {
54 return d_ptr->id == other.d_ptr->id;
58 if (!d_ptr->gid.isEmpty() || !other.d_ptr->gid.isEmpty()) {
59 return d_ptr->gid == other.d_ptr->gid;
63 return !isValid() && !other.isValid();
66bool Tag::operator!=(
const Tag &other)
const
68 return !operator==(other);
71Tag Tag::fromUrl(
const QUrl &url)
73 if (
url.scheme() != QLatin1StringView(
"akonadi")) {
77 const QString tagStr = QUrlQuery(
url).queryItemValue(QStringLiteral(
"tag"));
93 url.setScheme(QStringLiteral(
"akonadi"));
100 d_ptr->mAttributeStorage.addAttribute(attr);
105 d_ptr->mAttributeStorage.removeAttribute(type);
110 return d_ptr->mAttributeStorage.hasAttribute(type);
115 return d_ptr->mAttributeStorage.attributes();
120 d_ptr->mAttributeStorage.clearAttributes();
125 return d_ptr->mAttributeStorage.attribute(type);
130 markAttributeModified(type);
131 return d_ptr->mAttributeStorage.attribute(type);
136 d_ptr->id = identifier;
154void Tag::setRemoteId(
const QByteArray &remoteId)
156 d_ptr->remoteId = remoteId;
159QByteArray Tag::remoteId()
const
161 return d_ptr->remoteId;
164void Tag::setName(
const QString &name)
166 if (!name.isEmpty()) {
168 attr->setDisplayName(name);
172QString Tag::name()
const
175 const QString
displayName = attr ? attr->displayName() : QString();
179void Tag::setParent(
const Tag &parent)
181 d_ptr->parent.reset(
new Tag(parent));
184Tag Tag::parent()
const
186 if (!d_ptr->parent) {
189 return *d_ptr->parent;
192void Tag::setType(
const QByteArray &type)
197QByteArray Tag::type()
const
202bool Tag::isValid()
const
204 return d_ptr->id >= 0;
209 return (d_ptr->type.isEmpty() || d_ptr->type ==
PLAIN);
215 debug.
nospace() <<
"Akonadi::Tag(ID " << tag.
id() <<
", GID " << tag.gid() <<
", parent tag ID " << tag.parent().
id() <<
")";
233 qCWarning(AKONADICORE_LOG) <<
"Found attribute of unknown type" << type <<
". Did you forget to call AttributeFactory::registerAttribute()?";
237void Tag::markAttributeModified(
const QByteArray &type)
239 d_ptr->mAttributeStorage.markAttributeModified(type);
Provides interface for custom attributes for Entity.
QList< Attribute * > List
Describes a list of attributes.
Id id() const
Returns the unique identifier of the tag.
bool isImmutable() const
Returns true if the tag is immutable (cannot be modified after creation).
void removeAttribute()
Removes and deletes the attribute of the requested type.
static const char GENERIC[]
The GENERIC type has the following properties:
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
@ AddIfMissing
Creates the attribute if it is missing.
const T * attribute() const
Returns the attribute of the requested type or 0 if it is not available.
static const char PLAIN[]
The PLAIN type has the following properties:
void clearAttributes()
Removes and deletes all attributes of the entity.
Attribute::List attributes() const
Returns a list of all attributes of the entity.
QUrl url() const
Returns the url of the tag.
bool hasAttribute() const
Returns whether the entity has an attribute of the requested type.
void setId(Id identifier)
Sets the unique identifier of the tag.
static Tag genericTag(const QString &name)
Returns a GENERIC tag with the given name and a valid gid.
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
Helper integration between Akonadi and Qt.
QByteArray mid(qsizetype pos, qsizetype len) const const
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
QString number(double n, char format, int precision)
qlonglong toLongLong(bool *ok, int base) const const
QByteArray toByteArray(StringFormat mode) const const