feat(nmNum): 完善储层参数输入校验提示

- 使用参数中文别名和参数 ID 生成输入框悬浮提示
- 在悬浮提示中显示当前单位对应的有效范围
- 参数校验失败时将输入文字和提示文字标红
- 校验恢复正常后还原输入框原始文字颜色
- 使用调色板更新文字颜色,保留 Qt 原生输入框边框和右键菜单
feature/ReservoirPropertiesDlg-Refactoring-20260813
lh 3 days ago
parent 9d742b18e6
commit dffbe9da7a

@ -3,6 +3,7 @@
#include "nmSubWxs_global.h"
#include "nmReservoirParameterCatalog.h"
#include <QColor>
#include <QObject>
#include <QVariant>
@ -157,6 +158,7 @@ private:
QComboBox* m_pValueComboBox; ///< 枚举值下拉框。
QComboBox* m_pUnitComboBox; ///< 可换算单位下拉框。
QLabel* m_pUnitLabel; ///< 无单位字段的空白对齐占位。
QColor m_clrNormalText; ///< 输入框默认文字颜色。
bool m_bVisible; ///< 参数行是否参与编辑。
bool m_bUpdating; ///< 程序写值时阻止业务信号。
};

@ -10,6 +10,7 @@
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPalette>
#include <QSizePolicy>
namespace
@ -31,6 +32,24 @@ QString fieldText(const char* pText)
"nmReservoirParameterField", pText);
}
/** @brief 根据有效状态生成悬浮提示文字。 */
QString validationToolTip(const QString& sText, bool bValid)
{
if (bValid)
{
return sText;
}
QString sEscaped = sText;
sEscaped.replace("&", "&amp;");
sEscaped.replace("<", "&lt;");
sEscaped.replace(">", "&gt;");
sEscaped.replace("\"", "&quot;");
sEscaped.replace("\n", "<br/>");
return "<span style=\"color:red;\">" +
sEscaped + "</span>";
}
}
nmReservoirParameterField::nmReservoirParameterField(
@ -46,6 +65,7 @@ nmReservoirParameterField::nmReservoirParameterField(
m_pValueComboBox(nullptr),
m_pUnitComboBox(nullptr),
m_pUnitLabel(nullptr),
m_clrNormalText(),
m_bVisible(true),
m_bUpdating(false)
{
@ -149,6 +169,7 @@ bool nmReservoirParameterField::createNumericEditor(
QSizePolicy::Fixed);
m_pLineEdit = new QLineEdit(pParentWidget);
m_clrNormalText = m_pLineEdit->palette().color(QPalette::Text);
m_pLineEdit->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_pLineEdit->setFixedHeight(editorHeight());
m_pLineEdit->setMinimumWidth(editorMinimumWidth());
@ -399,12 +420,17 @@ QString nmReservoirParameterField::formatBaseValue(double dValue) const
void nmReservoirParameterField::updateValidationAppearance(bool bValid)
{
Q_UNUSED(bValid);
if (m_pLineEdit == nullptr || m_pParameter == nullptr)
{
return;
}
// 只修改文字色避免Qt 4.8样式表绘制覆盖原生输入框边框。
QPalette oPalette = m_pLineEdit->palette();
oPalette.setColor(QPalette::Text,
bValid ? m_clrNormalText : QColor(Qt::red));
m_pLineEdit->setPalette(oPalette);
QString sCurrentUnit;
iUnitGroup* pUnitGroup = nullptr;
if (m_pUnitComboBox != nullptr && m_pUnitService != nullptr)
@ -414,7 +440,19 @@ void nmReservoirParameterField::updateValidationAppearance(bool bValid)
}
QString sRange = iParaItemCtrl::getScaleStrOf(
m_pParameter, sCurrentUnit, pUnitGroup);
QString sHelp = m_pParameter->m_sDesc;
// 参数别名来自当前语言XML稳定ID便于定位参数定义。
QString sHelp = m_pParameter->m_sAlias;
if (!m_pParameter->m_sName.isEmpty())
{
if (!sHelp.isEmpty())
{
sHelp += "[" + m_pParameter->m_sName + "]";
}
else
{
sHelp = m_pParameter->m_sName;
}
}
if (!sRange.isEmpty())
{
if (!sHelp.isEmpty())
@ -423,7 +461,7 @@ void nmReservoirParameterField::updateValidationAppearance(bool bValid)
}
sHelp += sRange;
}
m_pLineEdit->setToolTip(sHelp);
m_pLineEdit->setToolTip(validationToolTip(sHelp, bValid));
m_pLineEdit->setWhatsThis(sHelp);
if (m_pLabel != nullptr)
{

Loading…
Cancel
Save