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>
36 using namespace Akonadi;
47 explicit DefaultAttribute(
const QByteArray &type,
const QByteArray &value = QByteArray() ) :
52 QByteArray type()
const {
return mType; }
55 return new DefaultAttribute( mType, mValue );
58 QByteArray serialized()
const {
return mValue; }
59 void deserialize(
const QByteArray &data ) { mValue = data; }
62 QByteArray mType, mValue;
79 AttributeFactory::registerAttribute<CollectionQuotaAttribute>();
80 AttributeFactory::registerAttribute<CollectionRightsAttribute>();
81 AttributeFactory::registerAttribute<EntityDisplayAttribute>();
82 AttributeFactory::registerAttribute<EntityHiddenAttribute>();
83 AttributeFactory::registerAttribute<IndexPolicyAttribute>();
84 AttributeFactory::registerAttribute<PersistentSearchAttribute>();
85 AttributeFactory::registerAttribute<EntityDeletedAttribute>();
86 AttributeFactory::registerAttribute<EntityAnnotationsAttribute>();
87 AttributeFactory::registerAttribute<TagAttribute>();
92 K_GLOBAL_STATIC( StaticAttributeFactory, s_attributeInstance )
96 using Akonadi::Internal::s_attributeInstance;
101 class AttributeFactory::Private
104 QHash<QByteArray, Attribute*> attributes;
109 s_attributeInstance->init();
110 return s_attributeInstance;
113 AttributeFactory::AttributeFactory()
118 AttributeFactory::~ AttributeFactory()
120 qDeleteAll( d->attributes );
127 Q_ASSERT( !attr->
type().contains(
' ' ) && !attr->
type().contains(
'\'' ) && !attr->
type().contains(
'"' ) );
128 QHash<QByteArray, Attribute*>::Iterator it = d->attributes.find( attr->
type() );
129 if ( it != d->attributes.end() ) {
131 d->attributes.erase( it );
133 d->attributes.insert( attr->
type(), attr );
138 Attribute *attr =
self()->d->attributes.value( type );
140 return attr->
clone();
142 return new Internal::DefaultAttribute( type );
Provides the functionality of registering and creating arbitrary entity attributes.
Provides interface for custom attributes for Entity.
static void registerAttribute()
Registers a custom attribute of type T.
static Attribute * createAttribute(const QByteArray &type)
Creates an entity attribute object of the given type.
virtual Attribute * clone() const =0
Creates a copy of this attribute.
virtual QByteArray type() const =0
Returns the type of the attribute.