update
This commit is contained in:
parent
818ebc219d
commit
c51ead0f01
|
@ -36,7 +36,7 @@ void IntDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewIt
|
|||
|
||||
void RuleSetCustom::targetRuleRefresh(const QModelIndex& idx)
|
||||
{
|
||||
auto rule_insv = _view._ruleset->_bind[idx.row()];
|
||||
auto rule_insv = (*_view._ruleset)[idx.row()];
|
||||
|
||||
auto offset_index = idx.sibling(idx.row(), 1);
|
||||
auto offset_number = offset_index.data(Qt::DisplayRole).toInt();
|
||||
|
@ -65,7 +65,7 @@ void RuleSetCustom::peersRuleChanged(const QModelIndex& idx)
|
|||
|
||||
auto rule_nm = _view.base->extractUnitList()[rule_name];
|
||||
auto new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
|
||||
_view._ruleset->_bind.replace(idx.row(), std::make_pair(field_name, new_inst));
|
||||
_view._ruleset->replace(idx.row(), std::make_pair(field_name, new_inst));
|
||||
|
||||
// ¶ÔListUnitÖ´ÐÐÌØÊâ³õʼ»¯²½Öè
|
||||
if (typeid(*new_inst.get()) == typeid(BytesAsList)) {
|
||||
|
@ -117,7 +117,7 @@ RuleSetCustom::RuleSetCustom(std::shared_ptr<TranslateBasic> base,
|
|||
if (!curr.isValid())
|
||||
return;
|
||||
|
||||
emit this->currentRuleChanged(_view._ruleset->_bind[curr.row()].second, curr);
|
||||
emit this->currentRuleChanged(_view._ruleset->operator[](curr.row()).second, curr);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -133,8 +133,8 @@ void RuleSetCustom::customTranslateRuleEdit(const QPoint& pos)
|
|||
void RuleSetCustom::addTranslateUnit()
|
||||
{
|
||||
auto curr_rule = _view.base->defaultExtractUnit()->newDefault();
|
||||
this->_view._ruleset->_bind.append(
|
||||
QString(u8"rule_%1").arg(_view._ruleset->_bind.sub_units.size()),
|
||||
this->_view._ruleset->append(
|
||||
QString(u8"rule_%1").arg(_view._ruleset->memberCount()),
|
||||
std::static_pointer_cast<ExtractUnit>(curr_rule));
|
||||
|
||||
auto hex_rule = std::static_pointer_cast<BytesAsHex>(curr_rule);
|
||||
|
@ -149,7 +149,7 @@ void RuleSetCustom::removeTranslateUnit()
|
|||
if (!idx_curr.isValid())
|
||||
return;
|
||||
|
||||
_view._ruleset->_bind.removeAt(idx_curr.row());
|
||||
_view._ruleset->removeAt(idx_curr.row());
|
||||
_view._seqs_model->removeRow(idx_curr.row());
|
||||
}
|
||||
|
||||
|
@ -157,9 +157,8 @@ void RuleSetCustom::membersPresent(std::shared_ptr<extract::BytesAsRuleSet> rule
|
|||
{
|
||||
model->removeRows(0, model->rowCount());
|
||||
|
||||
auto units = ruleset->_bind.sub_units;
|
||||
for (auto uidx = 0; uidx < units.size(); ++uidx) {
|
||||
auto u_pair = units.at(uidx);
|
||||
for (auto uidx = 0; uidx < ruleset->memberCount(); ++uidx) {
|
||||
auto u_pair = ruleset->operator[](uidx);
|
||||
|
||||
QList<QStandardItem*> new_row;
|
||||
new_row << new QStandardItem(u_pair.first);
|
||||
|
|
|
@ -86,7 +86,7 @@ void StructuralRuleView::cacheRefresh(const QModelIndex& curr, ListUnitConfigura
|
|||
auto field_idx = curr.sibling(curr.row(), 0);
|
||||
this->_current_fields_cache->bindCurrent(field_idx.data(Qt::DisplayRole).toString());
|
||||
|
||||
auto ins = this->_rule_base->_bind[curr.row()];
|
||||
auto ins = this->_rule_base->operator[](curr.row());
|
||||
auto conv = std::dynamic_pointer_cast<extract::BytesAsList>(ins.second);
|
||||
if (conv) {
|
||||
t->currentRuleAccept(conv, curr, this->_current_fields_cache);
|
||||
|
|
|
@ -195,7 +195,7 @@ std::shared_ptr<Serializable> InterpretedNumberPrivider::newDefault() const
|
|||
return std::make_shared<InterpretedNumberPrivider>();
|
||||
}
|
||||
|
||||
void ValueAccess::init(const QString& field, std::shared_ptr<DataAccessContext> parent)
|
||||
void ValueAccessContext::init(const QString& field, std::shared_ptr<DataAccessContext> parent)
|
||||
{
|
||||
this->_cascade._current_field = field;
|
||||
|
||||
|
@ -203,17 +203,17 @@ void ValueAccess::init(const QString& field, std::shared_ptr<DataAccessContext>
|
|||
parent->setChild(field, this->shared_from_this());
|
||||
}
|
||||
|
||||
void ValueAccess::setChild(const QString& field, std::shared_ptr<DataAccessContext> inst)
|
||||
void ValueAccessContext::setChild(const QString& field, std::shared_ptr<DataAccessContext> inst)
|
||||
{
|
||||
this->_cascade._children_context[field] = inst;
|
||||
}
|
||||
|
||||
void ValueAccess::append(const QVariant& value)
|
||||
void ValueAccessContext::append(const QVariant& value)
|
||||
{
|
||||
this->_cascade._current_value = value;
|
||||
}
|
||||
|
||||
QVariant ValueAccess::get(const QString& unique_key) const
|
||||
QVariant ValueAccessContext::get(const QString& unique_key) const
|
||||
{
|
||||
if (_cascade._current_field == unique_key)
|
||||
return _cascade._current_value;
|
||||
|
|
|
@ -184,7 +184,8 @@ namespace size_provider {
|
|||
};
|
||||
}
|
||||
|
||||
class ValueAccess : public DataAccessContext, std::enable_shared_from_this<ValueAccess> {
|
||||
class ValueAccessContext : public DataAccessContext,
|
||||
public std::enable_shared_from_this<ValueAccessContext> {
|
||||
public:
|
||||
struct __Private {
|
||||
QString _current_field = "";
|
||||
|
|
|
@ -421,7 +421,7 @@ void BytesAsList::parse(const QByteArray& bytes, std::shared_ptr<DataAccessConte
|
|||
for (auto idx = 0; idx < size_value; ++idx) {
|
||||
auto secn = bytes.mid(unit_size * idx, unit_size);
|
||||
|
||||
auto slice_context = std::make_shared<ValueAccess>();
|
||||
auto slice_context = std::make_shared<ValueAccessContext>();
|
||||
slice_context->init(QString("ls<%1>").arg(idx), out);
|
||||
this->_list._bind_unit->parse(secn, slice_context);
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ void BytesAsUnion::parse(const QByteArray& bytes, std::shared_ptr<DataAccessCont
|
|||
{
|
||||
for (auto u : this->elementRules())
|
||||
if (u->checkpass(bytes)) {
|
||||
auto enum_context = std::make_shared<ValueAccess>();
|
||||
auto enum_context = std::make_shared<ValueAccessContext>();
|
||||
enum_context->init(u->name(), out);
|
||||
u->bindRule()->parse(bytes, enum_context);
|
||||
}
|
||||
|
@ -559,8 +559,8 @@ void BytesAsUnion::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
|
|||
|
||||
void BytesAsRuleSet::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
|
||||
{
|
||||
for (auto rl_key : this->_bind.fieldNames()){
|
||||
auto rlinst = this->_bind[rl_key];
|
||||
for (auto rl_key : this->fieldNames()){
|
||||
auto rlinst = (*this)[rl_key];
|
||||
inst->setField(rl_key, rlinst->outType());
|
||||
auto layer = std::make_shared<FieldManagerLayer>(rl_key, inst);
|
||||
rlinst->registSubField(layer);
|
||||
|
@ -570,11 +570,11 @@ void BytesAsRuleSet::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
|
|||
void BytesAsRuleSet::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
|
||||
{
|
||||
auto bufx = bytes;
|
||||
for (auto keym : this->_bind.fieldNames()) {
|
||||
auto rule_context = std::make_shared<ValueAccess>();
|
||||
for (auto keym : this->fieldNames()) {
|
||||
auto rule_context = std::make_shared<ValueAccessContext>();
|
||||
rule_context->init(keym, out);
|
||||
|
||||
auto rule = this->_bind[keym];
|
||||
auto rule = (*this)[keym];
|
||||
bufx = bufx.mid(rule->offsetSpan());
|
||||
auto count = rule->countWithin();
|
||||
auto secx = bufx.mid(0, count);
|
||||
|
@ -658,39 +658,39 @@ std::shared_ptr<Serializable> BytesAsRuleSet::newDefault() const
|
|||
return std::make_shared<BytesAsRuleSet>();
|
||||
}
|
||||
|
||||
std::pair<QString, std::shared_ptr<ExtractUnit>> BytesAsRuleSet::__Private::operator[](int index) const
|
||||
std::pair<QString, std::shared_ptr<ExtractUnit>> BytesAsRuleSet::operator[](int index) const
|
||||
{
|
||||
return this->sub_units[index];
|
||||
return this->_bind.sub_units[index];
|
||||
}
|
||||
|
||||
void BytesAsRuleSet::__Private::replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst)
|
||||
void BytesAsRuleSet::replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst)
|
||||
{
|
||||
this->sub_units.replace(index, inst);
|
||||
this->_bind.sub_units.replace(index, inst);
|
||||
}
|
||||
|
||||
extract::BytesAsRuleSet::__Private& BytesAsRuleSet::__Private::append(const QString& nm, std::shared_ptr<ExtractUnit> u)
|
||||
extract::BytesAsRuleSet& BytesAsRuleSet::append(const QString& nm, std::shared_ptr<ExtractUnit> u)
|
||||
{
|
||||
this->sub_units.append(std::make_pair(nm, u));
|
||||
this->_bind.sub_units.append(std::make_pair(nm, u));
|
||||
return *this;
|
||||
}
|
||||
|
||||
void BytesAsRuleSet::__Private::removeAt(int index)
|
||||
void BytesAsRuleSet::removeAt(int index)
|
||||
{
|
||||
this->sub_units.removeAt(index);
|
||||
this->_bind.sub_units.removeAt(index);
|
||||
}
|
||||
|
||||
QList<QString> BytesAsRuleSet::__Private::fieldNames() const
|
||||
QList<QString> BytesAsRuleSet::fieldNames() const
|
||||
{
|
||||
QList<QString> fields_store;
|
||||
for (auto fpair : this->sub_units) {
|
||||
for (auto fpair : this->_bind.sub_units) {
|
||||
fields_store << fpair.first;
|
||||
}
|
||||
return fields_store;;
|
||||
}
|
||||
|
||||
std::shared_ptr<ExtractUnit> BytesAsRuleSet::__Private::operator[](const QString& field) const
|
||||
std::shared_ptr<ExtractUnit> BytesAsRuleSet::operator[](const QString& field) const
|
||||
{
|
||||
for (auto pair : this->sub_units) {
|
||||
for (auto pair : this->_bind.sub_units) {
|
||||
if(pair.first == field)
|
||||
return pair.second;
|
||||
}
|
||||
|
@ -707,3 +707,8 @@ QString BytesAsRuleSet::customName() const
|
|||
{
|
||||
return _bind._name_store;
|
||||
}
|
||||
|
||||
int BytesAsRuleSet::memberCount() const
|
||||
{
|
||||
return _bind.sub_units.size();
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace extract {
|
|||
virtual bool setCountWithin(int bytes);
|
||||
|
||||
// ExtractUnit ===========================
|
||||
QString name() const override;
|
||||
QString name() const override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) override;
|
||||
virtual DataType outType() const;
|
||||
/// <summary>
|
||||
|
@ -252,25 +252,27 @@ namespace extract {
|
|||
|
||||
|
||||
class BytesAsRuleSet : public ExtractUnit {
|
||||
public:
|
||||
private:
|
||||
struct __Private {
|
||||
int _byte_offset = 0, _byte_count = 1;
|
||||
QString _name_store;
|
||||
QList<std::pair<QString, std::shared_ptr<ExtractUnit>>> sub_units;
|
||||
|
||||
QList<QString> fieldNames() const;
|
||||
std::shared_ptr<ExtractUnit> operator[](const QString &field) const;
|
||||
|
||||
|
||||
std::pair<QString, std::shared_ptr<ExtractUnit>> operator[](int index) const;
|
||||
void replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst);
|
||||
void removeAt(int index);
|
||||
__Private& append(const QString& nm, std::shared_ptr<ExtractUnit> u);
|
||||
}_bind;
|
||||
|
||||
public:
|
||||
void setCustomName(const QString& name);
|
||||
QString customName() const;
|
||||
|
||||
QList<QString> fieldNames() const;
|
||||
std::shared_ptr<ExtractUnit> operator[](const QString& field) const;
|
||||
|
||||
int memberCount() const;
|
||||
std::pair<QString, std::shared_ptr<ExtractUnit>> operator[](int index) const;
|
||||
void replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst);
|
||||
void removeAt(int index);
|
||||
BytesAsRuleSet& append(const QString& nm, std::shared_ptr<ExtractUnit> u);
|
||||
|
||||
public:
|
||||
QString name() const override;
|
||||
void registSubField(std::shared_ptr<ScopeFieldsSetter> inst) override;
|
||||
|
|
Loading…
Reference in New Issue