This commit is contained in:
codeboss 2025-08-05 22:48:54 +08:00
parent 82511649d2
commit ff2ca20a6a
6 changed files with 77 additions and 45 deletions

View File

@ -39,6 +39,30 @@ void IntDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewIt
void RuleSetCustom::targetRuleRefresh(const QModelIndex& idx) 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<ExtractUnit>(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<AsList>(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 rule_insv = (*_view._ruleset)[idx.row()];
auto offset_index = idx.sibling(idx.row(), 1); auto offset_index = idx.sibling(idx.row(), 1);
@ -58,33 +82,6 @@ void RuleSetCustom::targetRuleRefresh(const QModelIndex& idx)
this->resizeColumnsToContents(); 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<ExtractUnit>(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<AsList>(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) void RuleSetCustom::showEvent(QShowEvent* e)
{ {
QTableView::showEvent(e); QTableView::showEvent(e);
@ -112,7 +109,6 @@ RuleSetCustom::RuleSetCustom(std::shared_ptr<TranslateBasic> base,
this->setContextMenuPolicy(Qt::CustomContextMenu); this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QTableView::customContextMenuRequested, this, &RuleSetCustom::customTranslateRuleEdit); 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(_view._seqs_model, &QAbstractItemModel::dataChanged, this, &RuleSetCustom::targetRuleRefresh);
connect(this, &QTableView::clicked, [=](const QModelIndex& curr) { connect(this, &QTableView::clicked, [=](const QModelIndex& curr) {
@ -204,8 +200,6 @@ void RuleSelectDelegate::setModelData(QWidget* editor, QAbstractItemModel* model
{ {
auto rule_name = dynamic_cast<QComboBox*>(editor)->currentText(); auto rule_name = dynamic_cast<QComboBox*>(editor)->currentText();
model->setData(index, rule_name, Qt::EditRole); model->setData(index, rule_name, Qt::EditRole);
emit this->dataChanged(index);
} }
void RuleSelectDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const void RuleSelectDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const

View File

@ -36,9 +36,6 @@ namespace unit_func {
private: private:
std::shared_ptr<TranslateBasic> _kernel; std::shared_ptr<TranslateBasic> _kernel;
signals:
void dataChanged(const QModelIndex& idx) const;
public: public:
RuleSelectDelegate(std::shared_ptr<TranslateBasic> ins); RuleSelectDelegate(std::shared_ptr<TranslateBasic> ins);
@ -66,7 +63,6 @@ signals:
public: public:
void targetRuleRefresh(const QModelIndex& idx); void targetRuleRefresh(const QModelIndex& idx);
void peersRuleChanged(const QModelIndex& idx_rule);
protected: protected:
void showEvent(QShowEvent* e) override; void showEvent(QShowEvent* e) override;

View File

@ -317,10 +317,18 @@ ListUnitConfiguration::ListUnitConfiguration(
connect(_size_layout_select, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(_size_layout_select, QOverload<int>::of(&QComboBox::currentIndexChanged),
[=](int idx) { [=](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, connect(this->_rule_select, &QComboBox::currentTextChanged,
this, &ListUnitConfiguration::elmRuleSet); this, &ListUnitConfiguration::elmRuleSet);
connect(this->_const_number_input, QOverload<int>::of(&QSpinBox::valueChanged),
this, &ListUnitConfiguration::constProviderBind);
connect(this->_prev_field_refer, &QComboBox::currentTextChanged,
this, &ListUnitConfiguration::fieldProviderBind);
} }
void ListUnitConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, void ListUnitConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u,
@ -375,3 +383,39 @@ void ListUnitConfiguration::elmRuleSet(const QString& name)
emit this->currentRuleChanged(this->_bind_index); 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<SizeProvider>(ninst));
auto u = this->_bind_u;
auto const_conv = std::dynamic_pointer_cast<ConstNumberProvider>(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<InterpretedNumberPrivider>(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);
}

View File

@ -101,6 +101,9 @@ namespace configuration_panel {
QComboBox* const _prev_field_refer; QComboBox* const _prev_field_refer;
void elmRuleSet(const QString &name); void elmRuleSet(const QString &name);
void sizeProviderSet(const QString &name);
void constProviderBind(int value);
void fieldProviderBind(const QString &name);
public: public:
ListUnitConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p = nullptr); ListUnitConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p = nullptr);

View File

@ -163,9 +163,11 @@ QString InterpretedNumberPrivider::name() const
#include <QMetaType> #include <QMetaType>
int32_t InterpretedNumberPrivider::value(const QString& expr) const int32_t InterpretedNumberPrivider::value(const QString& expr) const
{ {
auto value = this->_refer._context_inst->get(expr); if (this->_refer._context_inst) {
if (value.userType() == QMetaType::Int) auto value = this->_refer._context_inst->get(expr);
return value.toInt(); if (value.userType() == QMetaType::Int)
return value.toInt();
}
return 0; return 0;
} }

View File

@ -406,10 +406,6 @@ void AsList::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& o
xdev = core->extractUnitList()[bind_unit_name]->newDefault(); xdev = core->extractUnitList()[bind_unit_name]->newDefault();
this->_list._bind_unit = std::dynamic_pointer_cast<ExtractUnit>(xdev); this->_list._bind_unit = std::dynamic_pointer_cast<ExtractUnit>(xdev);
QString bind_provider_expr = "";
STRING_SAVE(bind_provider_expr, obj);
this->_list._bind_size_v->setExpression(bind_provider_expr);
QJsonObject unit_obj; QJsonObject unit_obj;
QJsonObject size_provider_obj; QJsonObject size_provider_obj;
OBJECT_PEAK(unit_obj, obj); OBJECT_PEAK(unit_obj, obj);
@ -434,15 +430,12 @@ void AsList::saveTo(QJsonObject& obj) const
OBJECT_SAVE(unit_obj, obj); OBJECT_SAVE(unit_obj, obj);
QString bind_size_provider_name = ""; QString bind_size_provider_name = "";
QString bind_provider_expr = "";
QJsonObject size_provider_obj; QJsonObject size_provider_obj;
if (this->_list._bind_size_v) { 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(); bind_size_provider_name = this->_list._bind_size_v->name();
this->_list._bind_size_v->saveTo(size_provider_obj); this->_list._bind_size_v->saveTo(size_provider_obj);
} }
STRING_SAVE(bind_size_provider_name, obj); STRING_SAVE(bind_size_provider_name, obj);
STRING_SAVE(bind_provider_expr, obj);
OBJECT_SAVE(size_provider_obj, obj); OBJECT_SAVE(size_provider_obj, obj);
} }