7#include "attributefactory.h" 
    9#include "collectionannotationsattribute.h" 
   10#include "collectionidentificationattribute.h" 
   11#include "collectionquotaattribute.h" 
   12#include "collectionrightsattribute_p.h" 
   13#include "entityannotationsattribute.h" 
   14#include "entitydeletedattribute.h" 
   15#include "entitydisplayattribute.h" 
   16#include "entityhiddenattribute.h" 
   17#include "favoritecollectionattribute.h" 
   18#include "indexpolicyattribute.h" 
   19#include "persistentsearchattribute.h" 
   20#include "tagattribute.h" 
   24#include <unordered_map> 
   35class DefaultAttribute : 
public Attribute
 
   38    explicit DefaultAttribute(
const QByteArray &type, 
const QByteArray &value = QByteArray())
 
   44    DefaultAttribute(
const DefaultAttribute &) = 
delete;
 
   45    DefaultAttribute &operator=(
const DefaultAttribute &) = 
delete;
 
   47    QByteArray type()
 const override 
   52    Attribute *clone()
 const override 
   54        return new DefaultAttribute(mType, mValue);
 
   57    QByteArray serialized()
 const override 
   62    void deserialize(
const QByteArray &data)
 override 
   68    QByteArray mType, mValue;
 
   74class StaticAttributeFactory : 
public AttributeFactory
 
   97    bool initialized = 
false;
 
  100Q_GLOBAL_STATIC(StaticAttributeFactory, s_attributeInstance) 
 
  104using Akonadi::Internal::s_attributeInstance;
 
  109class AttributeFactoryPrivate
 
  112    std::unordered_map<QByteArray, std::unique_ptr<Attribute>> attributes;
 
  117    s_attributeInstance->init();
 
  118    return s_attributeInstance;
 
  121AttributeFactory::AttributeFactory()
 
  122    : d(new AttributeFactoryPrivate())
 
  126AttributeFactory::~AttributeFactory() = 
default;
 
  131    Q_ASSERT(!attr->type().contains(
' ') && !attr->type().contains(
'\'') && !attr->type().contains(
'"'));
 
  132    auto it = d->attributes.find(attr->type());
 
  133    if (it != d->attributes.end()) {
 
  134        d->attributes.erase(it);
 
  136    d->attributes.emplace(attr->type(), std::move(attr));
 
  141    auto attr = self()->d->attributes.find(type);
 
  142    if (attr == self()->d->attributes.cend()) {
 
  143        return new Internal::DefaultAttribute(type);
 
  146    return attr->second->
clone();
 
 
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.
 
Helper integration between Akonadi and Qt.