96 lines
3.1 KiB
C++
96 lines
3.1 KiB
C++
#include "NuclideEditDialog.h"
|
|
|
|
NuclideEditDialog::NuclideEditDialog(bool isEdit, const QStringList& nuclideData, QWidget *parent)
|
|
: QDialog(parent), m_isEdit(isEdit)
|
|
{
|
|
// 编辑模式下提取ID和已有数据
|
|
if (isEdit && !nuclideData.isEmpty()) {
|
|
m_id = nuclideData[0]; // 第一个元素是ID
|
|
}
|
|
initUI();
|
|
|
|
// 编辑模式:填充已有数据(字段顺序不变,仅数据库字段名修改)
|
|
if (isEdit && nuclideData.size() >= 6) {
|
|
m_leName->setText(nuclideData[1]);
|
|
m_leHalfLife->setText(nuclideData[2]);
|
|
m_leHalfLifeUnc->setText(nuclideData[3]);
|
|
m_leParentNuclide->setText(nuclideData[4]);
|
|
m_leChildNuclide->setText(nuclideData[5]);
|
|
}
|
|
}
|
|
|
|
void NuclideEditDialog::initUI()
|
|
{
|
|
setWindowTitle(m_isEdit ? "编辑核素信息" : "添加核素信息");
|
|
setFixedSize(400, 220); // 稍微增加高度适配新校验提示
|
|
|
|
// 表单布局(控件名称不变,仅数据库映射修改)
|
|
QFormLayout *formLayout = new QFormLayout(this);
|
|
m_leName = new QLineEdit(this);
|
|
m_leHalfLife = new QLineEdit(this);
|
|
m_leHalfLifeUnc = new QLineEdit(this);
|
|
m_leParentNuclide = new QLineEdit(this);
|
|
m_leChildNuclide = new QLineEdit(this);
|
|
|
|
// 设置表单项(标签不变,用户界面无感知)
|
|
formLayout->addRow("核素名称", m_leName);
|
|
formLayout->addRow("半衰期", m_leHalfLife);
|
|
formLayout->addRow("半衰期不确定度", m_leHalfLifeUnc);
|
|
formLayout->addRow("母体核素名称", m_leParentNuclide);
|
|
formLayout->addRow("子体核素名称", m_leChildNuclide);
|
|
|
|
// 按钮盒
|
|
QDialogButtonBox *btnBox = new QDialogButtonBox(
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
|
|
Qt::Horizontal, this);
|
|
formLayout->addRow(btnBox);
|
|
|
|
// 信号连接
|
|
connect(btnBox, &QDialogButtonBox::accepted, this, [this]() {
|
|
if (validateInput()) {
|
|
accept();
|
|
}
|
|
});
|
|
connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
}
|
|
|
|
bool NuclideEditDialog::validateInput()
|
|
{
|
|
// 必填项校验
|
|
if (m_leName->text().trimmed().isEmpty()) {
|
|
QMessageBox::warning(this, "输入错误", "核素名称不能为空!");
|
|
return false;
|
|
}
|
|
if (m_leHalfLife->text().trimmed().isEmpty()) {
|
|
QMessageBox::warning(this, "输入错误", "半衰期不能为空!");
|
|
return false;
|
|
}
|
|
if (m_leHalfLifeUnc->text().trimmed().isEmpty()) {
|
|
QMessageBox::warning(this, "输入错误", "半衰期不确定度不能为空!");
|
|
return false;
|
|
}
|
|
|
|
bool ok;
|
|
m_leHalfLifeUnc->text().toDouble(&ok);
|
|
if (!ok) {
|
|
QMessageBox::warning(this, "输入错误", "半衰期不确定度必须为有效数字!");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
QStringList NuclideEditDialog::getNuclideData() const
|
|
{
|
|
QStringList data;
|
|
if (m_isEdit) {
|
|
data << m_id; // 编辑模式返回ID
|
|
}
|
|
data << m_leName->text().trimmed()
|
|
<< m_leHalfLife->text().trimmed()
|
|
<< m_leHalfLifeUnc->text().trimmed()
|
|
<< m_leParentNuclide->text().trimmed()
|
|
<< m_leChildNuclide->text().trimmed();
|
|
return data;
|
|
}
|