From cf9af911b8a98ff1fbfb26971355b9c0f3edf01f Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Fri, 18 Jul 2025 23:33:21 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E9=87=8D=E6=9E=84=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TranslateUI/SequenceView.cpp | 30 ++++++++++++++++++------------ TranslateUI/SequenceView.h | 4 ++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/TranslateUI/SequenceView.cpp b/TranslateUI/SequenceView.cpp index f6f01ee..14ea7e7 100644 --- a/TranslateUI/SequenceView.cpp +++ b/TranslateUI/SequenceView.cpp @@ -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(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(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(rule_nm->newDefault()); + _rule_sequence.replace(idx.row(), new_inst); + + currentRuleRefresh(idx); +} + #include 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) { diff --git a/TranslateUI/SequenceView.h b/TranslateUI/SequenceView.h index 3a6776a..4a2fada 100644 --- a/TranslateUI/SequenceView.h +++ b/TranslateUI/SequenceView.h @@ -21,7 +21,6 @@ public: std::shared_ptr defaultRule() const; QHash> extactors() const; - }; @@ -81,7 +80,8 @@ signals: void currentRuleChanged(std::shared_ptr 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);