20#include "attributefactory.h"
22#include "collectionquotaattribute.h"
23#include "collectionrightsattribute_p.h"
24#include "entitydisplayattribute.h"
25#include "entityhiddenattribute.h"
26#include "indexpolicyattribute.h"
27#include "persistentsearchattribute.h"
28#include "entitydeletedattribute.h"
29#include "tagattribute.h"
30#include "entityannotationsattribute.h"
34#include <QtCore/QHash>
47 explicit DefaultAttribute(
const QByteArray &type,
const QByteArray &value = QByteArray())
52 QByteArray type()
const
58 return new DefaultAttribute(mType, mValue);
61 QByteArray serialized()
const
65 void deserialize(
const QByteArray &data)
71 QByteArray mType, mValue;
80 StaticAttributeFactory()
82 , initialized(false) {}
90 AttributeFactory::registerAttribute<CollectionQuotaAttribute>();
91 AttributeFactory::registerAttribute<CollectionRightsAttribute>();
92 AttributeFactory::registerAttribute<EntityDisplayAttribute>();
93 AttributeFactory::registerAttribute<EntityHiddenAttribute>();
94 AttributeFactory::registerAttribute<IndexPolicyAttribute>();
95 AttributeFactory::registerAttribute<PersistentSearchAttribute>();
96 AttributeFactory::registerAttribute<EntityDeletedAttribute>();
97 AttributeFactory::registerAttribute<EntityAnnotationsAttribute>();
98 AttributeFactory::registerAttribute<TagAttribute>();
103K_GLOBAL_STATIC(StaticAttributeFactory, s_attributeInstance)
107using Akonadi::Internal::s_attributeInstance;
112class AttributeFactory::Private
115 QHash<QByteArray, Attribute *> attributes;
120 s_attributeInstance->init();
121 return s_attributeInstance;
124AttributeFactory::AttributeFactory()
129AttributeFactory::~ AttributeFactory()
131 qDeleteAll(d->attributes);
138 Q_ASSERT(!attr->
type().contains(
' ') && !attr->
type().contains(
'\'') && !attr->
type().contains(
'"'));
139 QHash<QByteArray, Attribute *>::Iterator it = d->attributes.find(attr->
type());
140 if (it != d->attributes.end()) {
142 d->attributes.erase(it);
144 d->attributes.insert(attr->
type(), attr);
149 Attribute *attr = self()->d->attributes.value(type);
151 return attr->
clone();
153 return new Internal::DefaultAttribute(type);
Provides the functionality of registering and creating arbitrary entity attributes.
static Attribute * createAttribute(const QByteArray &type)
Creates an entity attribute object of the given type.
static void registerAttribute()
Registers a custom attribute of type T.
Provides interface for custom attributes for Entity.
virtual Attribute * clone() const =0
Creates a copy of this attribute.
virtual QByteArray type() const =0
Returns the type of the attribute.
FreeBusyManager::Singleton.