Skip to content

Commit

Permalink
Moving "serializedHidden" info from properties to the field object it…
Browse files Browse the repository at this point in the history
…self.
  • Loading branch information
arobenko committed Oct 29, 2024
1 parent 3d57557 commit 3c60d06
Show file tree
Hide file tree
Showing 33 changed files with 148 additions and 120 deletions.
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/ArrayListFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ArrayListFieldWidget::ArrayListFieldWidget(
setSeparatorWidget(m_ui.m_sepLine);
setSerialisedValueWidget(m_ui.m_serValueWidget);

performNameLabelUpdate();
commonConstruct();

assert(m_fieldPtr->canWrite());
refreshInternal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ArrayListRawDataFieldWidget::ArrayListRawDataFieldWidget(
setSeparatorWidget(m_ui.m_sepLine);
setSerialisedValueWidget(m_ui.m_serValueWidget);

performNameLabelUpdate();
commonConstruct();

refresh();

Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/BitfieldFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BitfieldFieldWidget::BitfieldFieldWidget(
assert(m_ui.m_serValueLineEdit != nullptr);
setSerialisedInputMask(*m_ui.m_serValueLineEdit, m_fieldPtr->width());

performNameLabelUpdate();
commonConstruct();

connect(m_ui.m_serValueLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(serialisedValueUpdated(const QString&)));
Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/BitmaskValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ BitmaskValueFieldWidget::BitmaskValueFieldWidget(

prepareCheckboxes();

performNameLabelUpdate();
commonConstruct();

refresh();

Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/BundleFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BundleFieldWidget::BundleFieldWidget(
setLayout(m_membersLayout);
setNameLabelWidget(m_label);

performNameLabelUpdate();
commonConstruct();
}

BundleFieldWidget::~BundleFieldWidget() noexcept = default;
Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/EnumValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ EnumValueFieldWidget::EnumValueFieldWidget(

populateComboBox();

performNameLabelUpdate();
commonConstruct();

refresh();

Expand Down
72 changes: 40 additions & 32 deletions app/cc_view/src/widget/field/FieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ void FieldWidget::updateProperties(const QVariantMap& props)
{
property::field::Common commonProps(props);
m_hiddenWhenReadOnly = commonProps.isHiddenWhenReadOnly();
performNameLabelUpdate();
updatePropertiesImpl(props);
performUiElementsVisibilityCheck(commonProps);
performUiReadOnlyCheck(commonProps);
Expand Down Expand Up @@ -157,26 +156,10 @@ void FieldWidget::updateSerValue(
text.setPlainText(serValueStr);
}

void FieldWidget::performNameLabelUpdate()
void FieldWidget::commonConstruct()
{
if (m_nameLabel == nullptr) {
return;
}

auto& f = fieldImpl();
QString str = f.name();
if (str.isEmpty()) {
m_nameLabel->hide();
return;
}

if (!m_nameSuffix.isEmpty()) {
str.append(m_nameSuffix);
}

str.append(':');
m_nameLabel->setText(str);
m_nameLabel->show();
performNameLabelUpdate();
performSerVisibilityUpdate();
}

void FieldWidget::editEnabledUpdatedImpl()
Expand All @@ -202,18 +185,6 @@ void FieldWidget::performUiElementsVisibilityCheck(const property::field::Common
(m_serValueWidget == nullptr)) {
return;
}

auto setWidgetHiddenFunc =
[](QWidget* widget, bool hidden)
{
if (widget != nullptr) {
widget->setHidden(hidden);
}
};

auto serHidden = props.isSerialisedHidden();
setWidgetHiddenFunc(m_sepWidget, serHidden);
setWidgetHiddenFunc(m_serValueWidget, serHidden);
}

void FieldWidget::performUiReadOnlyCheck(const property::field::Common& props)
Expand All @@ -225,6 +196,43 @@ void FieldWidget::performUiReadOnlyCheck(const property::field::Common& props)
}
}

void FieldWidget::performNameLabelUpdate()
{
if (m_nameLabel == nullptr) {
return;
}

auto& f = fieldImpl();
QString str = f.name();
if (str.isEmpty()) {
m_nameLabel->hide();
return;
}

if (!m_nameSuffix.isEmpty()) {
str.append(m_nameSuffix);
}

str.append(':');
m_nameLabel->setText(str);
m_nameLabel->show();
}

void FieldWidget::performSerVisibilityUpdate()
{
auto setWidgetHiddenFunc =
[](QWidget* widget, bool hidden)
{
if (widget != nullptr) {
widget->setHidden(hidden);
}
};

auto& f = fieldImpl();
bool serHidden = f.isHiddenSerialization();
setWidgetHiddenFunc(m_sepWidget, serHidden);
setWidgetHiddenFunc(m_serValueWidget, serHidden);
}

} // namespace cc_tools_qt

4 changes: 3 additions & 1 deletion app/cc_view/src/widget/field/FieldWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public slots:
m_serValueWidget = widget;
}

void performNameLabelUpdate();
void commonConstruct();

virtual ToolsField& fieldImpl() = 0;
virtual void refreshImpl() = 0;
Expand All @@ -129,6 +129,8 @@ public slots:
private:
void performUiElementsVisibilityCheck(const property::field::Common& props);
void performUiReadOnlyCheck(const property::field::Common& props);
void performNameLabelUpdate();
void performSerVisibilityUpdate();

bool m_forcedReadOnly = false;
bool m_editEnabled = true;
Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/FloatValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ FloatValueFieldWidget::FloatValueFieldWidget(

createSpecialsWidget(m_fieldPtr->specials());

performNameLabelUpdate();
commonConstruct();

refresh();

Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/LongIntValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ LongIntValueFieldWidget::LongIntValueFieldWidget(
static_cast<double>(m_fieldPtr->maxValue()));
m_ui.m_valueSpinBox->setDecimals(0);

performNameLabelUpdate();
commonConstruct();

connect(m_ui.m_valueSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(valueUpdated(double)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ LongLongIntValueFieldWidget::LongLongIntValueFieldWidget(
assert(m_ui.m_serValueLineEdit != nullptr);
setSerialisedInputMask(*m_ui.m_serValueLineEdit, m_fieldPtr->minWidth(), m_fieldPtr->maxWidth());

performNameLabelUpdate();
commonConstruct();

connect(m_ui.m_valueLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(valueUpdated(const QString&)));
Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/OptionalFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ OptionalFieldWidget::OptionalFieldWidget(
m_ui.setupUi(this);
setNameLabelWidget(m_ui.m_nameLabel);

performNameLabelUpdate();
commonConstruct();

if (m_fieldPtr->getMode() == Mode::Tentative) {
m_fieldPtr->setMode(Mode::Missing);
Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/ScaledIntValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ScaledIntValueFieldWidget::ScaledIntValueFieldWidget(
m_ui.m_valueSpinBox->setDecimals(decimals);
}

performNameLabelUpdate();
commonConstruct();

refresh();

Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/ShortIntValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ShortIntValueFieldWidget::ShortIntValueFieldWidget(
static_cast<int>(m_fieldPtr->minValue()),
static_cast<int>(m_fieldPtr->maxValue()));

performNameLabelUpdate();
commonConstruct();

connect(m_ui.m_valueSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(valueUpdated(int)));
Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/StringFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ StringFieldWidget::StringFieldWidget(
setSeparatorWidget(m_ui.m_sepLine);
setSerialisedValueWidget(m_ui.m_serValueWidget);

performNameLabelUpdate();
commonConstruct();

connect(
m_ui.m_valuePlainTextEdit, SIGNAL(textChanged()),
Expand Down
2 changes: 1 addition & 1 deletion app/cc_view/src/widget/field/UnknownValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ UnknownValueFieldWidget::UnknownValueFieldWidget(
m_ui.setupUi(this);
setNameLabelWidget(m_ui.m_nameLabel);

performNameLabelUpdate();
commonConstruct();

connect(m_ui.m_serValueLineEdit, SIGNAL(textChanged(const QString&)),
this, SLOT(serialisedValueUpdated(const QString&)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ UnsignedLongLongIntValueFieldWidget::UnsignedLongLongIntValueFieldWidget(
setSerialisedInputMask(*m_ui.m_serValueLineEdit, m_fieldPtr->minWidth(), m_fieldPtr->maxWidth());
createSpecialsWidget(m_fieldPtr->specials());

performNameLabelUpdate();
commonConstruct();

refresh();

Expand Down
4 changes: 2 additions & 2 deletions app/cc_view/src/widget/field/VariantFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ VariantFieldWidget::VariantFieldWidget(
setNameLabelWidget(m_ui.m_nameLabel);
setValueWidget(m_ui.m_valueWidget);
setSeparatorWidget(m_ui.m_sepLine);
setSerialisedValueWidget(m_ui.m_serValueWidget);\
setSerialisedValueWidget(m_ui.m_serValueWidget);

m_ui.m_idxSpinBox->setMaximum(m_fieldPtr->getMembersCount() - 1);
updateIndexValue();
updateMemberCombo();

performNameLabelUpdate();
commonConstruct();

connect(
m_ui.m_idxSpinBox, SIGNAL(valueChanged(int)),
Expand Down
2 changes: 1 addition & 1 deletion demo/cc_plugin/DemoMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace
static QVariantList createFieldsProperties()
{
QVariantList props;
props.append(cc::property::field::IntValue().serialisedHidden().hiddenWhenReadOnly().asMap());
props.append(cc::property::field::IntValue().hiddenWhenReadOnly().asMap());

assert(props.size() == demo::DemoMessage<>::TransportFieldIdx_numOfValues);
return props;
Expand Down
19 changes: 4 additions & 15 deletions demo/cc_plugin/message/Bitfields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,28 @@ using ProtMsg = demo::cc_plugin::message::Bitfields::ProtMsg;
QVariantMap createField1BitmaskProperties()
{
using Field = ProtMsg::Field_field1::Field_member1;
auto props =
cc::property::field::ForField<Field>()
.serialisedHidden();
auto props = cc::property::field::ForField<Field>();
return props.asMap();
}

QVariantMap createField1EnumProperties()
{
using Field = ProtMsg::Field_field1::Field_member2;
auto props =
cc::property::field::ForField<Field>()
.serialisedHidden();

auto props = cc::property::field::ForField<Field>();
return props.asMap();
}

QVariantMap createField1Int1Properties()
{
using Field = ProtMsg::Field_field1::Field_member3;
auto props =
cc::property::field::ForField<Field>()
.serialisedHidden();

auto props = cc::property::field::ForField<Field>();
return props.asMap();
}

QVariantMap createField1Int2Properties()
{
using Field = ProtMsg::Field_field1::Field_member4;
auto props =
cc::property::field::ForField<Field>()
.serialisedHidden();

auto props = cc::property::field::ForField<Field>();
return props.asMap();
}

Expand Down
5 changes: 1 addition & 4 deletions demo/cc_plugin/message/Bundles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ QVariantMap createProps_field1()
using Field = ProtMsg::Field_field1;
auto props =
cc::property::field::ForField<Field>()
.serialisedHidden()
.add(createProps_field1_mem1())
.add(createProps_field1_mem2());
assert(props.members().size() == Field::FieldIdx_numOfValues);
Expand All @@ -68,8 +67,7 @@ QVariantMap createProps_field1()
QVariantMap createProps_field2_mem1()
{
using Field = ProtMsg::Field_field2::Field_length;
auto props =
cc::property::field::ForField<Field>();
auto props = cc::property::field::ForField<Field>();
return props.asMap();
}

Expand All @@ -86,7 +84,6 @@ QVariantMap createProps_field2()
using Field = ProtMsg::Field_field2;
auto props =
cc::property::field::ForField<Field>()
.serialisedHidden()
.add(createProps_field2_mem1())
.add(createProps_field2_mem2());
assert(props.members().size() == Field::FieldIdx_numOfValues);
Expand Down
16 changes: 6 additions & 10 deletions demo/cc_plugin/message/Lists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ QVariantMap createField3Properties()
using Field3 = ProtMsg::Field_field3;
cc::property::field::ForField<Field3> props;
props.appendIndexToElementName();
props.add(
cc::property::field::IntValue()
.serialisedHidden()
.asMap());
props.add(cc::property::field::IntValue().asMap());
return props.asMap();
}

Expand All @@ -54,7 +51,7 @@ QVariantMap createField4Properties()
return
cc::property::field::ForField<ProtMsg::Field_field4>()
.appendIndexToElementName()
.add(cc::property::field::IntValue().serialisedHidden().asMap())
.add(cc::property::field::IntValue().asMap())
.asMap();
}

Expand All @@ -65,12 +62,11 @@ QVariantMap createField5Properties()
.appendIndexToElementName()
.add(
cc::property::field::ForField<ProtMsg::Field_field5::ValueType::value_type>()
.add(cc::property::field::IntValue().serialisedHidden().asMap())
.add(cc::property::field::IntValue().serialisedHidden().asMap())
.add(cc::property::field::IntValue().serialisedHidden().asMap())
.serialisedHidden()
.add(cc::property::field::IntValue().asMap())
.add(cc::property::field::IntValue().asMap())
.add(cc::property::field::IntValue().asMap())
.asMap())
// .serialisedHidden()
//
// .showPrefix()
// .prefixName("length")
.asMap();
Expand Down
Loading

0 comments on commit 3c60d06

Please sign in to comment.