diff --git a/lib/include/cc_tools_qt/ToolsField.h b/lib/include/cc_tools_qt/ToolsField.h index 45e11e5..8bad456 100644 --- a/lib/include/cc_tools_qt/ToolsField.h +++ b/lib/include/cc_tools_qt/ToolsField.h @@ -20,7 +20,9 @@ #include "cc_tools_qt/Api.h" +#include #include +#include #include #include @@ -75,19 +77,29 @@ class CC_API ToolsField const Members& getMembers() const; void setMembers(Members&& members); + void forceReadOnly(); + bool isReadOnly() const; + + void forceHiddenSerialization(); + bool isHiddenSerialization() const; + protected: virtual const char* nameImpl() const = 0; virtual std::size_t lengthImpl() const = 0; virtual bool validImpl() const = 0; + virtual bool isReadOnlyImpl() const = 0; + virtual bool isHiddenSerializationImpl() const = 0; virtual SerialisedSeq getSerialisedValueImpl() const = 0; virtual bool setSerialisedValueImpl(const SerialisedSeq& value) = 0; virtual void dispatchImpl(ToolsFieldHandler& handler) = 0; virtual Ptr cloneImpl() = 0; virtual bool canWriteImpl() const = 0; virtual void resetImpl() = 0; + private: Members m_members; + QVariantMap m_props; }; using ToolsFieldPtr = ToolsField::Ptr; diff --git a/lib/include/cc_tools_qt/details/ToolsArrayListFieldImpl.h b/lib/include/cc_tools_qt/details/ToolsArrayListFieldImpl.h index d2c7196..41235c5 100644 --- a/lib/include/cc_tools_qt/details/ToolsArrayListFieldImpl.h +++ b/lib/include/cc_tools_qt/details/ToolsArrayListFieldImpl.h @@ -49,6 +49,7 @@ class ToolsArrayListFieldImpl : public ToolsFieldBase; @@ -263,35 +264,8 @@ class ToolsArrayListFieldImpl : public ToolsFieldBasecanWrite()); } } + + Base::setMembers(std::move(mems)); } void refreshMembersInternal(NoFeatureTag) diff --git a/lib/include/cc_tools_qt/details/ToolsFieldBase.h b/lib/include/cc_tools_qt/details/ToolsFieldBase.h index 1ded357..48413fa 100644 --- a/lib/include/cc_tools_qt/details/ToolsFieldBase.h +++ b/lib/include/cc_tools_qt/details/ToolsFieldBase.h @@ -75,6 +75,16 @@ class ToolsFieldBase : public TBase return m_field.valid(); } + virtual bool isReadOnlyImpl() const override + { + return Field::hasFixedValue(); + } + + virtual bool isHiddenSerializationImpl() const override + { + return Field::hasEmptySerialization(); + } + Field& field() { return m_field; diff --git a/lib/src/ToolsField.cpp b/lib/src/ToolsField.cpp index 425a30b..44504a1 100644 --- a/lib/src/ToolsField.cpp +++ b/lib/src/ToolsField.cpp @@ -19,10 +19,30 @@ #include "cc_tools_qt/ToolsField.h" #include +#include +#include namespace cc_tools_qt { +namespace +{ + +const QString& readOnlyProp() +{ + static const QString Str("cc.read_only"); + return Str; +} + +const QString& hiddenSerializationProp() +{ + static const QString Str("cc.hidden_ser"); + return Str; +} + +} // namespace + + ToolsField::ToolsField() = default; ToolsField::~ToolsField() noexcept = default; @@ -104,6 +124,7 @@ ToolsField::Ptr ToolsField::clone() } auto ptr = cloneImpl(); ptr->setMembers(std::move(clonedMembers)); + ptr->m_props = m_props; return ptr; } @@ -130,6 +151,56 @@ const ToolsField::Members& ToolsField::getMembers() const void ToolsField::setMembers(Members&& members) { m_members = std::move(members); + for (auto& m : m_members) { + using CheckFunc = bool (ToolsField::*)() const; + using ForceFunc = void (ToolsField::*)(); + static const std::vector> List = { + {&ToolsField::isReadOnly, &ToolsField::forceReadOnly}, + }; + + assert(m); + for (auto& funcs : List) { + if ((m.get()->*funcs.first)()) { + (m.get()->*funcs.second)(); + } + } + } +} + +void ToolsField::forceReadOnly() +{ + m_props[readOnlyProp()] = true; + for (auto& m : m_members) { + assert(m); + m->forceReadOnly(); + } +} + +bool ToolsField::isReadOnly() const +{ + if (m_props.contains(readOnlyProp())) { + return true; + } + + return isReadOnlyImpl(); +} + +void ToolsField::forceHiddenSerialization() +{ + m_props[hiddenSerializationProp()] = true; + for (auto& m : m_members) { + assert(m); + m->forceHiddenSerialization(); + } +} + +bool ToolsField::isHiddenSerialization() const +{ + if (m_props.contains(hiddenSerializationProp())) { + return true; + } + + return isHiddenSerializationImpl(); } } // namespace cc_tools_qt