From ff2ca20a6adee39cc138a1091b2ffe6ecd8f62ed Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Tue, 5 Aug 2025 22:48:54 +0800 Subject: [PATCH] update --- TranslateUI/SequenceView.cpp | 54 +++++++++++++----------------- TranslateUI/SequenceView.h | 4 --- TranslateUI/StructuralRuleView.cpp | 46 ++++++++++++++++++++++++- TranslateUI/StructuralRuleView.h | 3 ++ TranslateUI/TranslateBasic.cpp | 8 +++-- TranslateUI/extract_basic.cpp | 7 ---- 6 files changed, 77 insertions(+), 45 deletions(-) diff --git a/TranslateUI/SequenceView.cpp b/TranslateUI/SequenceView.cpp index 04bda91..bbe327f 100644 --- a/TranslateUI/SequenceView.cpp +++ b/TranslateUI/SequenceView.cpp @@ -39,6 +39,30 @@ void IntDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewIt void RuleSetCustom::targetRuleRefresh(const QModelIndex& idx) { + if (idx.column() == 2) { + auto field_idx = idx.sibling(idx.row(), 0); + auto field_name = field_idx.data(Qt::DisplayRole).toString(); + + auto rule_idx = idx.sibling(idx.row(), 2); + auto rule_name = rule_idx.data(Qt::DisplayRole).toString(); + + auto rule_nm = _view.base->extractUnitList()[rule_name]; + auto new_inst = std::dynamic_pointer_cast(rule_nm->newDefault()); + _view._ruleset->replace(idx.row(), std::make_pair(field_name, new_inst)); + + // 对ListUnit执行特殊初始化步骤 + if (typeid(*new_inst.get()) == typeid(AsList)) { + auto conv = std::dynamic_pointer_cast(new_inst); + if (!conv->elementRule()) { + conv->setElementRule(this->_view.base->defaultExtractUnit()); + } + + if (!conv->sizeProvider()) { + conv->setSizeProvider(this->_view.base->defaultSizeProvider()); + } + } + } + auto rule_insv = (*_view._ruleset)[idx.row()]; auto offset_index = idx.sibling(idx.row(), 1); @@ -58,33 +82,6 @@ void RuleSetCustom::targetRuleRefresh(const QModelIndex& idx) this->resizeColumnsToContents(); } -void RuleSetCustom::peersRuleChanged(const QModelIndex& idx) -{ - auto field_idx = idx.sibling(idx.row(), 0); - auto field_name = field_idx.data(Qt::DisplayRole).toString(); - - auto rule_idx = idx.sibling(idx.row(), 2); - auto rule_name = rule_idx.data(Qt::DisplayRole).toString(); - - auto rule_nm = _view.base->extractUnitList()[rule_name]; - auto new_inst = std::dynamic_pointer_cast(rule_nm->newDefault()); - _view._ruleset->replace(idx.row(), std::make_pair(field_name, new_inst)); - - // 对ListUnit执行特殊初始化步骤 - if (typeid(*new_inst.get()) == typeid(AsList)) { - auto conv = std::dynamic_pointer_cast(new_inst); - if (!conv->elementRule()) { - conv->setElementRule(this->_view.base->defaultExtractUnit()); - } - - if (!conv->sizeProvider()) { - conv->setSizeProvider(this->_view.base->defaultSizeProvider()); - } - } - - targetRuleRefresh(idx); -} - void RuleSetCustom::showEvent(QShowEvent* e) { QTableView::showEvent(e); @@ -112,7 +109,6 @@ RuleSetCustom::RuleSetCustom(std::shared_ptr base, this->setContextMenuPolicy(Qt::CustomContextMenu); connect(this, &QTableView::customContextMenuRequested, this, &RuleSetCustom::customTranslateRuleEdit); - connect(rule_delegate, &RuleSelectDelegate::dataChanged, this, &RuleSetCustom::peersRuleChanged); connect(_view._seqs_model, &QAbstractItemModel::dataChanged, this, &RuleSetCustom::targetRuleRefresh); connect(this, &QTableView::clicked, [=](const QModelIndex& curr) { @@ -204,8 +200,6 @@ void RuleSelectDelegate::setModelData(QWidget* editor, QAbstractItemModel* model { auto rule_name = dynamic_cast(editor)->currentText(); model->setData(index, rule_name, Qt::EditRole); - - emit this->dataChanged(index); } void RuleSelectDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const diff --git a/TranslateUI/SequenceView.h b/TranslateUI/SequenceView.h index 825ed68..09ad953 100644 --- a/TranslateUI/SequenceView.h +++ b/TranslateUI/SequenceView.h @@ -36,9 +36,6 @@ namespace unit_func { private: std::shared_ptr _kernel; - signals: - void dataChanged(const QModelIndex& idx) const; - public: RuleSelectDelegate(std::shared_ptr ins); @@ -66,7 +63,6 @@ signals: public: void targetRuleRefresh(const QModelIndex& idx); - void peersRuleChanged(const QModelIndex& idx_rule); protected: void showEvent(QShowEvent* e) override; diff --git a/TranslateUI/StructuralRuleView.cpp b/TranslateUI/StructuralRuleView.cpp index 53380af..0b76bb8 100644 --- a/TranslateUI/StructuralRuleView.cpp +++ b/TranslateUI/StructuralRuleView.cpp @@ -317,10 +317,18 @@ ListUnitConfiguration::ListUnitConfiguration( connect(_size_layout_select, QOverload::of(&QComboBox::currentIndexChanged), [=](int idx) { - this->_configs_stack->setCurrentIndex(this->_size_layout_select->currentIndex()); + this->_configs_stack->setCurrentIndex( + this->_size_layout_select->currentIndex() + ); }); + connect(this->_size_layout_select, &QComboBox::currentTextChanged, + this, &ListUnitConfiguration::sizeProviderSet); connect(this->_rule_select, &QComboBox::currentTextChanged, this, &ListUnitConfiguration::elmRuleSet); + connect(this->_const_number_input, QOverload::of(&QSpinBox::valueChanged), + this, &ListUnitConfiguration::constProviderBind); + connect(this->_prev_field_refer, &QComboBox::currentTextChanged, + this, &ListUnitConfiguration::fieldProviderBind); } void ListUnitConfiguration::currentRuleAccept(std::shared_ptr u, @@ -375,3 +383,39 @@ void ListUnitConfiguration::elmRuleSet(const QString& name) emit this->currentRuleChanged(this->_bind_index); } + +void ListUnitConfiguration::sizeProviderSet(const QString& name) +{ + if (name == this->_bind_u->sizeProvider()->name()) + return; + + auto ninst = this->_bind_core->sizeProviderList()[name]->newDefault(); + this->_bind_u->setSizeProvider(std::dynamic_pointer_cast(ninst)); + + auto u = this->_bind_u; + auto const_conv = std::dynamic_pointer_cast(u->sizeProvider()); + if (const_conv) { + _configs_stack->setCurrentIndex(0); + _const_number_input->setValue(const_conv->value(const_conv->expression())); + } + + auto runtime_conv = std::dynamic_pointer_cast(u->sizeProvider()); + if (runtime_conv) { + _configs_stack->setCurrentIndex(1); + this->_prev_field_refer->setCurrentText(runtime_conv->name()); + } + + emit this->currentRuleChanged(this->_bind_index); +} + +void ListUnitConfiguration::fieldProviderBind(const QString& name) +{ + this->_bind_u->sizeProvider()->setExpression(name); + emit this->currentRuleChanged(this->_bind_index); +} + +void ListUnitConfiguration::constProviderBind(int value) +{ + this->_bind_u->sizeProvider()->setExpression(QString("%1").arg(value)); + emit this->currentRuleChanged(this->_bind_index); +} diff --git a/TranslateUI/StructuralRuleView.h b/TranslateUI/StructuralRuleView.h index 609f032..9d2ab06 100644 --- a/TranslateUI/StructuralRuleView.h +++ b/TranslateUI/StructuralRuleView.h @@ -101,6 +101,9 @@ namespace configuration_panel { QComboBox* const _prev_field_refer; void elmRuleSet(const QString &name); + void sizeProviderSet(const QString &name); + void constProviderBind(int value); + void fieldProviderBind(const QString &name); public: ListUnitConfiguration(std::shared_ptr core, QWidget* p = nullptr); diff --git a/TranslateUI/TranslateBasic.cpp b/TranslateUI/TranslateBasic.cpp index 44ae866..687e1e0 100644 --- a/TranslateUI/TranslateBasic.cpp +++ b/TranslateUI/TranslateBasic.cpp @@ -163,9 +163,11 @@ QString InterpretedNumberPrivider::name() const #include int32_t InterpretedNumberPrivider::value(const QString& expr) const { - auto value = this->_refer._context_inst->get(expr); - if (value.userType() == QMetaType::Int) - return value.toInt(); + if (this->_refer._context_inst) { + auto value = this->_refer._context_inst->get(expr); + if (value.userType() == QMetaType::Int) + return value.toInt(); + } return 0; } diff --git a/TranslateUI/extract_basic.cpp b/TranslateUI/extract_basic.cpp index 4e8e8f9..85c5cda 100644 --- a/TranslateUI/extract_basic.cpp +++ b/TranslateUI/extract_basic.cpp @@ -406,10 +406,6 @@ void AsList::loadFrom(std::shared_ptr core, const QJsonObject& o xdev = core->extractUnitList()[bind_unit_name]->newDefault(); this->_list._bind_unit = std::dynamic_pointer_cast(xdev); - QString bind_provider_expr = ""; - STRING_SAVE(bind_provider_expr, obj); - this->_list._bind_size_v->setExpression(bind_provider_expr); - QJsonObject unit_obj; QJsonObject size_provider_obj; OBJECT_PEAK(unit_obj, obj); @@ -434,15 +430,12 @@ void AsList::saveTo(QJsonObject& obj) const OBJECT_SAVE(unit_obj, obj); QString bind_size_provider_name = ""; - QString bind_provider_expr = ""; QJsonObject size_provider_obj; if (this->_list._bind_size_v) { - bind_provider_expr = this->_list._bind_size_v->expression(); bind_size_provider_name = this->_list._bind_size_v->name(); this->_list._bind_size_v->saveTo(size_provider_obj); } STRING_SAVE(bind_size_provider_name, obj); - STRING_SAVE(bind_provider_expr, obj); OBJECT_SAVE(size_provider_obj, obj); }