From fb4f4685201389e1d85cab0c2505d9365dcbf464 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Tue, 12 Aug 2025 22:47:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86ListBaseUnit?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TranslateUI/ExtractRuleView.cpp | 111 ++++++++++++++++++++++++++++++-- TranslateUI/ExtractRuleView.h | 7 +- TranslateUI/TranslateBasic.cpp | 14 +++- TranslateUI/TranslateBasic.h | 2 + 4 files changed, 126 insertions(+), 8 deletions(-) diff --git a/TranslateUI/ExtractRuleView.cpp b/TranslateUI/ExtractRuleView.cpp index 48e7f76..981ed48 100644 --- a/TranslateUI/ExtractRuleView.cpp +++ b/TranslateUI/ExtractRuleView.cpp @@ -55,7 +55,7 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr base, _configs_stack->setCurrentIndex(2); list_configs->currentAccept(unit, target); } - else if (unit->baseType() == UnionBasedUnit::topic()){ + else if (unit->baseType() == UnionBasedUnit::topic()) { _configs_stack->setCurrentIndex(3); union_configs->currentAccept(unit, target); } @@ -126,7 +126,7 @@ ListBasedConfiguration::ListBasedConfiguration( :QWidget(p), _bind_core(core), _offset_enter(new QSpinBox(this)), _delegate_sync(new QPushButton("Sync", this)), - _rule_select(new QComboBox(this)), + _delegate_select(new QComboBox(this)), _size_layout_select(new QComboBox(this)), _configs_stack(new QStackedWidget(this)), _content_display(new QTextBrowser(this)), @@ -138,7 +138,7 @@ ListBasedConfiguration::ListBasedConfiguration( layout->addWidget(this->_offset_enter, 0, 1); layout->addWidget(this->_delegate_sync, 0, 2); layout->addWidget(new QLabel(tr("Delegate:")), 1, 0); - layout->addWidget(_rule_select, 1, 1, 1, 2); + layout->addWidget(_delegate_select, 1, 1, 1, 2); layout->addWidget(new QLabel(tr("Size:")), 2, 0); layout->addWidget(_size_layout_select, 2, 1, 1, 2); @@ -150,14 +150,115 @@ ListBasedConfiguration::ListBasedConfiguration( layout->setRowStretch(7, 1); layout->setColumnStretch(1, 1); + + connect(_offset_enter, QOverload::of(&QSpinBox::valueChanged), + [=](int v) { + this->_bind_u->setOffsetSpan(v); + + currentAccept(_bind_u, _bind_index, _fields_getter); + emit this->reloadRequest(); + }); + connect(_delegate_select, QOverload::of(&QComboBox::currentTextChanged), + [=](const QString& current_delegate) { + auto delt_o = _bind_core->operator[](current_delegate); + QJsonObject object; + delt_o->saveTo(object); + auto delt_ins = delt_o->newDefault(); + delt_ins->loadFrom(_bind_core, object); + _bind_u->setDelegate(std::dynamic_pointer_cast(delt_ins)); + + currentAccept(_bind_u, _bind_index, _fields_getter); + emit this->reloadRequest(); + }); + connect(_size_layout_select, QOverload::of(&QComboBox::currentTextChanged), + [=](const QString& size_provider_name) { + auto size_o = _bind_core->sizeProviderMap()[size_provider_name]; + auto size_ins = std::dynamic_pointer_cast(size_o->newDefault()); + this->_bind_u->setSizeProvider(size_ins); + + if (size_provider_name == ConstNumberProvider::topic()) { + _configs_stack->setCurrentIndex(0); + size_ins->setExpression("0"); + _const_number_input->setValue(0); + } + if (size_provider_name == InterpretedNumberPrivider::topic()) { + _configs_stack->setCurrentIndex(1); + QSignalBlocker s(_prev_field_refer); + _prev_field_refer->clear(); + s.unblock(); + auto fields_map = _fields_getter->prevFields(); + for (auto field_name : fields_map.keys()) { + _prev_field_refer->addItem(field_name, (int)fields_map[field_name]); + } + } + + currentAccept(_bind_u, _bind_index, _fields_getter); + emit this->reloadRequest(); + }); + connect(_const_number_input, QOverload::of(&QSpinBox::valueChanged), + [=](int value) { + auto size_ins = _bind_u->sizeProvider(); + size_ins->setExpression(QString("%1").arg(value)); + + currentAccept(_bind_u, _bind_index, _fields_getter); + emit this->reloadRequest(); + }); + connect(_prev_field_refer, QOverload::of(&QComboBox::currentTextChanged), + [=](const QString& current_field) { + auto size_ins = _bind_u->sizeProvider(); + size_ins->setExpression(current_field); + + currentAccept(_bind_u, _bind_index, _fields_getter); + emit this->reloadRequest(); + }); } -void ListBasedConfiguration::currentAccept(std::shared_ptr inst_u, const QModelIndex& idx) +void ListBasedConfiguration::currentAccept(std::shared_ptr inst_u, + const QModelIndex& idx, std::shared_ptr get) { _bind_u = std::dynamic_pointer_cast(inst_u); _bind_index = idx; + _fields_getter = get; + QSignalBlocker v(_offset_enter); + _offset_enter->setRange(0, INT_MAX); + _offset_enter->setValue(inst_u->offsetSpan()); + QSignalBlocker vx(_delegate_select); + this->_bind_u = std::dynamic_pointer_cast(inst_u); + _delegate_select->clear(); + _delegate_select->addItems(_bind_core->delegateAlias()); + _delegate_select->setCurrentText(this->_bind_u->delegateInst()->aliasName()); + + QSignalBlocker vv(_size_layout_select); + this->_size_layout_select->clear(); + this->_size_layout_select->addItems(_bind_core->sizeProviderMap().keys()); + this->_size_layout_select->setCurrentText(_bind_u->sizeProvider()->name()); + if (this->_size_layout_select->currentText() == ConstNumberProvider::topic()) { + _configs_stack->setCurrentIndex(0); + auto size_const = std::dynamic_pointer_cast(_bind_u->sizeProvider()); + QSignalBlocker s(_const_number_input); + _const_number_input->setValue(size_const->value(size_const->expression())); + } + + if (this->_size_layout_select->currentText() == InterpretedNumberPrivider::topic()) { + _configs_stack->setCurrentIndex(1); + auto size_rt = std::dynamic_pointer_cast(_bind_u->sizeProvider()); + QSignalBlocker s(_prev_field_refer); + _prev_field_refer->clear(); + auto fields_map = get->prevFields(); + for (auto field_name : fields_map.keys()) { + _prev_field_refer->addItem(field_name, (int)fields_map[field_name]); + } + + _prev_field_refer->setCurrentText(size_rt->expression()); + } + + QJsonObject content; + _bind_u->saveTo(content); + _content_display->setText( + QString::fromUtf8(QJsonDocument(content).toJson()) + ); } SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptr core, QWidget* p /*= nullptr*/) @@ -179,6 +280,7 @@ SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptr_offset_enter, QOverload::of(&QSpinBox::valueChanged), [=](int v_offset) { inst_current->setOffsetSpan(v_offset); + currentAccept(this->inst_current, this->idx_current); emit this->reloadRequest(); }); connect(this->_delegate_changed, QOverload::of(&QComboBox::currentTextChanged), @@ -189,6 +291,7 @@ SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptrsaveTo(content); v_inst->loadFrom(_bind_core, content); inst_current->setDelegate(std::dynamic_pointer_cast(v_inst)); + currentAccept(this->inst_current, this->idx_current); emit this->reloadRequest(); }); } diff --git a/TranslateUI/ExtractRuleView.h b/TranslateUI/ExtractRuleView.h index 3468b62..5b0b1d6 100644 --- a/TranslateUI/ExtractRuleView.h +++ b/TranslateUI/ExtractRuleView.h @@ -40,9 +40,10 @@ namespace unit_configurations { Q_OBJECT private: std::shared_ptr _bind_core; + QSpinBox* const _offset_enter; QPushButton* const _delegate_sync; - QComboBox* const _rule_select; + QComboBox* const _delegate_select; QComboBox* const _size_layout_select; QStackedWidget* const _configs_stack; QTextBrowser* const _content_display; @@ -51,11 +52,13 @@ namespace unit_configurations { QComboBox* const _prev_field_refer; std::shared_ptr _bind_u = nullptr; + std::shared_ptr _fields_getter = nullptr; QModelIndex _bind_index; public: ListBasedConfiguration(std::shared_ptr core, QWidget* p = nullptr); - void currentAccept(std::shared_ptr inst_u, const QModelIndex& idx); + void currentAccept(std::shared_ptr inst_u, + const QModelIndex& idx, std::shared_ptr get); signals: void reloadRequest(); diff --git a/TranslateUI/TranslateBasic.cpp b/TranslateUI/TranslateBasic.cpp index 4366525..70c7428 100644 --- a/TranslateUI/TranslateBasic.cpp +++ b/TranslateUI/TranslateBasic.cpp @@ -163,7 +163,7 @@ void ConstNumberProvider::bindInput(std::shared_ptr inst) QString ConstNumberProvider::name() const { - return NAME(ConstNumberProvider); + return topic(); } int32_t ConstNumberProvider::value(const QString& expr) const @@ -196,6 +196,11 @@ std::shared_ptr ConstNumberProvider::newDefault() const return std::make_shared(); } +QString ConstNumberProvider::topic() +{ + return NAME(ConstNumberProvider); +} + void InterpretedNumberPrivider::bindInput(std::shared_ptr inst) { this->_refer._context_inst = inst; @@ -203,7 +208,7 @@ void InterpretedNumberPrivider::bindInput(std::shared_ptr inst) QString InterpretedNumberPrivider::name() const { - return NAME(InterpretedNumberPrivider); + return topic(); } #include @@ -243,6 +248,11 @@ std::shared_ptr InterpretedNumberPrivider::newDefault() const return std::make_shared(); } +QString InterpretedNumberPrivider::topic() +{ + return NAME(InterpretedNumberPrivider); +} + void ValueAccessContext::init(const QString& field, std::shared_ptr parent) { this->_cascade._current_field = field; diff --git a/TranslateUI/TranslateBasic.h b/TranslateUI/TranslateBasic.h index 862f8ac..fe0628e 100644 --- a/TranslateUI/TranslateBasic.h +++ b/TranslateUI/TranslateBasic.h @@ -157,6 +157,7 @@ namespace size_provider { } _number; public: + static QString topic(); QString name() const override; void bindInput(std::shared_ptr inst) override; @@ -184,6 +185,7 @@ namespace size_provider { public: + static QString topic(); QString name() const override; void bindInput(std::shared_ptr inst) override;