Skip to content

Commit

Permalink
Cleanup of the optional field properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Oct 31, 2024
1 parent a917996 commit 7a2df7b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 168 deletions.
13 changes: 0 additions & 13 deletions app/cc_view/src/widget/field/OptionalFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ void OptionalFieldWidget::editEnabledUpdatedImpl()
m_field->setEditEnabled(isEditEnabled());
}

void OptionalFieldWidget::updatePropertiesImpl(const QVariantMap& props)
{
property::field::Optional optProps(props);
auto& fieldPropsMap = optProps.field();
assert(m_field);
m_field->updateProperties(fieldPropsMap);
refreshInternal();

bool uncheckable = optProps.isUncheckable();
m_ui.m_optCheckBox->setHidden(uncheckable);
m_ui.m_optSep->setHidden(uncheckable);
}

void OptionalFieldWidget::fieldUpdated()
{
if (!m_fieldPtr->canWrite()) {
Expand Down
1 change: 0 additions & 1 deletion app/cc_view/src/widget/field/OptionalFieldWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class OptionalFieldWidget : public FieldWidget
virtual ToolsField& fieldImpl() override;
virtual void refreshImpl() override;
virtual void editEnabledUpdatedImpl() override;
virtual void updatePropertiesImpl(const QVariantMap& props) override;

private slots:
void fieldUpdated();
Expand Down
24 changes: 3 additions & 21 deletions demo/cc_plugin/message/Optionals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,17 @@ QVariantMap createField1Properties()

QVariantMap createField2Properties()
{
return
cc::property::field::ForField<ProtMsg::Field_field2>()
.field(
cc::property::field::ForField<ProtMsg::Field_field2::Field>()
.asMap())
.uncheckable()
.asMap();
return cc::property::field::ForField<ProtMsg::Field_field2>().asMap();
}

QVariantMap createField3Properties()
{
return
cc::property::field::ForField<ProtMsg::Field_field3>()
.field(
cc::property::field::ForField<ProtMsg::Field_field3::Field>()
.asMap())
.uncheckable()
.asMap();
return cc::property::field::ForField<ProtMsg::Field_field3>().asMap();
}

QVariantMap createField4Properties()
{
return
cc::property::field::ForField<ProtMsg::Field_field4>()
.field(
cc::property::field::ForField<ProtMsg::Field_field4::Field>()
.asMap())
.uncheckable()
.asMap();
return cc::property::field::ForField<ProtMsg::Field_field4>().asMap();
}

QVariantList createFieldsProperties()
Expand Down
5 changes: 5 additions & 0 deletions lib/include/cc_tools_qt/ToolsExtraInfoMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class ToolsExtraInfoMessage : public
return false;
}

virtual FieldsList transportFieldsImpl() override
{
return FieldsList();
}

virtual FieldsList payloadFieldsImpl() override
{
auto fields = Base::payloadFieldsImpl();
Expand Down
11 changes: 11 additions & 0 deletions lib/include/cc_tools_qt/ToolsInvalidMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ class ToolsInvalidMessage : public
ToolsInvalidMessage<TBase>
>
{
using Base =
cc_tools_qt::ToolsMessageBase<
TBase,
details::ToolInvalidMessageImpl,
ToolsInvalidMessage<TBase>
>;
public:
using FieldsList = typename Base::FieldsList;
virtual ~ToolsInvalidMessage() noexcept = default;

protected:
Expand Down Expand Up @@ -94,6 +101,10 @@ class ToolsInvalidMessage : public
return false;
}

virtual FieldsList transportFieldsImpl() override
{
return FieldsList();
}
};

} // namespace cc_tools_qt
Expand Down
13 changes: 13 additions & 0 deletions lib/include/cc_tools_qt/ToolsRawDataMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ class ToolsRawDataMessage : public
ToolsRawDataMessage<TBase>
>
{
using Base =
cc_tools_qt::ToolsMessageBase<
TBase,
details::ToolsRawDataMessageImpl,
ToolsRawDataMessage<TBase>
>;
public:
using FieldsList = typename Base::FieldsList;

virtual ~ToolsRawDataMessage() noexcept = default;

protected:
Expand Down Expand Up @@ -105,6 +113,11 @@ class ToolsRawDataMessage : public
return false;
}

virtual FieldsList transportFieldsImpl() override
{
return FieldsList();
}

private:

static QVariantList createFieldsProperties()
Expand Down
62 changes: 1 addition & 61 deletions lib/include/cc_tools_qt/property/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,66 +140,6 @@ class CommonBase : public Common
CommonBase& operator=(CommonBase&&) = default;
};

/// @brief Class to contain all the properties relevant to
/// @b comms::field::Optional fields.
/// @headerfile cc_tools_qt/property/field.h
class CC_API Optional : public CommonBase<Optional>
{
typedef CommonBase<Optional> Base;
public:

/// @brief Default constructor
Optional();

/// @brief Copy constructor
Optional(const Optional&);

/// @brief Move constructor
Optional(Optional&&);

/// @brief Construct from QVariantMap
Optional(const QVariantMap& props);

/// @brief Construct from QVariant containing QVariantMap
Optional(const QVariant& props);

/// @brief Destructor
~Optional() noexcept;

/// @brief Copy assignment
Optional& operator=(const Optional&);

/// @brief Move assignment
Optional& operator=(Optional&&);

/// @brief Get access to contained field's properties
const QVariantMap& field() const;

/// @brief Set contained field's properties.
Optional& field(QVariantMap&& fieldProps);

/// @brief Set contained field's properties.
Optional& field(const QVariantMap& fieldProps);

/// @brief Check field is uncheckable.
/// @details Uncheckable means that the user cannot manually mark the field
/// as existing/missing independently.
bool isUncheckable() const;

/// @brief (Un)Mark the field uncheckable.
Optional& uncheckable(bool value = true);

/// @brief Retrieve all properties as map.
QVariantMap asMap() const;

private:
void getFrom(const QVariantMap& props);

QVariantMap m_field;
bool m_uncheckable = false;
};


/// @brief Class to contain all the properties relevant to
/// @b comms::field::Variant fields.
/// @headerfile cc_tools_qt/property/field.h
Expand Down Expand Up @@ -316,7 +256,7 @@ struct ForTag<comms::field::tag::ArrayList>
template <>
struct ForTag<comms::field::tag::Optional>
{
typedef cc_tools_qt::property::field::Optional Type;
using Type = cc_tools_qt::property::field::Common;
};

template <>
Expand Down
72 changes: 0 additions & 72 deletions lib/src/property/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ const QString& dataKey()
return Str;
}

const QString& uncheckableKey()
{
static const QString Str("cc.uncheckable");
return Str;
}

const QString& indexHiddenKey()
{
static const QString Str("cc.index_hidden");
Expand Down Expand Up @@ -85,72 +79,6 @@ QVariantMap Common::asMap() const
return props;
}

Optional::Optional() = default;
Optional::Optional(const Optional&) = default;
Optional::Optional(Optional&&) = default;
Optional::Optional(const QVariantMap& props)
: Base(props)
{
getFrom(props);
}

Optional::Optional(const QVariant& props)
: Base(props)
{
if (props.isValid() && props.canConvert<QVariantMap>()) {
getFrom(props.value<QVariantMap>());
}
}

Optional::~Optional() noexcept = default;

Optional& Optional::operator=(const Optional&) = default;
Optional& Optional::operator=(Optional&&) = default;

const QVariantMap& Optional::field() const
{
return m_field;
}

Optional& Optional::field(QVariantMap&& fieldProps)
{
m_field = std::move(fieldProps);
return *this;
}

Optional& Optional::field(const QVariantMap& fieldProps)
{
m_field = fieldProps;
return *this;
}

bool Optional::isUncheckable() const
{
return m_uncheckable;
}

Optional& Optional::uncheckable(bool value)
{
m_uncheckable = value;
return *this;
}

QVariantMap Optional::asMap() const
{
QVariantMap props;
Base::setTo(props);
Base::setElemTo(m_field, dataKey(), props);
Base::setElemTo(m_uncheckable, uncheckableKey(), props);
return props;
}

void Optional::getFrom(const QVariantMap& props)
{
m_field = getElemFrom<QVariantMap>(props, dataKey());
m_uncheckable = getElemFrom<bool>(props, uncheckableKey());
}


Variant::Variant() = default;
Variant::Variant(const Variant&) = default;
Variant::Variant(Variant&&) = default;
Expand Down

0 comments on commit 7a2df7b

Please sign in to comment.