2026-05-09 16:50:34 +08:00
|
|
|
|
#include "NuclideRayListDialog.h"
|
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
|
RayButtonDelegate::RayButtonDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
|
|
|
|
|
|
|
|
|
|
|
void RayButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index.column() == 8) { // 第8列是操作列
|
|
|
|
|
|
// 绘制编辑按钮
|
|
|
|
|
|
QStyleOptionButton editBtn;
|
|
|
|
|
|
editBtn.rect = QRect(option.rect.x(), option.rect.y() + 2, 60, option.rect.height() - 4);
|
2026-05-12 19:18:41 +08:00
|
|
|
|
editBtn.text = QStringLiteral(u"编辑");
|
2026-05-09 16:50:34 +08:00
|
|
|
|
editBtn.state = QStyle::State_Enabled;
|
|
|
|
|
|
if (option.state & QStyle::State_MouseOver)
|
|
|
|
|
|
editBtn.state |= QStyle::State_MouseOver;
|
|
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton, &editBtn, painter);
|
|
|
|
|
|
|
|
|
|
|
|
// 绘制删除按钮
|
|
|
|
|
|
QStyleOptionButton delBtn;
|
|
|
|
|
|
delBtn.rect = QRect(option.rect.x() + 70, option.rect.y() + 2, 60, option.rect.height() - 4);
|
2026-05-12 19:18:41 +08:00
|
|
|
|
delBtn.text = QStringLiteral(u"删除");
|
2026-05-09 16:50:34 +08:00
|
|
|
|
delBtn.state = QStyle::State_Enabled;
|
|
|
|
|
|
if (option.state & QStyle::State_MouseOver)
|
|
|
|
|
|
delBtn.state |= QStyle::State_MouseOver;
|
|
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton, &delBtn, painter);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RayButtonDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (index.column() == 8 && event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
|
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
|
|
|
|
|
|
QRect editRect = QRect(option.rect.x(), option.rect.y() + 2, 60, option.rect.height() - 4);
|
|
|
|
|
|
QRect delRect = QRect(option.rect.x() + 70, option.rect.y() + 2, 60, option.rect.height() - 4);
|
|
|
|
|
|
|
|
|
|
|
|
if (editRect.contains(mouseEvent->pos())) {
|
|
|
|
|
|
emit editButtonClicked(index);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else if (delRect.contains(mouseEvent->pos())) {
|
|
|
|
|
|
emit deleteButtonClicked(index);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NuclideRayListDialog::NuclideRayListDialog(const QString& nuclideId, const QString& nuclideName, QWidget *parent)
|
|
|
|
|
|
: QDialog(parent), m_nuclideId(nuclideId), m_nuclideName(nuclideName)
|
|
|
|
|
|
{
|
|
|
|
|
|
initUI();
|
|
|
|
|
|
loadRayData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NuclideRayListDialog::initUI()
|
|
|
|
|
|
{
|
2026-05-12 19:18:41 +08:00
|
|
|
|
setWindowTitle(QStringLiteral(u"%1 - 射线信息管理").arg(m_nuclideName));
|
|
|
|
|
|
setFixedSize(1100, 500);
|
2026-05-09 16:50:34 +08:00
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
|
|
|
|
// 添加按钮
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QPushButton *btnAdd = new QPushButton(QStringLiteral(u"添加射线"), this);
|
2026-05-09 16:50:34 +08:00
|
|
|
|
connect(btnAdd, &QPushButton::clicked, this, &NuclideRayListDialog::onAddRayClicked);
|
|
|
|
|
|
mainLayout->addWidget(btnAdd, 0, Qt::AlignRight);
|
|
|
|
|
|
|
|
|
|
|
|
// 射线列表
|
|
|
|
|
|
m_model = new QStandardItemModel(0, 9, this);
|
|
|
|
|
|
m_model->setHorizontalHeaderLabels({
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QStringLiteral(u"ID"), QStringLiteral(u"射线类型"), QStringLiteral(u"能量(MeV)"), QStringLiteral(u"能量不确定度"), QStringLiteral(u"分支比"),
|
|
|
|
|
|
QStringLiteral(u"分支比不确定度"), QStringLiteral(u"主射线"), QStringLiteral(u"加和峰"), QStringLiteral(u"操作")
|
2026-05-09 16:50:34 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
QTableView *tableView = new QTableView(this);
|
|
|
|
|
|
tableView->setModel(m_model);
|
2026-05-12 19:18:41 +08:00
|
|
|
|
tableView->verticalHeader()->setVisible(false);
|
|
|
|
|
|
tableView->setColumnWidth(0, 80); // ID
|
2026-05-09 16:50:34 +08:00
|
|
|
|
tableView->setColumnWidth(1, 80); // 射线类型
|
|
|
|
|
|
tableView->setColumnWidth(2, 120); // 能量
|
|
|
|
|
|
tableView->setColumnWidth(3, 120); // 能量不确定度
|
|
|
|
|
|
tableView->setColumnWidth(4, 100); // 分支比
|
|
|
|
|
|
tableView->setColumnWidth(5, 120); // 分支比不确定度
|
|
|
|
|
|
tableView->setColumnWidth(6, 80); // 主射线
|
|
|
|
|
|
tableView->setColumnWidth(7, 100); // 加和峰
|
|
|
|
|
|
tableView->setColumnWidth(8, 150); // 操作列
|
|
|
|
|
|
|
|
|
|
|
|
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
|
tableView->setAlternatingRowColors(true);
|
|
|
|
|
|
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
tableView->setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置委托
|
|
|
|
|
|
m_delegate = new RayButtonDelegate(this);
|
|
|
|
|
|
tableView->setItemDelegateForColumn(8, m_delegate);
|
|
|
|
|
|
connect(m_delegate, &RayButtonDelegate::editButtonClicked, this, &NuclideRayListDialog::onEditRayClicked);
|
|
|
|
|
|
connect(m_delegate, &RayButtonDelegate::deleteButtonClicked, this, &NuclideRayListDialog::onDeleteRayClicked);
|
|
|
|
|
|
|
|
|
|
|
|
mainLayout->addWidget(tableView);
|
|
|
|
|
|
|
|
|
|
|
|
// 关闭按钮
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QPushButton *btnClose = new QPushButton(QStringLiteral(u"关闭"), this);
|
2026-05-09 16:50:34 +08:00
|
|
|
|
connect(btnClose, &QPushButton::clicked, this, &QDialog::accept);
|
|
|
|
|
|
mainLayout->addWidget(btnClose, 0, Qt::AlignRight);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NuclideRayListDialog::loadRayData()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 查询当前核素的所有射线信息
|
|
|
|
|
|
QString sql = "SELECT ID, RAY_TYPE, RAY_MEV, RAY_MEV_UNCERTAINTY, RAY_BRANCH_RATIO, "
|
|
|
|
|
|
"RAY_BRANCH_RATIO_UNCERTAINTY, MAIN_RAY_IDENT, JIAHE_PEAK "
|
|
|
|
|
|
"FROM nuclideRayInfo WHERE NUCLIDE_ID = ?;";
|
|
|
|
|
|
auto rows = SqliteManager::instance().selectRows(sql, {m_nuclideId});
|
|
|
|
|
|
|
|
|
|
|
|
m_listRay.clear();
|
|
|
|
|
|
m_model->setRowCount(0);
|
|
|
|
|
|
int row = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& rec : rows) {
|
|
|
|
|
|
QStringList item;
|
|
|
|
|
|
item << rec["ID"].toString()
|
|
|
|
|
|
<< rec["RAY_TYPE"].toString()
|
|
|
|
|
|
<< rec["RAY_MEV"].toString()
|
|
|
|
|
|
<< rec["RAY_MEV_UNCERTAINTY"].toString()
|
|
|
|
|
|
<< rec["RAY_BRANCH_RATIO"].toString()
|
|
|
|
|
|
<< rec["RAY_BRANCH_RATIO_UNCERTAINTY"].toString()
|
|
|
|
|
|
<< rec["MAIN_RAY_IDENT"].toString()
|
|
|
|
|
|
<< rec["JIAHE_PEAK"].toString();
|
|
|
|
|
|
m_listRay.append(item);
|
|
|
|
|
|
|
|
|
|
|
|
// 插入模型行
|
|
|
|
|
|
QList<QStandardItem*> rowItems;
|
|
|
|
|
|
// 第0列:ID(隐藏)
|
|
|
|
|
|
QStandardItem *idItem = new QStandardItem(item[0]);
|
|
|
|
|
|
idItem->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
|
idItem->setFlags(idItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
|
rowItems << idItem;
|
|
|
|
|
|
|
|
|
|
|
|
// 第1~7列:射线数据
|
|
|
|
|
|
for (int col = 1; col <= 7; ++col) {
|
|
|
|
|
|
QStandardItem *dataItem = new QStandardItem(item[col]);
|
|
|
|
|
|
dataItem->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
|
dataItem->setFlags(dataItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
|
rowItems << dataItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 第8列:操作列
|
|
|
|
|
|
QStandardItem *opItem = new QStandardItem("");
|
|
|
|
|
|
opItem->setFlags(opItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
|
rowItems << opItem;
|
|
|
|
|
|
|
|
|
|
|
|
m_model->appendRow(rowItems);
|
|
|
|
|
|
++row;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList NuclideRayListDialog::getRayData(const QString &id)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& item : m_listRay) {
|
|
|
|
|
|
if (item.at(0) == id)
|
|
|
|
|
|
return item;
|
|
|
|
|
|
}
|
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NuclideRayListDialog::onAddRayClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
NuclideRayDialog dlg(false, {}, this);
|
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted) {
|
|
|
|
|
|
QStringList data = dlg.getRayData();
|
|
|
|
|
|
if (data.size() < 7) return;
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString, QVariant> fieldValues;
|
|
|
|
|
|
fieldValues["NUCLIDE_ID"] = m_nuclideId.toInt();
|
|
|
|
|
|
fieldValues["RAY_TYPE"] = data[0];
|
|
|
|
|
|
fieldValues["RAY_MEV"] = data[1];
|
|
|
|
|
|
fieldValues["RAY_MEV_UNCERTAINTY"] = data[2];
|
|
|
|
|
|
fieldValues["RAY_BRANCH_RATIO"] = data[3];
|
|
|
|
|
|
fieldValues["RAY_BRANCH_RATIO_UNCERTAINTY"] = data[4];
|
|
|
|
|
|
fieldValues["MAIN_RAY_IDENT"] = data[5];
|
|
|
|
|
|
fieldValues["JIAHE_PEAK"] = data[6];
|
|
|
|
|
|
fieldValues["CREATE_TIME"] = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
|
qint64 newId = SqliteManager::instance().insertRow("nuclideRayInfo", fieldValues);
|
|
|
|
|
|
if (newId > 0) {
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QMessageBox::information(this, QStringLiteral(u"成功"), QStringLiteral(u"射线信息添加成功!"));
|
2026-05-09 16:50:34 +08:00
|
|
|
|
loadRayData(); // 刷新列表
|
|
|
|
|
|
} else {
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QMessageBox::warning(this, QStringLiteral(u"失败"), QStringLiteral(u"添加失败:") + SqliteManager::instance().lastError());
|
2026-05-09 16:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NuclideRayListDialog::onEditRayClicked(const QModelIndex &index)
|
|
|
|
|
|
{
|
|
|
|
|
|
int row = index.row();
|
|
|
|
|
|
QString id = m_model->index(row, 0).data().toString();
|
|
|
|
|
|
QStringList data = getRayData(id);
|
|
|
|
|
|
if (data.isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
|
|
NuclideRayDialog dlg(true, data, this);
|
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted) {
|
|
|
|
|
|
QStringList newData = dlg.getRayData();
|
|
|
|
|
|
if (newData.size() < 8) return;
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString, QVariant> fieldValues;
|
|
|
|
|
|
fieldValues["RAY_TYPE"] = newData[1];
|
|
|
|
|
|
fieldValues["RAY_MEV"] = newData[2];
|
|
|
|
|
|
fieldValues["RAY_MEV_UNCERTAINTY"] = newData[3];
|
|
|
|
|
|
fieldValues["RAY_BRANCH_RATIO"] = newData[4];
|
|
|
|
|
|
fieldValues["RAY_BRANCH_RATIO_UNCERTAINTY"] = newData[5];
|
|
|
|
|
|
fieldValues["MAIN_RAY_IDENT"] = newData[6];
|
|
|
|
|
|
fieldValues["JIAHE_PEAK"] = newData[7];
|
|
|
|
|
|
|
|
|
|
|
|
int affectedRows = SqliteManager::instance().updateRow(
|
|
|
|
|
|
"nuclideRayInfo",
|
|
|
|
|
|
fieldValues,
|
|
|
|
|
|
"ID = ?",
|
|
|
|
|
|
{newData[0]}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (affectedRows > 0) {
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QMessageBox::information(this, QStringLiteral(u"成功"), QStringLiteral(u"射线信息修改成功!"));
|
2026-05-09 16:50:34 +08:00
|
|
|
|
loadRayData();
|
|
|
|
|
|
} else if (affectedRows == 0) {
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QMessageBox::information(this, QStringLiteral(u"提示"), QStringLiteral(u"未修改任何数据!"));
|
2026-05-09 16:50:34 +08:00
|
|
|
|
} else {
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QMessageBox::warning(this, QStringLiteral(u"失败"), QStringLiteral(u"修改失败:") + SqliteManager::instance().lastError());
|
2026-05-09 16:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NuclideRayListDialog::onDeleteRayClicked(const QModelIndex &index)
|
|
|
|
|
|
{
|
|
|
|
|
|
int row = index.row();
|
|
|
|
|
|
QString id = m_model->index(row, 0).data().toString();
|
|
|
|
|
|
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QMessageBox box(QMessageBox::Question, QStringLiteral(u"提示"), QStringLiteral(u"确定删除该射线信息吗?"),
|
2026-05-09 16:50:34 +08:00
|
|
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
2026-05-12 19:18:41 +08:00
|
|
|
|
box.button(QMessageBox::Yes)->setText(QStringLiteral(u"确认"));
|
|
|
|
|
|
box.button(QMessageBox::No)->setText(QStringLiteral(u"取消"));
|
2026-05-09 16:50:34 +08:00
|
|
|
|
if (box.exec() != QMessageBox::Yes) return;
|
|
|
|
|
|
|
|
|
|
|
|
bool ok = SqliteManager::instance().deleteRow("nuclideRayInfo", "ID = ?", {id});
|
|
|
|
|
|
if (ok) {
|
|
|
|
|
|
loadRayData();
|
|
|
|
|
|
} else {
|
2026-05-12 19:18:41 +08:00
|
|
|
|
QMessageBox::warning(this, QStringLiteral(u"错误"), QStringLiteral(u"删除失败:") + SqliteManager::instance().lastError());
|
2026-05-09 16:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|