完善ListBaseUnit配置机制
This commit is contained in:
parent
ac9b0f4e2c
commit
4d39cdc278
|
@ -56,6 +56,7 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
|||
}
|
||||
else if (unit->baseType() == ListBasedUnit::topic()) {
|
||||
_configs_stack->setCurrentIndex(2);
|
||||
FieldManagerLayer::__Private::fields_map.clear();
|
||||
_current_fields_cache = std::make_shared<FieldManagerLayer>("{self}");
|
||||
this->_current_rule->registSubField(_current_fields_cache);
|
||||
auto current_field = this->_current_rule->operator[](target.row());
|
||||
|
@ -145,10 +146,15 @@ void ExtractRuleView::dataChanged(QStandardItem* item)
|
|||
}break;
|
||||
|
||||
case 2: {
|
||||
// 提取Template名称
|
||||
auto unit_template = this->_basic_bind->extractUnitTypeMap()[item->text()];
|
||||
// 创建新单元副本
|
||||
auto unit_ins = std::dynamic_pointer_cast<ExtractUnit>(unit_template->newDefault());
|
||||
unit_ins->setName(current_unit->name());
|
||||
// 替换旧有单元类型
|
||||
this->_current_rule->replace(item->row(), unit_ins);
|
||||
|
||||
// 单数据解构类型
|
||||
if (unit_ins->baseType() == SingleBasedUnit::topic()) {
|
||||
auto single_ins = std::dynamic_pointer_cast<SingleBasedUnit>(unit_ins);
|
||||
|
||||
|
@ -160,6 +166,25 @@ void ExtractRuleView::dataChanged(QStandardItem* item)
|
|||
delt_conv->loadFrom(_basic_bind, object);
|
||||
single_ins->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(delt_conv));
|
||||
}
|
||||
// 列表数据解构类型
|
||||
if (unit_ins->baseType() == ListBasedUnit::topic()) {
|
||||
auto list_ins = std::dynamic_pointer_cast<ListBasedUnit>(unit_ins);
|
||||
|
||||
auto delt_name = _basic_bind->customDelegateAlias().first();
|
||||
auto delt_base = _basic_bind->operator[](delt_name);
|
||||
QJsonObject object;
|
||||
delt_base->saveTo(object);
|
||||
auto delt_elm = std::dynamic_pointer_cast<ExtractDelegate>(delt_base->newDefault());
|
||||
delt_elm->loadFrom(_basic_bind, object);
|
||||
list_ins->setDelegate(delt_elm);
|
||||
|
||||
auto size_o = _basic_bind->defaultSizeProviderType();
|
||||
QJsonObject mobject;
|
||||
size_o->saveTo(mobject);
|
||||
auto size_copy = std::dynamic_pointer_cast<SizeProvider>(size_o->newDefault());
|
||||
size_copy->loadFrom(_basic_bind, mobject);
|
||||
list_ins->setSizeProvider(size_copy);
|
||||
}
|
||||
|
||||
}break;
|
||||
|
||||
|
@ -197,7 +222,8 @@ ListBasedConfiguration::ListBasedConfiguration(
|
|||
layout->addWidget(new QLabel(tr("Size:")), 2, 0);
|
||||
layout->addWidget(_size_layout_select, 2, 1, 1, 2);
|
||||
|
||||
layout->addWidget(_configs_stack, 3, 0, 2, 3);
|
||||
layout->addWidget(new QLabel(tr("Exprs:")), 3, 0);
|
||||
layout->addWidget(_configs_stack, 3, 1, 2, 3);
|
||||
_configs_stack->addWidget(_const_number_input);
|
||||
_configs_stack->addWidget(_prev_field_refer);
|
||||
|
||||
|
@ -246,7 +272,7 @@ ListBasedConfiguration::ListBasedConfiguration(
|
|||
switch (fields_map[field_name]) {
|
||||
case DataType::Integer:
|
||||
case DataType::Unsigned:
|
||||
_prev_field_refer->addItem(field_name);
|
||||
_prev_field_refer->addItem(tr("BindField:") + field_name, field_name);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -265,7 +291,8 @@ ListBasedConfiguration::ListBasedConfiguration(
|
|||
emit this->reloadRequest();
|
||||
});
|
||||
connect(_prev_field_refer, QOverload<const QString&>::of(&QComboBox::currentTextChanged),
|
||||
[=](const QString& current_field) {
|
||||
[=]() {
|
||||
auto current_field = _prev_field_refer->currentData().toString();
|
||||
auto size_ins = _bind_u->sizeProvider();
|
||||
size_ins->setExpression(current_field);
|
||||
|
||||
|
@ -312,13 +339,22 @@ void ListBasedConfiguration::currentAccept(std::shared_ptr<ExtractUnit> inst_u,
|
|||
switch (fields_map[field_name]) {
|
||||
case DataType::Integer:
|
||||
case DataType::Unsigned:
|
||||
_prev_field_refer->addItem(field_name);
|
||||
_prev_field_refer->addItem(tr("BindField:") + field_name, field_name);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_prev_field_refer->setCurrentText(size_rt->expression());
|
||||
if (size_rt->expression() == QString()) {
|
||||
auto text_expr = _prev_field_refer->currentData().toString();
|
||||
size_rt->setExpression(text_expr);
|
||||
}
|
||||
for (auto idx = 0; idx < _prev_field_refer->count(); ++idx) {
|
||||
auto expr_t = _prev_field_refer->itemData(idx).toString();
|
||||
if (size_rt->expression() == expr_t) {
|
||||
_prev_field_refer->setCurrentIndex(idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QJsonObject content;
|
||||
|
|
|
@ -44,7 +44,7 @@ void AbstractExtractor::saveTo(QJsonObject& obj) const
|
|||
INT32_SAVE(_abs_data.byte_count, obj);
|
||||
}
|
||||
|
||||
void AbstractExtractor::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) {}
|
||||
void AbstractExtractor::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const {}
|
||||
|
||||
QString AbstractExtractor::aliasName() const
|
||||
{
|
||||
|
@ -332,7 +332,7 @@ QString AsUnsigned::topic()
|
|||
}
|
||||
|
||||
#include <stdexcept>
|
||||
void AsRuleSet::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
|
||||
void AsRuleSet::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const
|
||||
{
|
||||
for (auto subrule : _bind.sub_units) {
|
||||
subrule->registSubField(inst);
|
||||
|
@ -501,7 +501,7 @@ void SingleBasedUnit::setDelegate(std::shared_ptr<ExtractDelegate> inst)
|
|||
_inst._delegate_inst = inst;
|
||||
}
|
||||
|
||||
void SingleBasedUnit::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
|
||||
void SingleBasedUnit::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const
|
||||
{
|
||||
inst->setField(name(), _inst._delegate_inst->outType());
|
||||
|
||||
|
@ -606,7 +606,7 @@ void ListBasedUnit::setDelegate(std::shared_ptr<ExtractDelegate> inst)
|
|||
_list.delegate_inst = inst;
|
||||
}
|
||||
|
||||
void ListBasedUnit::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) {}
|
||||
void ListBasedUnit::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const {}
|
||||
|
||||
int ListBasedUnit::countWithin() const
|
||||
{
|
||||
|
@ -735,7 +735,7 @@ int UnionBasedUnit::offsetSpan() const
|
|||
return _union.bytes_offset;
|
||||
}
|
||||
|
||||
void UnionBasedUnit::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) {}
|
||||
void UnionBasedUnit::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const {}
|
||||
|
||||
int UnionBasedUnit::countWithin() const
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ public:
|
|||
/// 注册自身
|
||||
/// </summary>
|
||||
/// <param typeAlias="inst"></param>
|
||||
virtual void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) = 0;
|
||||
virtual void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 解析所用的字节数量
|
||||
|
@ -115,7 +115,7 @@ namespace extract {
|
|||
void setAlias(const QString& name) override;
|
||||
|
||||
// ExtractStruct ============================
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const override;
|
||||
|
||||
// Serializable ==============================
|
||||
void loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) override;
|
||||
|
@ -258,7 +258,7 @@ namespace extract {
|
|||
|
||||
public:
|
||||
QString unitType() const override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const override;
|
||||
DataType outType() const override;
|
||||
int countWithin() const override;
|
||||
|
||||
|
@ -297,7 +297,7 @@ namespace extract {
|
|||
|
||||
virtual int countWithin() const;
|
||||
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const override;
|
||||
void parse(const QByteArray& bytes, std::shared_ptr<DataContext> out) const override;
|
||||
|
||||
void loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) override;
|
||||
|
@ -329,7 +329,7 @@ namespace extract {
|
|||
QString name() const override;
|
||||
void setName(const QString& name) override;
|
||||
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const override;
|
||||
bool setOffsetSpan(int bytes) override;
|
||||
int offsetSpan() const override;
|
||||
int countWithin() const override;
|
||||
|
@ -359,7 +359,7 @@ namespace extract {
|
|||
public:
|
||||
static QString topic();
|
||||
QString baseType() const override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) const override;
|
||||
|
||||
QString name() const override;
|
||||
void setName(const QString& name) override;
|
||||
|
|
Loading…
Reference in New Issue