update 重构更新逻辑

This commit is contained in:
codeboss 2025-07-18 23:33:21 +08:00
parent fbf498de9d
commit cf9af911b8
2 changed files with 20 additions and 14 deletions

View File

@ -33,20 +33,16 @@ void IntDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewIt
}
#include "TranslateBasic.h"
void SequenceView::tidyRuleAt(const QModelIndex& idx)
void SequenceView::currentRuleRefresh(const QModelIndex& idx)
{
auto rule_idx = idx.sibling(idx.row(), 3);
auto rule_nm = base->extactors()[rule_idx.data(Qt::DisplayRole).toString()];
auto new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
_rule_sequence.replace(idx.row(), new_inst);
auto offset_index = idx.sibling(idx.row(), 1);
auto offset_number = offset_index.data(Qt::DisplayRole).toInt();
auto count_index = idx.sibling(idx.row(), 2);
auto count_number = count_index.data(Qt::DisplayRole).toInt();
auto new_inst = _rule_sequence.at(idx.row());
auto rule_insv = std::dynamic_pointer_cast<AbstractExtractor>(new_inst);
auto offset_index = idx.sibling(idx.row(), 1);
auto count_index = idx.sibling(idx.row(), 2);
if (rule_insv) {
auto offset_number = offset_index.data(Qt::DisplayRole).toInt();
auto count_number = count_index.data(Qt::DisplayRole).toInt();
rule_insv->setOffsetFromPrevious(offset_number);
rule_insv->setCountWithinParse(count_number);
}
@ -63,6 +59,16 @@ void SequenceView::tidyRuleAt(const QModelIndex& idx)
this->resizeColumnsToContents();
}
void SequenceView::peersRuleChanged(const QModelIndex& idx)
{
auto rule_idx = idx.sibling(idx.row(), 3);
auto rule_nm = base->extactors()[rule_idx.data(Qt::DisplayRole).toString()];
auto new_inst = std::dynamic_pointer_cast<ExtractUnit>(rule_nm->newDefault());
_rule_sequence.replace(idx.row(), new_inst);
currentRuleRefresh(idx);
}
#include <QItemSelectionModel>
SequenceView::SequenceView(QWidget* p /*= nullptr*/)
:QTableView(p),
@ -82,8 +88,8 @@ SequenceView::SequenceView(QWidget* p /*= nullptr*/)
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QTableView::customContextMenuRequested, this, &SequenceView::customTranslateRuleEdit);
connect(rule_delegate, &RuleSelectDelegate::dataChanged, this, &SequenceView::tidyRuleAt);
connect(int_delegate, &IntDelegate::valueChanged, this, &SequenceView::tidyRuleAt);
connect(rule_delegate, &RuleSelectDelegate::dataChanged, this, &SequenceView::peersRuleChanged);
connect(int_delegate, &IntDelegate::valueChanged, this, &SequenceView::currentRuleRefresh);
auto select_model = this->selectionModel();
connect(select_model, &QItemSelectionModel::currentRowChanged, [=](const QModelIndex& curr) {

View File

@ -21,7 +21,6 @@ public:
std::shared_ptr<ExtractUnit> defaultRule() const;
QHash<QString, std::shared_ptr<ExtractUnit>> extactors() const;
};
@ -81,7 +80,8 @@ signals:
void currentRuleChanged(std::shared_ptr<ExtractUnit> u) const;
public:
void tidyRuleAt(const QModelIndex& idx_rule);
void currentRuleRefresh(const QModelIndex &idx);
void peersRuleChanged(const QModelIndex &idx_rule);
public:
SequenceView(QWidget* p = nullptr);