添加了ListBaseUnit配置面板

This commit is contained in:
codeboss 2025-08-12 22:47:19 +08:00
parent b194d486fa
commit fb4f468520
4 changed files with 126 additions and 8 deletions

View File

@ -55,7 +55,7 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
_configs_stack->setCurrentIndex(2); _configs_stack->setCurrentIndex(2);
list_configs->currentAccept(unit, target); list_configs->currentAccept(unit, target);
} }
else if (unit->baseType() == UnionBasedUnit::topic()){ else if (unit->baseType() == UnionBasedUnit::topic()) {
_configs_stack->setCurrentIndex(3); _configs_stack->setCurrentIndex(3);
union_configs->currentAccept(unit, target); union_configs->currentAccept(unit, target);
} }
@ -126,7 +126,7 @@ ListBasedConfiguration::ListBasedConfiguration(
:QWidget(p), _bind_core(core), :QWidget(p), _bind_core(core),
_offset_enter(new QSpinBox(this)), _offset_enter(new QSpinBox(this)),
_delegate_sync(new QPushButton("Sync", this)), _delegate_sync(new QPushButton("Sync", this)),
_rule_select(new QComboBox(this)), _delegate_select(new QComboBox(this)),
_size_layout_select(new QComboBox(this)), _size_layout_select(new QComboBox(this)),
_configs_stack(new QStackedWidget(this)), _configs_stack(new QStackedWidget(this)),
_content_display(new QTextBrowser(this)), _content_display(new QTextBrowser(this)),
@ -138,7 +138,7 @@ ListBasedConfiguration::ListBasedConfiguration(
layout->addWidget(this->_offset_enter, 0, 1); layout->addWidget(this->_offset_enter, 0, 1);
layout->addWidget(this->_delegate_sync, 0, 2); layout->addWidget(this->_delegate_sync, 0, 2);
layout->addWidget(new QLabel(tr("Delegate:")), 1, 0); 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(new QLabel(tr("Size:")), 2, 0);
layout->addWidget(_size_layout_select, 2, 1, 1, 2); layout->addWidget(_size_layout_select, 2, 1, 1, 2);
@ -150,14 +150,115 @@ ListBasedConfiguration::ListBasedConfiguration(
layout->setRowStretch(7, 1); layout->setRowStretch(7, 1);
layout->setColumnStretch(1, 1); layout->setColumnStretch(1, 1);
connect(_offset_enter, QOverload<int>::of(&QSpinBox::valueChanged),
[=](int v) {
this->_bind_u->setOffsetSpan(v);
currentAccept(_bind_u, _bind_index, _fields_getter);
emit this->reloadRequest();
});
connect(_delegate_select, QOverload<const QString&>::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<ExtractDelegate>(delt_ins));
currentAccept(_bind_u, _bind_index, _fields_getter);
emit this->reloadRequest();
});
connect(_size_layout_select, QOverload<const QString&>::of(&QComboBox::currentTextChanged),
[=](const QString& size_provider_name) {
auto size_o = _bind_core->sizeProviderMap()[size_provider_name];
auto size_ins = std::dynamic_pointer_cast<SizeProvider>(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<int>::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<const QString&>::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<ExtractUnit> inst_u, const QModelIndex& idx) void ListBasedConfiguration::currentAccept(std::shared_ptr<ExtractUnit> inst_u,
const QModelIndex& idx, std::shared_ptr<ScopeFieldsGetter> get)
{ {
_bind_u = std::dynamic_pointer_cast<ListBasedUnit>(inst_u); _bind_u = std::dynamic_pointer_cast<ListBasedUnit>(inst_u);
_bind_index = idx; _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<extract::ListBasedUnit>(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<ConstNumberProvider>(_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<InterpretedNumberPrivider>(_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<TranslateBasic> core, QWidget* p /*= nullptr*/) SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p /*= nullptr*/)
@ -179,6 +280,7 @@ SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptr<TranslateBasi
connect(this->_offset_enter, QOverload<int>::of(&QSpinBox::valueChanged), connect(this->_offset_enter, QOverload<int>::of(&QSpinBox::valueChanged),
[=](int v_offset) { [=](int v_offset) {
inst_current->setOffsetSpan(v_offset); inst_current->setOffsetSpan(v_offset);
currentAccept(this->inst_current, this->idx_current);
emit this->reloadRequest(); emit this->reloadRequest();
}); });
connect(this->_delegate_changed, QOverload<const QString&>::of(&QComboBox::currentTextChanged), connect(this->_delegate_changed, QOverload<const QString&>::of(&QComboBox::currentTextChanged),
@ -189,6 +291,7 @@ SingleBasedConfiguration::SingleBasedConfiguration(std::shared_ptr<TranslateBasi
o_inst->saveTo(content); o_inst->saveTo(content);
v_inst->loadFrom(_bind_core, content); v_inst->loadFrom(_bind_core, content);
inst_current->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(v_inst)); inst_current->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(v_inst));
currentAccept(this->inst_current, this->idx_current);
emit this->reloadRequest(); emit this->reloadRequest();
}); });
} }

View File

@ -40,9 +40,10 @@ namespace unit_configurations {
Q_OBJECT Q_OBJECT
private: private:
std::shared_ptr<TranslateBasic> _bind_core; std::shared_ptr<TranslateBasic> _bind_core;
QSpinBox* const _offset_enter; QSpinBox* const _offset_enter;
QPushButton* const _delegate_sync; QPushButton* const _delegate_sync;
QComboBox* const _rule_select; QComboBox* const _delegate_select;
QComboBox* const _size_layout_select; QComboBox* const _size_layout_select;
QStackedWidget* const _configs_stack; QStackedWidget* const _configs_stack;
QTextBrowser* const _content_display; QTextBrowser* const _content_display;
@ -51,11 +52,13 @@ namespace unit_configurations {
QComboBox* const _prev_field_refer; QComboBox* const _prev_field_refer;
std::shared_ptr<extract::ListBasedUnit> _bind_u = nullptr; std::shared_ptr<extract::ListBasedUnit> _bind_u = nullptr;
std::shared_ptr<ScopeFieldsGetter> _fields_getter = nullptr;
QModelIndex _bind_index; QModelIndex _bind_index;
public: public:
ListBasedConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p = nullptr); ListBasedConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p = nullptr);
void currentAccept(std::shared_ptr<ExtractUnit> inst_u, const QModelIndex& idx); void currentAccept(std::shared_ptr<ExtractUnit> inst_u,
const QModelIndex& idx, std::shared_ptr<ScopeFieldsGetter> get);
signals: signals:
void reloadRequest(); void reloadRequest();

View File

@ -163,7 +163,7 @@ void ConstNumberProvider::bindInput(std::shared_ptr<DataContext> inst)
QString ConstNumberProvider::name() const QString ConstNumberProvider::name() const
{ {
return NAME(ConstNumberProvider); return topic();
} }
int32_t ConstNumberProvider::value(const QString& expr) const int32_t ConstNumberProvider::value(const QString& expr) const
@ -196,6 +196,11 @@ std::shared_ptr<Serializable> ConstNumberProvider::newDefault() const
return std::make_shared<ConstNumberProvider>(); return std::make_shared<ConstNumberProvider>();
} }
QString ConstNumberProvider::topic()
{
return NAME(ConstNumberProvider);
}
void InterpretedNumberPrivider::bindInput(std::shared_ptr<DataContext> inst) void InterpretedNumberPrivider::bindInput(std::shared_ptr<DataContext> inst)
{ {
this->_refer._context_inst = inst; this->_refer._context_inst = inst;
@ -203,7 +208,7 @@ void InterpretedNumberPrivider::bindInput(std::shared_ptr<DataContext> inst)
QString InterpretedNumberPrivider::name() const QString InterpretedNumberPrivider::name() const
{ {
return NAME(InterpretedNumberPrivider); return topic();
} }
#include <QMetaType> #include <QMetaType>
@ -243,6 +248,11 @@ std::shared_ptr<Serializable> InterpretedNumberPrivider::newDefault() const
return std::make_shared<InterpretedNumberPrivider>(); return std::make_shared<InterpretedNumberPrivider>();
} }
QString InterpretedNumberPrivider::topic()
{
return NAME(InterpretedNumberPrivider);
}
void ValueAccessContext::init(const QString& field, std::shared_ptr<DataContext> parent) void ValueAccessContext::init(const QString& field, std::shared_ptr<DataContext> parent)
{ {
this->_cascade._current_field = field; this->_cascade._current_field = field;

View File

@ -157,6 +157,7 @@ namespace size_provider {
} _number; } _number;
public: public:
static QString topic();
QString name() const override; QString name() const override;
void bindInput(std::shared_ptr<DataContext> inst) override; void bindInput(std::shared_ptr<DataContext> inst) override;
@ -184,6 +185,7 @@ namespace size_provider {
public: public:
static QString topic();
QString name() const override; QString name() const override;
void bindInput(std::shared_ptr<DataContext> inst) override; void bindInput(std::shared_ptr<DataContext> inst) override;