7#include "attributestorage_p.h"
19 AttributeStoragePrivate() =
default;
20 AttributeStoragePrivate(AttributeStoragePrivate &other)
22 , atributes(other.atributes)
23 , modifiedAttributes(other.modifiedAttributes)
24 , deletedAttributes(other.deletedAttributes)
26 for (
Attribute *attr : std::as_const(atributes)) {
27 atributes.insert(attr->type(), attr->clone());
31 ~AttributeStoragePrivate()
33 qDeleteAll(atributes);
37 std::set<QByteArray> modifiedAttributes;
43AttributeStorage::AttributeStorage()
44 : d(new AttributeStoragePrivate)
48AttributeStorage::AttributeStorage(
const AttributeStorage &other)
53AttributeStorage::AttributeStorage(AttributeStorage &&other)
noexcept
58AttributeStorage &AttributeStorage::operator=(
const AttributeStorage &other)
64AttributeStorage &AttributeStorage::operator=(AttributeStorage &&other)
noexcept
70AttributeStorage::~AttributeStorage() =
default;
72void AttributeStorage::detach()
77void AttributeStorage::addAttribute(
Attribute *attr)
81 Attribute *existing = d->atributes.value(type);
83 if (attr == existing) {
86 d->atributes.remove(type);
89 d->atributes.insert(type, attr);
90 markAttributeModified(type);
93void AttributeStorage::removeAttribute(
const QByteArray &type)
95 d->modifiedAttributes.erase(type);
96 d->deletedAttributes.insert(type);
97 delete d->atributes.take(type);
100bool AttributeStorage::hasAttribute(
const QByteArray &type)
const
102 return d->atributes.contains(type);
107 return d->atributes.values();
110void AttributeStorage::clearAttributes()
112 for (
Attribute *attr : std::as_const(d->atributes)) {
113 d->deletedAttributes.insert(attr->
type());
116 d->atributes.
clear();
117 d->modifiedAttributes.clear();
122 return d->atributes.value(type);
127 Attribute *attr = d->atributes.value(type);
129 markAttributeModified(type);
134void AttributeStorage::markAttributeModified(
const QByteArray &type)
136 if (d->atributes.contains(type)) {
137 d->deletedAttributes.remove(type);
138 d->modifiedAttributes.insert(type);
142void AttributeStorage::resetChangeLog()
144 d->modifiedAttributes.clear();
145 d->deletedAttributes.clear();
150 return d->deletedAttributes;
153bool AttributeStorage::hasModifiedAttributes()
const
155 return !d->modifiedAttributes.
empty();
158std::vector<Attribute *> AttributeStorage::modifiedAttributes()
const
160 std::vector<Attribute *> ret;
161 ret.reserve(d->modifiedAttributes.size());
162 for (
const auto &type : d->modifiedAttributes) {
163 Attribute *attr = d->atributes.value(type);
Provides interface for custom attributes for Entity.
virtual QByteArray type() const =0
Returns the type of the attribute.
Helper integration between Akonadi and Qt.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)