7 #include "attributestorage_p.h"
11 AttributeStorage::AttributeStorage()
15 AttributeStorage::AttributeStorage(
const AttributeStorage &other)
16 : mModifiedAttributes(other.mModifiedAttributes)
17 , mDeletedAttributes(other.mDeletedAttributes)
19 for (
Attribute *attr : std::as_const(other.mAttributes)) {
20 mAttributes.insert(attr->type(), attr->clone());
24 AttributeStorage &AttributeStorage::operator=(
const AttributeStorage &other)
26 AttributeStorage
copy(other);
31 void AttributeStorage::swap(AttributeStorage &other) noexcept
34 swap(other.mAttributes, mAttributes);
35 swap(other.mModifiedAttributes, mModifiedAttributes);
36 swap(other.mDeletedAttributes, mDeletedAttributes);
39 AttributeStorage::~AttributeStorage()
41 qDeleteAll(mAttributes);
44 void AttributeStorage::addAttribute(
Attribute *attr)
48 Attribute *existing = mAttributes.value(type);
50 if (attr == existing) {
53 mAttributes.remove(type);
56 mAttributes.insert(type, attr);
57 markAttributeModified(type);
60 void AttributeStorage::removeAttribute(
const QByteArray &type)
62 mModifiedAttributes.erase(type);
63 mDeletedAttributes.insert(type);
64 delete mAttributes.take(type);
67 bool AttributeStorage::hasAttribute(
const QByteArray &type)
const
69 return mAttributes.contains(type);
74 return mAttributes.values();
77 void AttributeStorage::clearAttributes()
79 for (
Attribute *attr : std::as_const(mAttributes)) {
84 mModifiedAttributes.clear();
89 return mAttributes.value(type);
94 Attribute *attr = mAttributes.value(type);
96 markAttributeModified(type);
101 void AttributeStorage::markAttributeModified(
const QByteArray &type)
103 if (mAttributes.contains(type)) {
104 mDeletedAttributes.remove(type);
105 mModifiedAttributes.insert(type);
109 void AttributeStorage::resetChangeLog()
111 mModifiedAttributes.clear();
112 mDeletedAttributes.clear();
117 return mDeletedAttributes;
120 bool AttributeStorage::hasModifiedAttributes()
const
122 return !mModifiedAttributes.
empty();
125 std::vector<Attribute *> AttributeStorage::modifiedAttributes()
const
127 std::vector<Attribute *> ret;
128 ret.reserve(mModifiedAttributes.size());
129 for (
const auto &type : mModifiedAttributes) {
130 Attribute *attr = mAttributes.value(type);