update:添加unit、添加field基础逻辑
This commit is contained in:
parent
0d2a32faea
commit
ac9b0f4e2c
|
|
@ -20,7 +20,7 @@ using namespace extract;
|
||||||
|
|
||||||
ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
||||||
std::shared_ptr<extract::AsRuleSet> inst_r, QWidget* p /*= nullptr*/)
|
std::shared_ptr<extract::AsRuleSet> inst_r, QWidget* p /*= nullptr*/)
|
||||||
: QWidget(p), _rule_base(inst_r), _base_bind(base),
|
: QWidget(p), _current_rule(inst_r), _basic_bind(base),
|
||||||
_member_units(new QTableView(this)),
|
_member_units(new QTableView(this)),
|
||||||
_member_model(new QStandardItemModel(this)),
|
_member_model(new QStandardItemModel(this)),
|
||||||
_configs_stack(new QStackedWidget(this))
|
_configs_stack(new QStackedWidget(this))
|
||||||
|
|
@ -42,11 +42,14 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
||||||
auto union_configs = new UnionBasedConfiguration(base, this);
|
auto union_configs = new UnionBasedConfiguration(base, this);
|
||||||
_configs_stack->addWidget(union_configs);
|
_configs_stack->addWidget(union_configs);
|
||||||
|
|
||||||
|
connect(single_configs, &SingleBasedConfiguration::reloadRequest, this, &ExtractRuleView::reload);
|
||||||
|
connect(list_configs, &ListBasedConfiguration::reloadRequest, this, &ExtractRuleView::reload);
|
||||||
|
connect(union_configs, &UnionBasedConfiguration::reloadRequest, this, &ExtractRuleView::reload);
|
||||||
connect(_member_units, &QTableView::clicked, [=](const QModelIndex& target) {
|
connect(_member_units, &QTableView::clicked, [=](const QModelIndex& target) {
|
||||||
if (!target.isValid())
|
if (!target.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto unit = _rule_base->operator[](target.row());
|
auto unit = _current_rule->operator[](target.row());
|
||||||
if (unit->baseType() == SingleBasedUnit::topic()) {
|
if (unit->baseType() == SingleBasedUnit::topic()) {
|
||||||
_configs_stack->setCurrentIndex(1);
|
_configs_stack->setCurrentIndex(1);
|
||||||
single_configs->currentAccept(unit, target);
|
single_configs->currentAccept(unit, target);
|
||||||
|
|
@ -54,8 +57,8 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
||||||
else if (unit->baseType() == ListBasedUnit::topic()) {
|
else if (unit->baseType() == ListBasedUnit::topic()) {
|
||||||
_configs_stack->setCurrentIndex(2);
|
_configs_stack->setCurrentIndex(2);
|
||||||
_current_fields_cache = std::make_shared<FieldManagerLayer>("{self}");
|
_current_fields_cache = std::make_shared<FieldManagerLayer>("{self}");
|
||||||
this->_rule_base->registSubField(_current_fields_cache);
|
this->_current_rule->registSubField(_current_fields_cache);
|
||||||
auto current_field = this->_rule_base->operator[](target.row());
|
auto current_field = this->_current_rule->operator[](target.row());
|
||||||
_current_fields_cache->bindCurrent(current_field->name());
|
_current_fields_cache->bindCurrent(current_field->name());
|
||||||
list_configs->currentAccept(unit, target, _current_fields_cache);
|
list_configs->currentAccept(unit, target, _current_fields_cache);
|
||||||
}
|
}
|
||||||
|
|
@ -69,6 +72,8 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
||||||
});
|
});
|
||||||
|
|
||||||
_member_units->setModel(_member_model);
|
_member_units->setModel(_member_model);
|
||||||
|
connect(_member_model, &QStandardItemModel::itemChanged, this, &ExtractRuleView::dataChanged);
|
||||||
|
_member_units->setItemDelegateForColumn(2, new UnitSelectDelegate(_basic_bind));
|
||||||
_member_model->setHorizontalHeaderLabels(QStringList() << "FieldName" << "OffsetSpan" << "UnitType");
|
_member_model->setHorizontalHeaderLabels(QStringList() << "FieldName" << "OffsetSpan" << "UnitType");
|
||||||
_member_units->setContextMenuPolicy(Qt::CustomContextMenu);
|
_member_units->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(_member_units, &QTableView::customContextMenuRequested, [=](const QPoint& pt) {
|
connect(_member_units, &QTableView::customContextMenuRequested, [=](const QPoint& pt) {
|
||||||
|
|
@ -83,12 +88,12 @@ void ExtractRuleView::reload()
|
||||||
auto cnt = _member_model->rowCount();
|
auto cnt = _member_model->rowCount();
|
||||||
_member_model->removeRows(0, cnt);
|
_member_model->removeRows(0, cnt);
|
||||||
|
|
||||||
auto list = _rule_base->fieldNames();
|
auto list = _current_rule->fieldNames();
|
||||||
for (auto key : list) {
|
for (auto key : list) {
|
||||||
auto field_mbr = _rule_base->operator[](key);
|
auto field_mbr = _current_rule->operator[](key);
|
||||||
QList<QStandardItem*> row;
|
QList<QStandardItem*> row;
|
||||||
row << new QStandardItem(field_mbr->name());
|
row << new QStandardItem(field_mbr->name());
|
||||||
row << new QStandardItem(QString("%1").arg(field_mbr->offsetSpan()));
|
row << new QStandardItem(QString("%1 bytes").arg(field_mbr->offsetSpan()));
|
||||||
row.last()->setEditable(false);
|
row.last()->setEditable(false);
|
||||||
row << new QStandardItem(field_mbr->baseType());
|
row << new QStandardItem(field_mbr->baseType());
|
||||||
_member_model->appendRow(row);
|
_member_model->appendRow(row);
|
||||||
|
|
@ -96,6 +101,7 @@ void ExtractRuleView::reload()
|
||||||
_member_units->resizeColumnsToContents();
|
_member_units->resizeColumnsToContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
void ExtractRuleView::appendUnit()
|
void ExtractRuleView::appendUnit()
|
||||||
{
|
{
|
||||||
|
|
@ -103,21 +109,66 @@ void ExtractRuleView::appendUnit()
|
||||||
if (name_u == "")
|
if (name_u == "")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto inst_u = _base_bind->defaultExtractUnitType()->newDefault();
|
if (this->_current_rule->fieldNames().contains(name_u)) {
|
||||||
auto new_unit = std::dynamic_pointer_cast<SingleBasedUnit>(inst_u);
|
QMessageBox::critical(this, "DataValidate", "Field can't repeat");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto unit_template = _basic_bind->defaultExtractUnitType()->newDefault();
|
||||||
|
auto new_unit = std::dynamic_pointer_cast<SingleBasedUnit>(unit_template);
|
||||||
new_unit->setName(name_u);
|
new_unit->setName(name_u);
|
||||||
auto delt_key = _base_bind->delegateAlias().first();
|
auto delt_key = _basic_bind->customDelegateAlias().first();
|
||||||
auto delt_o = _base_bind->operator[](delt_key);
|
auto delt_o = _basic_bind->operator[](delt_key);
|
||||||
auto delt_u = delt_o->newDefault();
|
|
||||||
QJsonObject content;
|
QJsonObject content;
|
||||||
delt_o->saveTo(content);
|
delt_o->saveTo(content);
|
||||||
delt_u->loadFrom(_base_bind, content);
|
auto delt_u = delt_o->newDefault();
|
||||||
|
delt_u->loadFrom(_basic_bind, content);
|
||||||
new_unit->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(delt_u));
|
new_unit->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(delt_u));
|
||||||
this->_rule_base->append(new_unit);
|
this->_current_rule->append(new_unit);
|
||||||
|
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExtractRuleView::dataChanged(QStandardItem* item)
|
||||||
|
{
|
||||||
|
auto current_unit = this->_current_rule->operator[](item->row());
|
||||||
|
switch (item->column()) {
|
||||||
|
case 0: {
|
||||||
|
auto fields_names = this->_current_rule->fieldNames();
|
||||||
|
if (fields_names.contains(item->text())) {
|
||||||
|
QMessageBox::critical(this, "DataValidate", "Field can't repeat");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
current_unit->setName(item->text());
|
||||||
|
}
|
||||||
|
reload();
|
||||||
|
}break;
|
||||||
|
|
||||||
|
case 2: {
|
||||||
|
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());
|
||||||
|
|
||||||
|
if (unit_ins->baseType() == SingleBasedUnit::topic()) {
|
||||||
|
auto single_ins = std::dynamic_pointer_cast<SingleBasedUnit>(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_conv = std::dynamic_pointer_cast<ExtractDelegate>(delt_base->newDefault());
|
||||||
|
delt_conv->loadFrom(_basic_bind, object);
|
||||||
|
single_ins->setDelegate(std::dynamic_pointer_cast<ExtractDelegate>(delt_conv));
|
||||||
|
}
|
||||||
|
|
||||||
|
}break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ExtractRuleView::showEvent(QShowEvent* e)
|
void ExtractRuleView::showEvent(QShowEvent* e)
|
||||||
{
|
{
|
||||||
QWidget::showEvent(e);
|
QWidget::showEvent(e);
|
||||||
|
|
@ -176,7 +227,7 @@ ListBasedConfiguration::ListBasedConfiguration(
|
||||||
});
|
});
|
||||||
connect(_size_layout_select, QOverload<const QString&>::of(&QComboBox::currentTextChanged),
|
connect(_size_layout_select, QOverload<const QString&>::of(&QComboBox::currentTextChanged),
|
||||||
[=](const QString& size_provider_name) {
|
[=](const QString& size_provider_name) {
|
||||||
auto size_o = _bind_core->sizeProviderMap()[size_provider_name];
|
auto size_o = _bind_core->sizeProviderTypeMap()[size_provider_name];
|
||||||
auto size_ins = std::dynamic_pointer_cast<SizeProvider>(size_o->newDefault());
|
auto size_ins = std::dynamic_pointer_cast<SizeProvider>(size_o->newDefault());
|
||||||
this->_bind_u->setSizeProvider(size_ins);
|
this->_bind_u->setSizeProvider(size_ins);
|
||||||
|
|
||||||
|
|
@ -237,12 +288,12 @@ void ListBasedConfiguration::currentAccept(std::shared_ptr<ExtractUnit> inst_u,
|
||||||
QSignalBlocker vx(_delegate_select);
|
QSignalBlocker vx(_delegate_select);
|
||||||
this->_bind_u = std::dynamic_pointer_cast<extract::ListBasedUnit>(inst_u);
|
this->_bind_u = std::dynamic_pointer_cast<extract::ListBasedUnit>(inst_u);
|
||||||
_delegate_select->clear();
|
_delegate_select->clear();
|
||||||
_delegate_select->addItems(_bind_core->delegateAlias());
|
_delegate_select->addItems(_bind_core->customDelegateAlias());
|
||||||
_delegate_select->setCurrentText(this->_bind_u->delegateInst()->aliasName());
|
_delegate_select->setCurrentText(this->_bind_u->delegateInst()->aliasName());
|
||||||
|
|
||||||
QSignalBlocker vv(_size_layout_select);
|
QSignalBlocker vv(_size_layout_select);
|
||||||
this->_size_layout_select->clear();
|
this->_size_layout_select->clear();
|
||||||
this->_size_layout_select->addItems(_bind_core->sizeProviderMap().keys());
|
this->_size_layout_select->addItems(_bind_core->sizeProviderTypeMap().keys());
|
||||||
this->_size_layout_select->setCurrentText(_bind_u->sizeProvider()->name());
|
this->_size_layout_select->setCurrentText(_bind_u->sizeProvider()->name());
|
||||||
if (this->_size_layout_select->currentText() == ConstNumberProvider::topic()) {
|
if (this->_size_layout_select->currentText() == ConstNumberProvider::topic()) {
|
||||||
_configs_stack->setCurrentIndex(0);
|
_configs_stack->setCurrentIndex(0);
|
||||||
|
|
@ -323,7 +374,7 @@ void SingleBasedConfiguration::currentAccept(std::shared_ptr<ExtractUnit> inst_u
|
||||||
|
|
||||||
QSignalBlocker v(_delegate_changed);
|
QSignalBlocker v(_delegate_changed);
|
||||||
_delegate_changed->clear();
|
_delegate_changed->clear();
|
||||||
_delegate_changed->addItems(_bind_core->delegateAlias());
|
_delegate_changed->addItems(_bind_core->customDelegateAlias());
|
||||||
auto conv = std::dynamic_pointer_cast<SingleBasedUnit>(inst_u);
|
auto conv = std::dynamic_pointer_cast<SingleBasedUnit>(inst_u);
|
||||||
_delegate_changed->setCurrentText(conv->delegateInst()->aliasName());
|
_delegate_changed->setCurrentText(conv->delegateInst()->aliasName());
|
||||||
|
|
||||||
|
|
@ -343,3 +394,32 @@ void UnionBasedConfiguration::currentAccept(std::shared_ptr<ExtractUnit> inst_u,
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UnitSelectDelegate::UnitSelectDelegate(std::shared_ptr<TranslateBasic> ins)
|
||||||
|
: _kernel(ins)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget* UnitSelectDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
return new QComboBox(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitSelectDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
auto combo = dynamic_cast<QComboBox*>(editor);
|
||||||
|
combo->addItems(_kernel->extractUnitTypeMap().keys());
|
||||||
|
combo->setCurrentText(index.data(Qt::DisplayRole).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitSelectDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
auto combo = dynamic_cast<QComboBox*>(editor);
|
||||||
|
model->setData(index, combo->currentText(), Qt::EditRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitSelectDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
editor->setGeometry(option.rect);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,26 +75,41 @@ namespace unit_configurations {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
class UnitSelectDelegate : public QStyledItemDelegate {
|
||||||
|
private:
|
||||||
|
std::shared_ptr<TranslateBasic> _kernel;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UnitSelectDelegate(std::shared_ptr<TranslateBasic> ins);
|
||||||
|
|
||||||
|
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
|
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
||||||
|
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
||||||
|
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
|
};
|
||||||
|
|
||||||
class ExtractRuleView : public QWidget
|
class ExtractRuleView : public QWidget
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<TranslateBasic> _basic_bind;
|
||||||
|
|
||||||
QTableView* const _member_units;
|
QTableView* const _member_units;
|
||||||
QStandardItemModel* const _member_model;
|
QStandardItemModel* const _member_model;
|
||||||
QStackedWidget* const _configs_stack;
|
QStackedWidget* const _configs_stack;
|
||||||
|
|
||||||
std::shared_ptr<extract::AsRuleSet> _rule_base;
|
std::shared_ptr<extract::AsRuleSet> _current_rule;
|
||||||
std::shared_ptr<TranslateBasic> _base_bind;
|
|
||||||
std::shared_ptr<FieldManagerLayer> _current_fields_cache = nullptr;
|
std::shared_ptr<FieldManagerLayer> _current_fields_cache = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExtractRuleView(
|
ExtractRuleView(std::shared_ptr<TranslateBasic> base,
|
||||||
std::shared_ptr<TranslateBasic> base,
|
std::shared_ptr<extract::AsRuleSet> inst_r, QWidget* p = nullptr);
|
||||||
std::shared_ptr<extract::AsRuleSet> inst_r,
|
|
||||||
QWidget* p = nullptr);
|
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
void appendUnit();
|
void appendUnit();
|
||||||
|
|
||||||
|
void dataChanged(QStandardItem* item);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent* e) override;
|
void showEvent(QShowEvent* e) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -49,27 +49,27 @@ TranslateBasic::TranslateBasic()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ExtractDelegate> TranslateBasic::defaultExtractDelegateType() const
|
std::shared_ptr<ExtractDelegate> TranslateBasic::defaultExtractImplType() const
|
||||||
{
|
{
|
||||||
return _default_translate_rule;
|
return _default_translate_rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, std::shared_ptr<ExtractDelegate>> TranslateBasic::extractDelegateTypeMap() const
|
QHash<QString, std::shared_ptr<ExtractDelegate>> TranslateBasic::extractImplTypeMap() const
|
||||||
{
|
{
|
||||||
return _basic_extractor_types;
|
return _basic_extractor_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SizeProvider> TranslateBasic::defaultSizeProvider() const
|
std::shared_ptr<SizeProvider> TranslateBasic::defaultSizeProviderType() const
|
||||||
{
|
{
|
||||||
return _default_size_provider;
|
return _default_size_provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<RuleMatch> TranslateBasic::defaultRuleMatch() const
|
std::shared_ptr<RuleMatch> TranslateBasic::defaultRuleMatchType() const
|
||||||
{
|
{
|
||||||
return _default_rule_match;
|
return _default_rule_match;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslateBasic::addDelegate(std::shared_ptr<ExtractDelegate> inst)
|
void TranslateBasic::addCustomDelegate(std::shared_ptr<ExtractDelegate> inst)
|
||||||
{
|
{
|
||||||
auto repeat_name_count = std::count_if(
|
auto repeat_name_count = std::count_if(
|
||||||
this->_custom_rule_types.begin(), this->_custom_rule_types.end(),
|
this->_custom_rule_types.begin(), this->_custom_rule_types.end(),
|
||||||
|
|
@ -91,7 +91,7 @@ void TranslateBasic::addDelegate(std::shared_ptr<ExtractDelegate> inst)
|
||||||
this->_custom_rule_types << inst;
|
this->_custom_rule_types << inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslateBasic::removeDelegate(const QString& typeAlias)
|
void TranslateBasic::removeCustomDelegate(const QString& typeAlias)
|
||||||
{
|
{
|
||||||
for (auto idxp = 0; idxp< this->_custom_rule_types.size(); idxp++) {
|
for (auto idxp = 0; idxp< this->_custom_rule_types.size(); idxp++) {
|
||||||
auto rule = this->_custom_rule_types.at(idxp);
|
auto rule = this->_custom_rule_types.at(idxp);
|
||||||
|
|
@ -104,7 +104,7 @@ void TranslateBasic::removeDelegate(const QString& typeAlias)
|
||||||
throw new BaseException("指定RuleName不合法");
|
throw new BaseException("指定RuleName不合法");
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> TranslateBasic::delegateAlias() const
|
QList<QString> TranslateBasic::customDelegateAlias() const
|
||||||
{
|
{
|
||||||
QList<QString> values;
|
QList<QString> values;
|
||||||
std::transform(_custom_rule_types.begin(), _custom_rule_types.end(),
|
std::transform(_custom_rule_types.begin(), _custom_rule_types.end(),
|
||||||
|
|
@ -123,7 +123,7 @@ std::shared_ptr<ExtractDelegate> TranslateBasic::operator[](const QString& name)
|
||||||
throw new BaseException(u8"指定Name不存在");
|
throw new BaseException(u8"指定Name不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslateBasic::replaceDelegate(const QString& name, std::shared_ptr<ExtractDelegate> inst)
|
void TranslateBasic::replaceCustomDelegate(const QString& name, std::shared_ptr<ExtractDelegate> inst)
|
||||||
{
|
{
|
||||||
for (auto idx = 0; _custom_rule_types.size(); ++idx) {
|
for (auto idx = 0; _custom_rule_types.size(); ++idx) {
|
||||||
auto rule_inst = _custom_rule_types.at(idx);
|
auto rule_inst = _custom_rule_types.at(idx);
|
||||||
|
|
@ -136,12 +136,12 @@ void TranslateBasic::replaceDelegate(const QString& name, std::shared_ptr<Extrac
|
||||||
throw new BaseException(u8"指定Name不存在");
|
throw new BaseException(u8"指定Name不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, std::shared_ptr<SizeProvider>> TranslateBasic::sizeProviderMap() const
|
QHash<QString, std::shared_ptr<SizeProvider>> TranslateBasic::sizeProviderTypeMap() const
|
||||||
{
|
{
|
||||||
return _size_provider_types;
|
return _size_provider_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, std::shared_ptr<RuleMatch>> TranslateBasic::ruleMatchMap() const
|
QHash<QString, std::shared_ptr<RuleMatch>> TranslateBasic::ruleMatchTypeMap() const
|
||||||
{
|
{
|
||||||
return _rule_match_types;
|
return _rule_match_types;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,19 +130,19 @@ private:
|
||||||
public:
|
public:
|
||||||
TranslateBasic();
|
TranslateBasic();
|
||||||
|
|
||||||
std::shared_ptr<ExtractDelegate> defaultExtractDelegateType() const;
|
std::shared_ptr<ExtractDelegate> defaultExtractImplType() const;
|
||||||
QHash<QString, std::shared_ptr<ExtractDelegate>> extractDelegateTypeMap() const;
|
QHash<QString, std::shared_ptr<ExtractDelegate>> extractImplTypeMap() const;
|
||||||
std::shared_ptr<SizeProvider> defaultSizeProvider() const;
|
std::shared_ptr<SizeProvider> defaultSizeProviderType() const;
|
||||||
QHash<QString, std::shared_ptr<SizeProvider>> sizeProviderMap() const;
|
QHash<QString, std::shared_ptr<SizeProvider>> sizeProviderTypeMap() const;
|
||||||
std::shared_ptr<RuleMatch> defaultRuleMatch() const;
|
std::shared_ptr<RuleMatch> defaultRuleMatchType() const;
|
||||||
QHash<QString, std::shared_ptr<RuleMatch>> ruleMatchMap() const;
|
QHash<QString, std::shared_ptr<RuleMatch>> ruleMatchTypeMap() const;
|
||||||
std::shared_ptr<ExtractUnit> defaultExtractUnitType() const;
|
std::shared_ptr<ExtractUnit> defaultExtractUnitType() const;
|
||||||
QHash<QString, std::shared_ptr<ExtractUnit>> extractUnitTypeMap() const;
|
QHash<QString, std::shared_ptr<ExtractUnit>> extractUnitTypeMap() const;
|
||||||
|
|
||||||
void addDelegate(std::shared_ptr<ExtractDelegate> inst);
|
void addCustomDelegate(std::shared_ptr<ExtractDelegate> inst);
|
||||||
void removeDelegate(const QString& alias);
|
void removeCustomDelegate(const QString& alias);
|
||||||
void replaceDelegate(const QString &name, std::shared_ptr<ExtractDelegate> inst);
|
void replaceCustomDelegate(const QString &name, std::shared_ptr<ExtractDelegate> inst);
|
||||||
QList<QString> delegateAlias() const;
|
QList<QString> customDelegateAlias() const;
|
||||||
std::shared_ptr<ExtractDelegate> operator[](const QString &name) const;
|
std::shared_ptr<ExtractDelegate> operator[](const QString &name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ WrapConfigs::WrapConfigs(std::shared_ptr<TranslateBasic> _base, QWidget* p)
|
||||||
if (!idx.isValid())
|
if (!idx.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto alias_key = _bind_base->delegateAlias()[idx.row()];
|
auto alias_key = _bind_base->customDelegateAlias()[idx.row()];
|
||||||
auto delt_inst = _bind_base->operator[](alias_key);
|
auto delt_inst = _bind_base->operator[](alias_key);
|
||||||
switch (delt_inst->outType()) {
|
switch (delt_inst->outType()) {
|
||||||
case DataType::Flt32:
|
case DataType::Flt32:
|
||||||
|
|
@ -89,7 +89,7 @@ void WrapConfigs::aliasReload()
|
||||||
auto row_cnt = _alias_model->rowCount();
|
auto row_cnt = _alias_model->rowCount();
|
||||||
_alias_model->removeRows(0, row_cnt);
|
_alias_model->removeRows(0, row_cnt);
|
||||||
|
|
||||||
auto alias_keys = _bind_base->delegateAlias();
|
auto alias_keys = _bind_base->customDelegateAlias();
|
||||||
for (auto key_nm : alias_keys) {
|
for (auto key_nm : alias_keys) {
|
||||||
QList<QStandardItem*> row;
|
QList<QStandardItem*> row;
|
||||||
|
|
||||||
|
|
@ -125,15 +125,15 @@ void WrapConfigs::aliasAppend()
|
||||||
if (name == "")
|
if (name == "")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto exists = _bind_base->delegateAlias();
|
auto exists = _bind_base->customDelegateAlias();
|
||||||
while (exists.contains(name))
|
while (exists.contains(name))
|
||||||
name += "#";
|
name += "#";
|
||||||
|
|
||||||
auto ins = _bind_base->defaultExtractDelegateType()->newDefault();
|
auto ins = _bind_base->defaultExtractImplType()->newDefault();
|
||||||
auto nins = std::dynamic_pointer_cast<ExtractDelegate>(ins);
|
auto nins = std::dynamic_pointer_cast<ExtractDelegate>(ins);
|
||||||
nins->setAlias(name);
|
nins->setAlias(name);
|
||||||
|
|
||||||
_bind_base->addDelegate(nins);
|
_bind_base->addCustomDelegate(nins);
|
||||||
aliasReload();
|
aliasReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,8 +143,8 @@ void WrapConfigs::aliasRemove()
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto origin_key = _bind_base->delegateAlias()[index.row()];
|
auto origin_key = _bind_base->customDelegateAlias()[index.row()];
|
||||||
_bind_base->removeDelegate(origin_key);
|
_bind_base->removeCustomDelegate(origin_key);
|
||||||
aliasReload();
|
aliasReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ void WrapConfigs::dataChanged(QStandardItem* cell)
|
||||||
switch (cell->column()) {
|
switch (cell->column()) {
|
||||||
case 0: { // ÐÞ¸Äalias-name
|
case 0: { // ÐÞ¸Äalias-name
|
||||||
auto cell_name = cell->text();
|
auto cell_name = cell->text();
|
||||||
auto total_alias_set = _bind_base->delegateAlias();
|
auto total_alias_set = _bind_base->customDelegateAlias();
|
||||||
auto origin_key = total_alias_set.at(cell->row());
|
auto origin_key = total_alias_set.at(cell->row());
|
||||||
auto appoint_unit = _bind_base->operator[](origin_key);
|
auto appoint_unit = _bind_base->operator[](origin_key);
|
||||||
|
|
||||||
|
|
@ -169,14 +169,14 @@ void WrapConfigs::dataChanged(QStandardItem* cell)
|
||||||
appoint_unit->setAlias(cell_name);
|
appoint_unit->setAlias(cell_name);
|
||||||
}break;
|
}break;
|
||||||
case 1: { // ÐÞ¸Äalias»ù´¡ÀàÐÍ
|
case 1: { // ÐÞ¸Äalias»ù´¡ÀàÐÍ
|
||||||
auto total_alias_set = _bind_base->delegateAlias();
|
auto total_alias_set = _bind_base->customDelegateAlias();
|
||||||
auto origin_key = total_alias_set.at(cell->row());
|
auto origin_key = total_alias_set.at(cell->row());
|
||||||
|
|
||||||
auto new_type = cell->text();
|
auto new_type = cell->text();
|
||||||
auto new_ins = _bind_base->extractDelegateTypeMap()[new_type]->newDefault();
|
auto new_ins = _bind_base->extractImplTypeMap()[new_type]->newDefault();
|
||||||
auto new_delegate = std::dynamic_pointer_cast<ExtractDelegate>(new_ins);
|
auto new_delegate = std::dynamic_pointer_cast<ExtractDelegate>(new_ins);
|
||||||
new_delegate->setAlias(origin_key);
|
new_delegate->setAlias(origin_key);
|
||||||
_bind_base->replaceDelegate(origin_key, new_delegate);
|
_bind_base->replaceCustomDelegate(origin_key, new_delegate);
|
||||||
}break;
|
}break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -197,7 +197,7 @@ QWidget* RuleSelectDelegate::createEditor(QWidget* parent, const QStyleOptionVie
|
||||||
|
|
||||||
void RuleSelectDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
void RuleSelectDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
auto rule_names = this->_kernel->extractDelegateTypeMap().keys();
|
auto rule_names = this->_kernel->extractImplTypeMap().keys();
|
||||||
std::sort(rule_names.begin(), rule_names.end());
|
std::sort(rule_names.begin(), rule_names.end());
|
||||||
|
|
||||||
auto combo = dynamic_cast<QComboBox*>(editor);
|
auto combo = dynamic_cast<QComboBox*>(editor);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
/// 翻译规则编辑代理
|
/// 翻译规则编辑代理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class RuleSelectDelegate : public QStyledItemDelegate {
|
class RuleSelectDelegate : public QStyledItemDelegate {
|
||||||
Q_OBJECT
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<TranslateBasic> _kernel;
|
std::shared_ptr<TranslateBasic> _kernel;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -643,7 +643,7 @@ void ListBasedUnit::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonOb
|
||||||
OBJECT_PEAK(provider_obj, obj);
|
OBJECT_PEAK(provider_obj, obj);
|
||||||
OBJECT_PEAK(delegate_obj, obj);
|
OBJECT_PEAK(delegate_obj, obj);
|
||||||
|
|
||||||
auto ins_size = core->sizeProviderMap()[provider_name]->newDefault();
|
auto ins_size = core->sizeProviderTypeMap()[provider_name]->newDefault();
|
||||||
ins_size->loadFrom(core, provider_obj);
|
ins_size->loadFrom(core, provider_obj);
|
||||||
auto ins_delt = core->operator[](delegate_name)->newDefault();
|
auto ins_delt = core->operator[](delegate_name)->newDefault();
|
||||||
ins_delt->loadFrom(core, delegate_obj);
|
ins_delt->loadFrom(core, delegate_obj);
|
||||||
|
|
@ -771,7 +771,7 @@ void UnionBasedUnit::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonO
|
||||||
QString match_type;
|
QString match_type;
|
||||||
STRING_PEAK(match_type, rule_obj);
|
STRING_PEAK(match_type, rule_obj);
|
||||||
|
|
||||||
auto ninst = core->ruleMatchMap()[match_type]->newDefault();
|
auto ninst = core->ruleMatchTypeMap()[match_type]->newDefault();
|
||||||
QJsonObject content_obj;
|
QJsonObject content_obj;
|
||||||
OBJECT_PEAK(content_obj, rule_obj);
|
OBJECT_PEAK(content_obj, rule_obj);
|
||||||
ninst->loadFrom(core, content_obj);
|
ninst->loadFrom(core, content_obj);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue