修改测量分析树控件点击进入能量刻度,能量刻度名称默认填写“[测量分析名称]能量刻度,测量分析树控件点击进入能量刻度,按钮“另存为”改为“保存到系统”,点击后弹出“能量刻度名称”和“备注”编辑的对话框,编辑保存到“bin/configure”目录,所有的能量刻度编辑界面中,能量刻度拟合数据表编辑修改数据后,要求重新拟合,三维符合能谱的界面中三维图表添加图表各轴的名称label

This commit is contained in:
anxinglong 2026-05-28 15:48:24 +08:00
parent 6e2837c0e9
commit a72dbeebbe
4 changed files with 155 additions and 35 deletions

View File

@ -61,11 +61,15 @@ void EnergyScaleForm::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data
if (!data_files_set.isEmpty()) {
const QString& data_name = data_files_set.firstKey();
const QString& data_filename = data_files_set.first().toString();
QFileInfo info(data_filename);
QDir dir = info.dir();
if (QFileInfo(data_filename).exists()) {
ui->groupBox_3->hide();
QFileInfo fileInfo(data_filename);
QString baseName = fileInfo.baseName();
QString baseName =QString("[%1]%2").arg(dir.dirName()).arg(fileInfo.baseName());
ui->lineEdit_name->setText(baseName);
ui->lineEdit_name->setReadOnly(true);
ui->pBtn_SaveAs->setText(QStringLiteral(u"保存到系统"));
m_currentFilePath = data_filename;
QString errorMsg;
m_channelList = parseJsonToChannels(data_filename, errorMsg);
@ -461,6 +465,7 @@ bool EnergyScaleForm::fitFwhmModel(ChannelData &chData)
}
arma::vec E(E_list.data(), E_list.size());
arma::vec FWHM(fwhm_list.data(), fwhm_list.size());
arma::vec params = NolinearLeastSquaresCurveFit::Lsqcurvefit(FwhmModel,E,FWHM, { 1.0, 1.0 });
chData.fwhmFitResultCoeffs.clear();
chData.fwhmFitResultCoeffs.append(params(0)); // k
@ -474,8 +479,11 @@ bool EnergyScaleForm::saveChannelDataToJson(const QString &filePath)
if (filePath.isEmpty()) return false;
QJsonObject rootObj;
QString remark = ui->plainTextEdit_description->toPlainText().trimmed();
QString remark;
if(systemEnble)
remark = ui->plainTextEdit_description->property("systemData").toString();
else
remark = ui->plainTextEdit_description->toPlainText().trimmed();
rootObj["Remark"] = remark;
for (auto it = m_channelList.begin(); it != m_channelList.end(); ++it) {
@ -838,7 +846,6 @@ void EnergyScaleForm::on_tablew_scale_data_cellChanged(int row, int column)
return;
}
// 只同步道址和能量列的修改
bool needRecalc = false;
if (column == 0) {
// 检查道址重复
@ -860,45 +867,134 @@ void EnergyScaleForm::on_tablew_scale_data_cellChanged(int row, int column)
}
if (needRecalc) {
calculateFitValues(chData);
m_isLoadingTable = true;
showChannelData(channelName);
m_isLoadingTable = false;
showCurve();
// calculateFitValues(chData);
// m_isLoadingTable = true;
// showChannelData(channelName);
// m_isLoadingTable = false;
// showCurve();
on_pBtn_fitting_clicked();
}
}
void EnergyScaleForm::on_pBtn_SaveAs_clicked()
{
QString SaveAsName = ui->pBtn_SaveAs->text();
QString targetFilePath;
QString fileName;
QString remark;
if(SaveAsName.contains("保存到系统"))
{
systemEnble = true;
QDialog dialog(this);
dialog.setWindowTitle(QStringLiteral(u"保存到系统 - 能量刻度配置"));
dialog.setFixedSize(400, 250);
dialog.setModal(true);
QVBoxLayout* mainLayout = new QVBoxLayout(&dialog);
mainLayout->setSpacing(15);
mainLayout->setContentsMargins(20, 20, 20, 20);
QHBoxLayout* nameLayout = new QHBoxLayout();
QLabel* nameLabel = new QLabel(QStringLiteral(u"能量刻度名称:"));
QLineEdit* nameEdit = new QLineEdit();
nameEdit->setPlaceholderText(QStringLiteral(u"请输入刻度名称:"));
if (!ui->lineEdit_name->text().isEmpty()) {
QString baseName = ui->lineEdit_name->text();
baseName = baseName.contains("[") ? baseName.split("]").last().trimmed() : baseName;
nameEdit->setText(baseName);
}
nameLayout->addWidget(nameLabel);
nameLayout->addWidget(nameEdit);
// 备注输入框
QVBoxLayout* remarkLayout = new QVBoxLayout();
QLabel* remarkLabel = new QLabel(QStringLiteral(u"备注:"));
QTextEdit* remarkEdit = new QTextEdit();
remarkEdit->setPlaceholderText(QStringLiteral(u"请输入备注信息(可选)"));
remarkEdit->setPlainText(ui->plainTextEdit_description->toPlainText()); // 填充现有备注
remarkLayout->addWidget(remarkLabel);
remarkLayout->addWidget(remarkEdit);
// 按钮组
QHBoxLayout* btnLayout = new QHBoxLayout();
QPushButton* okBtn = new QPushButton(QStringLiteral(u"保存"));
QPushButton* cancelBtn = new QPushButton(QStringLiteral(u"取消"));
okBtn->setDefault(true);
btnLayout->addStretch();
btnLayout->addWidget(okBtn);
btnLayout->addWidget(cancelBtn);
// 组装布局
mainLayout->addLayout(nameLayout);
mainLayout->addLayout(remarkLayout);
mainLayout->addLayout(btnLayout);
connect(okBtn, &QPushButton::clicked, &dialog, &QDialog::accept);
connect(cancelBtn, &QPushButton::clicked, &dialog, &QDialog::reject);
if (dialog.exec() != QDialog::Accepted) {
return;
}
fileName = nameEdit->text().trimmed();
remark = remarkEdit->toPlainText().trimmed();
if (fileName.isEmpty()) {
QMessageBox::warning(this, QStringLiteral(u"输入错误"), QStringLiteral(u"能量刻度名称不能为空!"));
return;
}
QString defaultDir = QDir(qApp->applicationDirPath()).filePath("configure/EnergyScale");
QDir dir(defaultDir);
if (!dir.exists() && !dir.mkpath(".")) {
QMessageBox::critical(this, QStringLiteral(u"错误"), QStringLiteral(u"无法创建目录:%1").arg(defaultDir));
return;
}
targetFilePath = dir.filePath(fileName + ".json"); // 强制.json后缀
if (QFile::exists(targetFilePath)) {
QMessageBox::StandardButton ret = QMessageBox::question(
this,
QStringLiteral(u"文件已存在"),
QStringLiteral(u"名称为“%1”的能量刻度文件已存在是否覆盖").arg(fileName),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No
);
if (ret != QMessageBox::Yes) {
return;
}
}
ui->plainTextEdit_description->setProperty("systemData",remark);
}else{
systemEnble = false;
// 选择保存路径
QString defaultDir = QDir(qApp->applicationDirPath()).filePath("configure/EnergyScale");
QString filePath = QFileDialog::getSaveFileName(this,
QString targetFilePath = QFileDialog::getSaveFileName(this,
"另存为能量刻度文件",
defaultDir,
"JSON文件 (*.json);;所有文件 (*.*)");
if (filePath.isEmpty()) {
if (targetFilePath.isEmpty()) {
return;
}
// 确保后缀是.json
if (!filePath.endsWith(".json", Qt::CaseInsensitive)) {
filePath += ".json";
if (!targetFilePath.endsWith(".json", Qt::CaseInsensitive)) {
targetFilePath += ".json";
}
}
// 保存文件
if (saveChannelDataToJson(filePath)) {
m_currentFilePath = filePath; // 更新当前文件路径
ui->lineEdit_name->setText(QFileInfo(filePath).baseName());
if (saveChannelDataToJson(targetFilePath)) {
// m_currentFilePath = targetFilePath; // 更新当前文件路径
// ui->lineEdit_name->setText(QFileInfo(targetFilePath).baseName());
loadAllFilesInTheFolder();
QMessageBox::information(this, "成功", "文件另存为成功");
} else {
QMessageBox::critical(this, "失败", "文件另存为失败");
}
}
void EnergyScaleForm::on_pBtn_Save_clicked()
{
systemEnble = false;
if (saveChannelDataToJson(m_currentFilePath)) {
QMessageBox::information(this, "成功", "数据保存成功");
} else {

View File

@ -100,6 +100,8 @@ private:
//记录当前加载的文件路径
QString m_currentFilePath;
bool systemEnble = false;
};
#endif // ENERGYSCALEFORM_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1086</width>
<height>584</height>
<width>1920</width>
<height>1080</height>
</rect>
</property>
<property name="minimumSize">
@ -65,7 +65,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_6" stretch="3,5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,5">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="3,1,5,0,1,1">
<item>
@ -214,6 +214,12 @@
</item>
<item>
<widget class="QLabel" name="label_fit_type_text">
<property name="minimumSize">
<size>
<width>287</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>y = a + bx</string>
</property>
@ -221,6 +227,12 @@
</item>
<item>
<widget class="QLabel" name="label_fit_result">
<property name="minimumSize">
<size>
<width>287</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>a = 1.21823, b = -5.0542</string>
</property>

View File

@ -70,10 +70,20 @@ void ThreeDDisplay::_init3DSurface()
ui->hLayout3D->setContentsMargins(0, 0, 0, 0);
// 设置轴标签和标题
m_surface->axisX()->setTitle("初级粒子能量 (MeV)");
m_surface->axisY()->setTitle("符合事件计数");
m_surface->axisZ()->setTitle("次级粒子能量和 (MeV)");
m_surface->axisX()->setTitle("初级粒子能量 (KeV)");
m_surface->axisX()->setTitleVisible(true); // 关键:启用标题显示
m_surface->axisX()->setLabelFormat("%.1f"); // 刻度标签格式
m_surface->axisX()->setLabelAutoRotation(30); // 标签自动旋转避免重叠
m_surface->axisY()->setTitle("符合事件计数");
m_surface->axisY()->setTitleVisible(true);
m_surface->axisY()->setLabelFormat("%.0f"); // 整数格式
m_surface->axisY()->setLabelAutoRotation(30);
m_surface->axisZ()->setTitle("次级粒子能量和 (KeV)");
m_surface->axisZ()->setTitleVisible(true);
m_surface->axisZ()->setLabelFormat("%.1f");
m_surface->axisZ()->setLabelAutoRotation(30);
// 创建自定义主题(或者修改当前主题)
Q3DTheme *customTheme = m_surface->activeTheme();
customTheme->setType(Q3DTheme::ThemeQt); // 使用Qt主题为基础