From 61bab7393835af002d427fcc2e985dfcf24a0258 Mon Sep 17 00:00:00 2001 From: lh <2334563547@qq.com> Date: Wed, 17 Jun 2026 14:24:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20nmGridRowUtils=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=80=BC=E5=8F=98=E5=8D=B3=E5=90=8C=E6=AD=A5=EF=BC=8C=E7=A7=BB?= =?UTF-8?q?=E9=99=A4onActiveItemChanged=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除onActiveItemChanged override(切换项触发不可靠) - 新增slotItemValueChanged直接emit sigParaChanged - connectSignalsOf连接sigValueChanged实现实时同步 --- Include/nmNum/nmGUI/nmGridRowUtils.h | 8 +++++--- Src/nmNum/nmGUI/nmGridRowUtils.cpp | 14 ++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Include/nmNum/nmGUI/nmGridRowUtils.h b/Include/nmNum/nmGUI/nmGridRowUtils.h index 96e32e7..e516a7d 100644 --- a/Include/nmNum/nmGUI/nmGridRowUtils.h +++ b/Include/nmNum/nmGUI/nmGridRowUtils.h @@ -147,9 +147,11 @@ public slots: /// @param bOk 是否成功获取 virtual void slotGetValueOf(QString sPara, QVariant& o, bool& bOk) override; - /// @brief 激活项切换回调(用户离开当前编辑项时触发) - /// @note 在此时同步上一个编辑项的最终值,避免中间态非法值污染数据层 - virtual void onActiveItemChanged(iGridRowItem* p) override; +private slots: + + /// @brief 参数值改变后的回调(iGridRowItem::sigValueChanged 触发) + /// @note 立即 emit sigParaChanged,确保数据层与 UI 始终同步 + void slotItemValueChanged(QString sPara, QVariant o); signals: diff --git a/Src/nmNum/nmGUI/nmGridRowUtils.cpp b/Src/nmNum/nmGUI/nmGridRowUtils.cpp index c4a6da7..deb34e8 100644 --- a/Src/nmNum/nmGUI/nmGridRowUtils.cpp +++ b/Src/nmNum/nmGUI/nmGridRowUtils.cpp @@ -130,6 +130,10 @@ bool nmGridRowUtils::createAndAddItem(iGridRowItem* pParent, void nmGridRowUtils::connectSignalsOf(iGridRowItem* p) { iGridRowUtils::connectSignalsOf(p); + + // 连接 sigValueChanged,值改变立即同步到数据层 + connect(p, SIGNAL(sigValueChanged(QString, QVariant)), + this, SLOT(slotItemValueChanged(QString, QVariant))); } void nmGridRowUtils::bindItems() @@ -141,15 +145,9 @@ void nmGridRowUtils::bindItems() // 槽函数 // ================================================================ -void nmGridRowUtils::onActiveItemChanged(iGridRowItem* p) +void nmGridRowUtils::slotItemValueChanged(QString sPara, QVariant o) { - // 基类调用前,m_pItemSel 仍是上一个编辑项 - // 在此时同步其最终值,避免中间态非法值污染数据层 - if (m_pItemSel && m_pItemSel != p) { - emit sigParaChanged(m_pItemSel->getName(), m_pItemSel->getCurValue()); - } - - iGridRowUtils::onActiveItemChanged(p); + emit sigParaChanged(sPara, o); } void nmGridRowUtils::slotGetValueOf(QString sPara, QVariant& o, bool& bOk)