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)