Skip to content

Commit

Permalink
Improved fields cloning.
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Oct 27, 2024
1 parent e8d3de0 commit 9d0abfb
Show file tree
Hide file tree
Showing 61 changed files with 217 additions and 175 deletions.
30 changes: 15 additions & 15 deletions app/cc_view/src/DefaultMessageDisplayHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@ class WidgetCreator : public ToolsFieldHandler

virtual void handle(field::ToolsIntField& field) override
{
m_widget.reset(new IntValueFieldWidget(field.clone(), m_parent));
m_widget.reset(new IntValueFieldWidget(field.actClone(), m_parent));
}

virtual void handle(field::ToolsUnsignedLongField& field) override
{
m_widget.reset(new UnsignedLongLongIntValueFieldWidget(field.clone(), m_parent));
m_widget.reset(new UnsignedLongLongIntValueFieldWidget(field.actClone(), m_parent));
}

virtual void handle(field::ToolsBitmaskField& field) override
{
m_widget.reset(new BitmaskValueFieldWidget(field.clone(), m_parent));
m_widget.reset(new BitmaskValueFieldWidget(field.actClone(), m_parent));
}

virtual void handle(field::ToolsEnumField& field) override
{
m_widget.reset(new EnumValueFieldWidget(field.clone(), m_parent));
m_widget.reset(new EnumValueFieldWidget(field.actClone(), m_parent));
}

virtual void handle(field::ToolsStringField& field) override
{
m_widget.reset(new StringFieldWidget(field.clone(), m_parent));
m_widget.reset(new StringFieldWidget(field.actClone(), m_parent));
}

virtual void handle(field::ToolsBitfieldField& field) override
Expand All @@ -90,7 +90,7 @@ class WidgetCreator : public ToolsFieldHandler
membersWidgets.push_back(getWidget());
}

std::unique_ptr<BitfieldFieldWidget> widget(new BitfieldFieldWidget(field.clone(), m_parent));
std::unique_ptr<BitfieldFieldWidget> widget(new BitfieldFieldWidget(field.actClone(), m_parent));
for (auto& memWidget : membersWidgets) {
widget->addMemberField(memWidget.release());
}
Expand All @@ -103,7 +103,7 @@ class WidgetCreator : public ToolsFieldHandler
field.getFieldWrapper().dispatch(*this);
auto wrappedWidget = getWidget();

std::unique_ptr<OptionalFieldWidget> widget(new OptionalFieldWidget(field.clone(), m_parent));
std::unique_ptr<OptionalFieldWidget> widget(new OptionalFieldWidget(field.actClone(), m_parent));
widget->setField(wrappedWidget.release());
m_widget = std::move(widget);
}
Expand All @@ -118,7 +118,7 @@ class WidgetCreator : public ToolsFieldHandler
membersWidgets.push_back(getWidget());
}

std::unique_ptr<BundleFieldWidget> widget(new BundleFieldWidget(field.clone(), m_parent));
std::unique_ptr<BundleFieldWidget> widget(new BundleFieldWidget(field.actClone(), m_parent));
for (auto& memWidget : membersWidgets) {
widget->addMemberField(memWidget.release());
}
Expand All @@ -128,7 +128,7 @@ class WidgetCreator : public ToolsFieldHandler

virtual void handle(field::ToolsRawDataField& field) override
{
m_widget.reset(new ArrayListRawDataFieldWidget(field.clone(), m_parent));
m_widget.reset(new ArrayListRawDataFieldWidget(field.actClone(), m_parent));
}

virtual void handle(field::ToolsArrayListField& field) override
Expand All @@ -152,12 +152,12 @@ class WidgetCreator : public ToolsFieldHandler
};

assert(field.size() == field.getMembers().size());
m_widget.reset(new ArrayListFieldWidget(field.clone(), std::move(createMembersWidgetsFunc), m_parent));
m_widget.reset(new ArrayListFieldWidget(field.actClone(), std::move(createMembersWidgetsFunc), m_parent));
}

virtual void handle(field::ToolsFloatField& field) override
{
m_widget.reset(new FloatValueFieldWidget(field.clone(), m_parent));
m_widget.reset(new FloatValueFieldWidget(field.actClone(), m_parent));
}

virtual void handle(field::ToolsVariantField& field) override
Expand All @@ -171,15 +171,15 @@ class WidgetCreator : public ToolsFieldHandler
};

FieldWidgetPtr memberWidget;
auto& memberFieldPtr = field.getCurrent();
if (memberFieldPtr) {
auto* memberFieldPtr = field.getCurrent();
if (memberFieldPtr != nullptr) {
memberFieldPtr->dispatch(*this);
memberWidget = getWidget();
}

std::unique_ptr<VariantFieldWidget> widget(
new VariantFieldWidget(
field.clone(),
field.actClone(),
createMemberWidgetsFunc,
m_parent));
if (memberWidget) {
Expand All @@ -191,7 +191,7 @@ class WidgetCreator : public ToolsFieldHandler

virtual void handle(field::ToolsUnknownField& field) override
{
m_widget.reset(new UnknownValueFieldWidget(field.clone(), m_parent));
m_widget.reset(new UnknownValueFieldWidget(field.actClone(), m_parent));
}

virtual void handle([[maybe_unused]] ToolsField& field) override
Expand Down
3 changes: 3 additions & 0 deletions app/cc_view/src/widget/field/ArrayListFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ArrayListElementWidget::ArrayListElementWidget(
m_ui.m_layout->addWidget(fieldWidget);

updateUi();

connect(
m_fieldWidget, SIGNAL(sigFieldUpdated()),
this, SIGNAL(sigFieldUpdated()));
Expand Down Expand Up @@ -96,6 +97,8 @@ ArrayListFieldWidget::ArrayListFieldWidget(
setSeparatorWidget(m_ui.m_sepLine);
setSerialisedValueWidget(m_ui.m_serValueWidget);

performNameLabelUpdate();

assert(m_fieldPtr->canWrite());
refreshInternal();
addMissingFields();
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/ArrayListRawDataFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ArrayListRawDataFieldWidget::ArrayListRawDataFieldWidget(
setSeparatorWidget(m_ui.m_sepLine);
setSerialisedValueWidget(m_ui.m_serValueWidget);

performNameLabelUpdate();

refresh();

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

performNameLabelUpdate();

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

prepareCheckboxes();

performNameLabelUpdate();

refresh();

connect(m_ui.m_serValueLineEdit, SIGNAL(textEdited(const QString&)),
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/BundleFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ BundleFieldWidget::BundleFieldWidget(
m_membersLayout->addWidget(m_label);
setLayout(m_membersLayout);
setNameLabelWidget(m_label);

performNameLabelUpdate();
}

BundleFieldWidget::~BundleFieldWidget() noexcept = default;
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/EnumValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ EnumValueFieldWidget::EnumValueFieldWidget(

populateComboBox();

performNameLabelUpdate();

refresh();

connect(m_ui.m_valueComboBox, SIGNAL(currentIndexChanged(int)),
Expand Down
43 changes: 22 additions & 21 deletions app/cc_view/src/widget/field/FieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ void FieldWidget::updateSerValue(
text.setPlainText(serValueStr);
}

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::editEnabledUpdatedImpl()
{
}
Expand Down Expand Up @@ -203,27 +225,6 @@ 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();
}

} // namespace cc_tools_qt

5 changes: 3 additions & 2 deletions app/cc_view/src/widget/field/FieldWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public slots:
m_serValueWidget = widget;
}

void performNameLabelUpdate();

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


bool m_forcedReadOnly = false;
bool m_editEnabled = true;
bool m_hiddenWhenReadOnly = false;
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/FloatValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ FloatValueFieldWidget::FloatValueFieldWidget(

createSpecialsWidget(m_fieldPtr->specials());

performNameLabelUpdate();

refresh();

connect(m_ui.m_valueSpinBox, SIGNAL(valueChanged(double)),
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/LongIntValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ LongIntValueFieldWidget::LongIntValueFieldWidget(
static_cast<double>(m_fieldPtr->maxValue()));
m_ui.m_valueSpinBox->setDecimals(0);

performNameLabelUpdate();

connect(m_ui.m_valueSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(valueUpdated(double)));

Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/LongLongIntValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ LongLongIntValueFieldWidget::LongLongIntValueFieldWidget(
assert(m_ui.m_serValueLineEdit != nullptr);
setSerialisedInputMask(*m_ui.m_serValueLineEdit, m_fieldPtr->minWidth(), m_fieldPtr->maxWidth());

performNameLabelUpdate();

connect(m_ui.m_valueLineEdit, SIGNAL(textEdited(const QString&)),
this, SLOT(valueUpdated(const QString&)));

Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/OptionalFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ OptionalFieldWidget::OptionalFieldWidget(
m_ui.setupUi(this);
setNameLabelWidget(m_ui.m_nameLabel);

performNameLabelUpdate();

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

performNameLabelUpdate();

refresh();

connect(m_ui.m_valueSpinBox, SIGNAL(valueChanged(double)),
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/ShortIntValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ ShortIntValueFieldWidget::ShortIntValueFieldWidget(
static_cast<int>(m_fieldPtr->minValue()),
static_cast<int>(m_fieldPtr->maxValue()));

performNameLabelUpdate();

connect(m_ui.m_valueSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(valueUpdated(int)));

Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/StringFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ StringFieldWidget::StringFieldWidget(
setSeparatorWidget(m_ui.m_sepLine);
setSerialisedValueWidget(m_ui.m_serValueWidget);

performNameLabelUpdate();

connect(
m_ui.m_valuePlainTextEdit, SIGNAL(textChanged()),
this, SLOT(stringChanged()));
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/UnknownValueFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ UnknownValueFieldWidget::UnknownValueFieldWidget(
m_ui.setupUi(this);
setNameLabelWidget(m_ui.m_nameLabel);

performNameLabelUpdate();

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,6 +45,8 @@ UnsignedLongLongIntValueFieldWidget::UnsignedLongLongIntValueFieldWidget(
setSerialisedInputMask(*m_ui.m_serValueLineEdit, m_fieldPtr->minWidth(), m_fieldPtr->maxWidth());
createSpecialsWidget(m_fieldPtr->specials());

performNameLabelUpdate();

refresh();

connect(m_ui.m_valueLineEdit, SIGNAL(textEdited(const QString&)),
Expand Down
2 changes: 2 additions & 0 deletions app/cc_view/src/widget/field/VariantFieldWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ VariantFieldWidget::VariantFieldWidget(
updateIndexValue();
updateMemberCombo();

performNameLabelUpdate();

connect(
m_ui.m_idxSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(indexUpdated(int)));
Expand Down
5 changes: 3 additions & 2 deletions lib/include/cc_tools_qt/ToolsField.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CC_API ToolsField
virtual ~ToolsField() noexcept;

ToolsField(const ToolsField&) = delete;
ToolsField& operator=(const ToolsField&) = delete;

const char* name() const;

Expand All @@ -64,7 +65,7 @@ class CC_API ToolsField

void dispatch(ToolsFieldHandler& handler);

Ptr upClone();
Ptr clone();

bool canWrite() const;

Expand All @@ -81,7 +82,7 @@ class CC_API ToolsField
virtual SerialisedSeq getSerialisedValueImpl() const = 0;
virtual bool setSerialisedValueImpl(const SerialisedSeq& value) = 0;
virtual void dispatchImpl(ToolsFieldHandler& handler) = 0;
virtual Ptr upCloneImpl() = 0;
virtual Ptr cloneImpl() = 0;
virtual bool canWriteImpl() const = 0;
virtual void resetImpl() = 0;

Expand Down
4 changes: 2 additions & 2 deletions lib/include/cc_tools_qt/details/ToolsArrayListFieldImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <functional>
#include <utility>


namespace cc_tools_qt
{

Expand All @@ -47,6 +46,7 @@ class ToolsArrayListFieldImpl : public ToolsFieldBase<cc_tools_qt::field::ToolsA

public:
using SerialisedSeq = typename Base::SerialisedSeq;
using Ptr = typename Base::Ptr;
using ActPtr = typename Base::ActPtr;
using PrefixFieldInfo = typename Base::PrefixFieldInfo;

Expand Down Expand Up @@ -149,7 +149,7 @@ class ToolsArrayListFieldImpl : public ToolsFieldBase<cc_tools_qt::field::ToolsA
adjustFixedSizeInternal(Tag());
}

virtual ActPtr cloneImpl() override
virtual Ptr cloneImpl() override
{
ActPtr ptr(new ToolsArrayListFieldImpl(Base::field()));
static_cast<ToolsArrayListFieldImpl<TField>*>(ptr.get())->m_wrapFieldFunc = m_wrapFieldFunc;
Expand Down
Loading

0 comments on commit 9d0abfb

Please sign in to comment.