能量刻度界面进行修改,gvf转csv 问题解决

This commit is contained in:
anxinglong 2026-05-27 19:35:17 +08:00
parent 1a2afa2416
commit c4c0e4a26f
8 changed files with 1438 additions and 315 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,21 +2,104 @@
#define ENERGYSCALEFORM_H
#include <QWidget>
#include <QMap>
#include <QVector>
#include <QwtPlotCurve>
#include <QwtSymbol>
#include <MeasureAnalysisView.h>
class CustomQwtPlot;
class QListWidgetItem;
namespace Ui {
class EnergyScaleForm;
}
class EnergyScaleForm : public QWidget
struct FitDataRow {
double daoSite;//道址
double energy;//能量
double fittingEnergy;//拟合能量
double energyFittingDeviation;//能量拟合偏差
double resolution;//分辨率
double fitResolution;//拟合分辨率
double resolutionFittingDeviation;//分辨率拟合偏差
};
struct ChannelData {
int energyFitDegree;//拟合公式
QVector<double> energyFitResultCoeffs;//能量拟合系数
QVector<FitDataRow> fitData;// 多条拟合数据行
QVector<double> fwhmFitResultCoeffs;// FWHM 拟合系数
};
class EnergyScaleForm : public MeasureAnalysisView
{
Q_OBJECT
public:
explicit EnergyScaleForm(QWidget *parent = nullptr);
~EnergyScaleForm();
virtual void InitViewWorkspace(const QString& project_name) override final;
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
private:
void setupPlot();
//加载能量刻度文件夹下所有的文件
void loadAllFilesInTheFolder();
//读取JSON文件
QMap<QString, ChannelData> parseJsonToChannels(const QString &filePath, QString &errorMsg);
//初始化通道数
void initComboBoxUi();
void initScaleDataTable();
void showChannelData(const QString channelName);
void showCurve();
void clearPlot();
QVector<QPointF> generateFitCurvePoints(const ChannelData &chData);
QVector<QPointF> generateFitCurvePoints(const double a = 0,const double b = 0,const double c = 0);
//计算拟合值和偏差
void calculateFitValues(ChannelData &chData);
//保存通道数据到JSON文件
bool saveChannelDataToJson(const QString &filePath);
//检查道址是否重复
bool isDaoSiteDuplicated(const QString &channelName, double daoSite);
bool fitFwhmModel(ChannelData &chData);
private slots:
void onItemDoubleClicked(QListWidgetItem *item);
void on_comboBox_channel_currentTextChanged(const QString &text);
void on_comboBox_fit_type_currentTextChanged(const QString &text);
void on_pBtn_Add_clicked();
void on_pBtn_Delete_clicked();
void on_pBtn_fitting_clicked();
void on_tablew_scale_data_cellChanged(int row, int column);
void on_pBtn_SaveAs_clicked();
void on_pBtn_Save_clicked();
void on_pBtn_Add_File_clicked();
void on_pBtn_Delete_File_clicked();
private:
Ui::EnergyScaleForm *ui;
CustomQwtPlot* _plot = nullptr;
QMap<QString, ChannelData> m_channelList;
QwtPlotCurve *_rawDataCurve; // 原始数据散点曲线
QwtPlotCurve *_fitCurve; // 拟合曲线
QwtSymbol *_rawDataSymbol; // 原始数据点样式
// 防止表格填充时触发cellChanged信号
bool m_isLoadingTable = false;
//记录当前加载的文件路径
QString m_currentFilePath;
};
#endif // ENERGYSCALEFORM_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>831</width>
<height>568</height>
<width>1086</width>
<height>584</height>
</rect>
</property>
<property name="minimumSize">
@ -19,338 +19,347 @@
<property name="windowTitle">
<string>能量刻度</string>
</property>
<widget class="QTableWidget" name="tablew_scale_data">
<property name="geometry">
<rect>
<x>190</x>
<y>420</y>
<width>621</width>
<height>101</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>道址</string>
</property>
</column>
<column>
<property name="text">
<string>能量</string>
</property>
</column>
<column>
<property name="text">
<string>拟合能量</string>
</property>
</column>
<column>
<property name="text">
<string>能量拟合偏差</string>
</property>
</column>
<column>
<property name="text">
<string>分辨率</string>
</property>
</column>
<column>
<property name="text">
<string>拟合分辨率</string>
</property>
</column>
<column>
<property name="text">
<string>分辨率拟合偏差</string>
</property>
</column>
</widget>
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>151</width>
<height>531</height>
</rect>
</property>
<property name="title">
<string>能量刻度管理列表</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTreeWidget" name="treeWidget">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,5">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>能量刻度管理列表</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="pushButton_4">
<property name="text">
<string>添加</string>
</property>
</widget>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<property name="text">
<string>删除</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QPushButton" name="pBtn_Add_File">
<property name="text">
<string>添加</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pBtn_Delete_File">
<property name="text">
<string>删除</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>191</x>
<y>9</y>
<width>631</width>
<height>338</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>能量刻度信息</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6" stretch="3,5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,5">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="3,1,5,0,1,1">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>能量刻度信息</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="2,3" rowminimumheight="2,3" columnminimumwidth="0,0">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="minimumSize">
<size>
<width>85</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>能量刻度命名:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_name"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
<width>85</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>备注说明:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="plainTextEdit_description">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<property name="minimumSize">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>通道:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_channel"/>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>85</width>
<height>0</height>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>能量刻度命名:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_name"/>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="pBtn_Save">
<property name="text">
<string>保存</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pBtn_SaveAs">
<property name="text">
<string>另存为</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>公式拟合</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>拟合公式:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="comboBox_fit_type">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pBtn_fitting">
<property name="text">
<string>拟合</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_fit_type_text">
<property name="text">
<string>y = a + bx</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_fit_result">
<property name="text">
<string>a = 1.21823, b = -5.0542</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>能量刻度拟合数据</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<widget class="QPushButton" name="pBtn_Add">
<property name="text">
<string>新增</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pBtn_Delete">
<property name="text">
<string>删除</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>85</width>
<height>0</height>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="text">
<string>设备测量配置:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_measure_dev_cfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
<width>85</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>备注说明:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit_description">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>通道:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_channel"/>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>保存</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>另存为</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>公式拟合</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>拟合公式:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="comboBox_fit_type">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>拟合</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_fit_type_text">
<property name="text">
<string>y = a + bx</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_fit_result">
<property name="text">
<string>a = 1.21823, b = -5.0542</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="styleSheet">
<string notr="true">background-color: rgb(85, 170, 255);</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QWidget" name="widget" native="true">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="layout_fittingCurve">
<property name="spacing">
<number>0</number>
</property>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tablew_scale_data">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>道址</string>
</property>
</column>
<column>
<property name="text">
<string>能量</string>
</property>
</column>
<column>
<property name="text">
<string>拟合能量</string>
</property>
</column>
<column>
<property name="text">
<string>能量拟合偏差</string>
</property>
</column>
<column>
<property name="text">
<string>分辨率</string>
</property>
</column>
<column>
<property name="text">
<string>拟合分辨率</string>
</property>
</column>
<column>
<property name="text">
<string>分辨率拟合偏差</string>
</property>
</column>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>

View File

@ -196,6 +196,12 @@ void GvfToCsv::convertGVF2CSVAsync(const QString &gvfPath, const QString &csvPat
void GvfToCsv::onSqliteOperationCompleted(bool success, const QString &msg)
{
if (!m_sqliteWorker) {
setLastError("SQLite 工作对象已被销毁");
emit conversionFinished(false);
return;
}
if (!success) {
setLastError(QString("GVF数据读取失败: %1").arg(msg));
cleanUp();
@ -219,9 +225,14 @@ void GvfToCsv::onSqliteOperationCompleted(bool success, const QString &msg)
void GvfToCsv::processDBData()
{
if (!m_sqliteWorker) {
throw std::runtime_error("SQLite 工作对象已销毁,无法读取数据");
}
QVector<DataBaseStruct> dbList = m_sqliteWorker->DataBaseList();
if (dbList.isEmpty()) {
throw std::runtime_error("GVF数据库中无任何记录");
return;
}
QFile outFile(m_csvPath);
if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {

View File

@ -100,6 +100,16 @@ void MeasureAnalysisTreeView::onNodeDoubleClicked(const QModelIndex& index)
}
}
} break;
case AnalysisType::EnergyScale:{
MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name);
if (project_model) {
auto file_name = project_model->GetEnergyScaleFilename();
if ( !file_name.isEmpty() ) {
data_files_set[QStringLiteral(u"能量刻度")] = file_name;
}
}
}
;break;
case AnalysisType::ParticleData: {
MeasureAnalysisProjectModel* project_model = _model->GetProjectModel(project_name);
if (project_model) {

View File

@ -13,6 +13,7 @@
#include "AntiConformEnergySpectrumView.h"
#include "CoincidenceEventTimeView.h"
#include "NuclideAnalysisView.h"
#include "EnergyScaleForm.h"
#include <QMap>
MeasureAnalysisView* MeasureAnalysisView::NewAnalyzeView(AnalysisType view_type)
@ -28,8 +29,8 @@ MeasureAnalysisView* MeasureAnalysisView::NewAnalyzeView(AnalysisType view_type)
new_view->setDeleteOnClose(true);
} break;
case AnalysisType::EnergyScale: {
// new_view = new MeasureAnalysisDataTableView;
// new_view->setDeleteOnClose(true);
new_view = new EnergyScaleForm;
new_view->setDeleteOnClose(true);
} break;
case AnalysisType::EfficiencyScale: {
// new_view = new MeasureAnalysisDataTableView;

View File

@ -467,7 +467,7 @@ void ConformityAnalysis::loadHistoryFromFile()
QString binPath = QDir(_workspace).filePath(QString("surface_%1.bin").arg(c));
if (!QFile::exists(jsonPath)) {
qDebug() << "[ConformityAnalysis] " << c << "重符合历史文件不存在:" << jsonPath;
// qDebug() << "[ConformityAnalysis] " << c << "重符合历史文件不存在:" << jsonPath;
continue;
}

View File

@ -180,7 +180,7 @@
<widget class="QLabel" name="lineEdit_begin_start">
<property name="minimumSize">
<size>
<width>106</width>
<width>50</width>
<height>21</height>
</size>
</property>
@ -200,7 +200,7 @@
<widget class="QLabel" name="lineEdit_begin_end">
<property name="minimumSize">
<size>
<width>106</width>
<width>50</width>
<height>21</height>
</size>
</property>
@ -266,7 +266,7 @@
<widget class="QLabel" name="lineEdit_second_start">
<property name="minimumSize">
<size>
<width>106</width>
<width>50</width>
<height>21</height>
</size>
</property>
@ -286,7 +286,7 @@
<widget class="QLabel" name="lineEdit_second_end">
<property name="minimumSize">
<size>
<width>106</width>
<width>50</width>
<height>21</height>
</size>
</property>
@ -358,7 +358,7 @@
<widget class="QLabel" name="lineEdit_count">
<property name="minimumSize">
<size>
<width>150</width>
<width>100</width>
<height>21</height>
</size>
</property>