2025-04-18T17:30:34

This commit is contained in:
yuntang 2025-04-18 17:30:35 +08:00
parent 588f33a25b
commit 8aee1d8048
15 changed files with 757 additions and 15 deletions

View File

@ -25,6 +25,7 @@ SOURCES += \
global.cpp \
logger/logger.cpp \
ui/aboutform.cpp \
ui/coefficientselectionform.cpp \
ui/enthalpydatacorrectionform.cpp \
ui/rightwidget.cpp \
thirdparty/easylogging/easylogging++.cc \
@ -55,6 +56,7 @@ HEADERS += \
defines.h \
logger/logger.h \
ui/aboutform.h \
ui/coefficientselectionform.h \
ui/enthalpydatacorrectionform.h \
ui/rightwidget.h \
thirdparty/easylogging/easylogging++.h \
@ -79,6 +81,7 @@ HEADERS += \
FORMS += \
mainwindow.ui \
ui/aboutform.ui \
ui/coefficientselectionform.ui \
ui/degreeofcrystallinityform.ui \
ui/degreeofcureform.ui \
ui/enthalpydatacorrectionform.ui \

View File

@ -2,6 +2,8 @@
#include "pointcalculate.h"
#include "logger.h"
#include "global.h"
#include "confighandler.h"
QVector<Global::ExperimentData>PointCalculate:: _dataVtr;
QPointF PointCalculate::_peakPoint;
@ -246,8 +248,31 @@ float PointCalculate::calculateArea() {
integral += std::abs(cellArea);
}
/*
* H = K * S / w;
*/
float coefficient = 0.0f;
if(Global::_enthalpyCoefficientEnableFlag){
float startTemp = _leftSelectedPoint.x();
return integral;
float value1 = Global::_enthalpyCoefficientVtr.at(0);
float value2 = Global::_enthalpyCoefficientVtr.at(0);
float value3 = Global::_enthalpyCoefficientVtr.at(0);
coefficient = value1 * startTemp * startTemp +
value2 * startTemp +
value3;
}else{
coefficient = ConfigHandler::_configMap[ConInstrumentCoefficientStr].toFloat();
}
logde<<"coefficient:"<<coefficient;
float weight = 1.0f;
float area = integral * coefficient / weight;
return area;
}
QPair<QPointF, QPointF> PointCalculate::calculateStartAndEndPoint()

View File

@ -7,6 +7,9 @@ QVector<CurveFileData> _curveFileDataVtr;
ExperimentInfo _experimentInfo;
QVector<CurveExperimentData> _curveExperimentDataVtr;
bool _enthalpyCoefficientEnableFlag = false;
QVector<double> _enthalpyCoefficientVtr;
}
#if 0

View File

@ -78,6 +78,12 @@ extern QVector<CurveFileData> _curveFileDataVtr;
// Experiment setting data.
extern ExperimentInfo _experimentInfo;
extern QVector<CurveExperimentData> _curveExperimentDataVtr;
//
extern bool _enthalpyCoefficientEnableFlag;
//abc
extern QVector<double> _enthalpyCoefficientVtr;
}
#if 0

View File

@ -25,22 +25,31 @@ int main(int argc, char *argv[])
logde<<"config,instrument coefficient:"
<<ConfigHandler::_configMap[ConInstrumentCoefficientStr].toFloat();
#if 0
ConfigHandler::_configMap[ConInstrumentCoefficientStr] = 2.001f;
ConfigHandler::writer(false);
ConfigHandler::reader();
logde<<"config,instrument coefficient:"
<<ConfigHandler::_configMap[ConInstrumentCoefficientStr].toFloat();
#endif
//
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 启用高DPI缩放
QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/images/logo.png"));
#if 1
MainWindow w;
w.setWindowTitle("Analysis Tool");
w.setWindowIcon(QIcon(":/images/logo.png"));
w.show();
#endif
// EnthalpyDataCorrectionForm edf;
// edf.show();
// CoefficientSelectionForm csf;
// csf.show();
// AboutForm af;
// af.show();

View File

@ -24,6 +24,7 @@ MainWindow::MainWindow(QWidget *parent)
,_degreeOfCrystallinityForm(new DegreeOfCrystallinityForm(this))
,_aboutForm(new AboutForm(this))
,_enthalpyDataCorrectionForm(new EnthalpyDataCorrectionForm(this))
,_coefficientSelectionForm(new CoefficientSelectionForm(this))
{
ui->setupUi(this);
this->setToolTip(".....");
@ -73,6 +74,7 @@ MainWindow::MainWindow(QWidget *parent)
setSubWidgetAttribute(_degreeOfCrystallinityForm);
setSubWidgetAttribute(_aboutForm);
setSubWidgetAttribute(_enthalpyDataCorrectionForm);
setSubWidgetAttribute(_coefficientSelectionForm);
//
setActionEnable(true);
@ -332,7 +334,13 @@ void MainWindow::on_actionAbout_triggered()
_aboutForm->show();
}
void MainWindow::on_actionEnthalpyCorrection_triggered()
void MainWindow::on_actionEnthalpyCorrectionEdit_triggered()
{
_enthalpyDataCorrectionForm->show();
}
void MainWindow::on_actionEnthalpyCorrectionSelection_triggered()
{
_coefficientSelectionForm->show();
}

View File

@ -19,6 +19,7 @@
#include "oitautoanalysisparamform.h"
#include "aboutform.h"
#include "enthalpydatacorrectionform.h"
#include "coefficientselectionform.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -75,7 +76,9 @@ private slots:
void on_actionAbout_triggered();
void on_actionEnthalpyCorrection_triggered();
void on_actionEnthalpyCorrectionEdit_triggered();
void on_actionEnthalpyCorrectionSelection_triggered();
private:
void connections();
@ -98,5 +101,6 @@ private:
OITAutoAnalysisParamForm* _OITAutoAnalysisParamForm;
AboutForm *_aboutForm;
EnthalpyDataCorrectionForm* _enthalpyDataCorrectionForm;
CoefficientSelectionForm * _coefficientSelectionForm;
};
#endif // MAINWINDOW_H

View File

@ -67,7 +67,8 @@
<property name="title">
<string>工具</string>
</property>
<addaction name="actionEnthalpyCorrection"/>
<addaction name="actionEnthalpyCorrectionEdit"/>
<addaction name="actionEnthalpyCorrectionSelection"/>
</widget>
<widget class="QMenu" name="menu_6">
<property name="title">
@ -254,9 +255,14 @@
<string>关于</string>
</property>
</action>
<action name="actionEnthalpyCorrection">
<action name="actionEnthalpyCorrectionEdit">
<property name="text">
<string>热焓校正</string>
<string>热焓校正系数编辑</string>
</property>
</action>
<action name="actionEnthalpyCorrectionSelection">
<property name="text">
<string>热焓校正系数选择</string>
</property>
</action>
</widget>

View File

@ -0,0 +1,240 @@
#include <QFileDialog>
#include "coefficientselectionform.h"
#include "ui_coefficientselectionform.h"
#include "confighandler.h"
#include "logger.h"
#include "global.h"
CoefficientSelectionForm::CoefficientSelectionForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::CoefficientSelectionForm)
{
ui->setupUi(this);
setWindowTitle("热焓校正系数选择");
#if 1
ui->LineEditCoefficient->setText(
QString::number(
ConfigHandler::_configMap[ConInstrumentCoefficientStr].toFloat(),
'f',3));
#endif
ui->radioButtonSinglePointCoefficient->setChecked(true);
ui->radioButtonSinglePointCoefficient->setChecked(false);
on_radioButtonSinglePointCoefficient_toggled(true);
on_radioButtonMultiPointCoefficient_toggled(false);
ui->textEditFileContent->setReadOnly(true);
}
CoefficientSelectionForm::~CoefficientSelectionForm()
{
delete ui;
}
void CoefficientSelectionForm::on_pushButtonCalculate_clicked()
{
float theory = ui->LineEditTheory->text().toFloat();
float measure = ui->LineEditActualMeasurement->text().toFloat();
_instrumentCoefficient = theory/measure;
ui->LineEditCoefficient->setText(QString::number(_instrumentCoefficient,'f',3));
}
void CoefficientSelectionForm::on_pushButtonConfirm_clicked()
{
if(ui->radioButtonSinglePointCoefficient->isChecked()){
ConfigHandler::_configMap[ConInstrumentCoefficientStr] = _instrumentCoefficient;
ConfigHandler::writer();
Global::_enthalpyCoefficientEnableFlag = false;
}else{
QVector<double> xVtr,yVtr;
QJsonDocument jsonDoc = QJsonDocument::fromJson(_jsonStr.toUtf8());
QJsonArray jsonArray = jsonDoc.array();
for (const QJsonValue &value : jsonArray) {
QJsonObject jsonObj = value.toObject();
xVtr<<jsonObj["theory"].toDouble();
yVtr<<jsonObj["rate"].toDouble();
}
double coeff[3] = {0};
cubicLeastSquaresFit(xVtr.data(),yVtr.data(),xVtr.size(),coeff);
logde<<"y:"<<coeff[0]<<","
<<coeff[1]<<","
<<coeff[2];
Global::_enthalpyCoefficientEnableFlag = false;
Global::_enthalpyCoefficientVtr.clear();
Global::_enthalpyCoefficientVtr.push_back(coeff[2]);
Global::_enthalpyCoefficientVtr.push_back(coeff[1]);
Global::_enthalpyCoefficientVtr.push_back(coeff[0]);
}
}
void CoefficientSelectionForm::on_pushButtonExit_clicked()
{
ui->LineEditTheory->clear();
ui->LineEditCoefficient->clear();
ui->labelFilePath->clear();
ui->textEditFileContent->clear();
_jsonStr.clear();
hide();
}
void CoefficientSelectionForm::on_pushButtonSelectFile_clicked()
{
QString filePath = QFileDialog::getOpenFileName(
nullptr, "选择 JSON 文件", "", "JSON 文件 (*.json);;所有文件 (*.*)");
if (!filePath.isEmpty()) {
QFile file(filePath);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
_jsonStr = in.readAll();
file.close();
} else {
qDebug() << "无法打开文件:" << filePath;
return;
}
} else {
qDebug() << "未选择文件";
return;
}
//
ui->labelFilePath->setText(filePath);
ui->textEditFileContent->setText(_jsonStr);
}
void CoefficientSelectionForm::on_radioButtonSinglePointCoefficient_toggled(bool checked)
{
ui->LineEditTheory->setEnabled(checked);
ui->LineEditCoefficient->setEnabled(checked);
ui->LineEditActualMeasurement->setEnabled(checked);
ui->pushButtonCalculate->setEnabled(checked);
#if 0
if(checked){
ui->LineEditTheory->setEnabled(true);
ui->LineEditCoefficient->setEnabled(true);
ui->LineEditActualMeasurement->setEnabled(true);
ui->pushButtonCalculate->setEnabled(true);
}else{
ui->LineEditTheory->setEnabled(false);
ui->LineEditCoefficient->setEnabled(false);
ui->LineEditActualMeasurement->setEnabled(false);
ui->pushButtonCalculate->setEnabled(false);
}
#endif
}
void CoefficientSelectionForm::on_radioButtonMultiPointCoefficient_toggled(bool checked)
{
ui->pushButtonSelectFile->setEnabled(checked);
ui->textEditFileContent->setEnabled(checked);
#if 0
if(checked){
ui->pushButtonSelectFile->setEnabled(true);
ui->textEditFileContent->setEnabled(true);
}else{
ui->pushButtonSelectFile->setEnabled(false);
ui->textEditFileContent->setEnabled(false);
}
#endif
}
void CoefficientSelectionForm::cubicLeastSquaresFit(
double x[], double y[], int n, double coeff[])
{
int i, j, k;
double atemp[3] = {0}; // 存储x^0, x^1, x^2的和
double b[3] = {0}; // 右侧向量
// 计算各次幂的和
for (i = 0; i < n; i++) {
double xi = x[i];
double xi_pow2 = xi * xi; // x^2
// 累加atemp[0]到atemp[2]
atemp[0] += 1; // x^0的和等于数据点个数
atemp[1] += xi;
atemp[2] += xi_pow2;
// 计算右侧向量b
double yi = y[i];
b[0] += yi;
b[1] += yi * xi;
b[2] += yi * xi_pow2;
}
// 构建法方程矩阵
double a[3][3];
a[0][0] = atemp[0];
a[0][1] = atemp[1];
a[0][2] = atemp[2];
a[1][0] = atemp[1];
a[1][1] = atemp[2];
a[1][2] = 0;
a[2][0] = atemp[2];
a[2][1] = 0;
a[2][2] = 0;
// 高斯列主元消元法
for (k = 0; k < 2; k++) { // 消去第k列
// 寻找主元行
int max_row = k;
double max_val = fabs(a[k][k]);
for (i = k + 1; i < 3; i++) {
if (fabs(a[i][k]) > max_val) {
max_val = fabs(a[i][k]);
max_row = i;
}
}
// 交换行
if (max_row != k) {
for (j = k; j < 3; j++) {
double temp = a[k][j];
a[k][j] = a[max_row][j];
a[max_row][j] = temp;
}
double temp_b = b[k];
b[k] = b[max_row];
b[max_row] = temp_b;
}
// 消元
for (i = k + 1; i < 3; i++) {
double factor = a[i][k] / a[k][k];
for (j = k; j < 3; j++) {
a[i][j] -= factor * a[k][j];
}
b[i] -= factor * b[k];
}
}
// 回代求解
coeff[2] = b[2] / a[2][2];
for (i = 1; i >= 0; i--) {
double sum = 0.0;
for (j = i + 1; j < 3; j++) {
sum += a[i][j] * coeff[j];
}
coeff[i] = (b[i] - sum) / a[i][i];
}
}

View File

@ -0,0 +1,35 @@
#ifndef COEFFICIENTSELECTIONFORM_H
#define COEFFICIENTSELECTIONFORM_H
#include <QWidget>
namespace Ui {
class CoefficientSelectionForm;
}
class CoefficientSelectionForm : public QWidget
{
Q_OBJECT
public:
explicit CoefficientSelectionForm(QWidget *parent = nullptr);
~CoefficientSelectionForm();
private slots:
void on_radioButtonSinglePointCoefficient_toggled(bool checked);
void on_radioButtonMultiPointCoefficient_toggled(bool checked);
void on_pushButtonCalculate_clicked();
void on_pushButtonSelectFile_clicked();
void on_pushButtonConfirm_clicked();
void on_pushButtonExit_clicked();
private:
void cubicLeastSquaresFit(double x[], double y[], int n, double coeff[4]);
QString _jsonStr;
Ui::CoefficientSelectionForm *ui;
float _instrumentCoefficient;
};
#endif // COEFFICIENTSELECTIONFORM_H

View File

@ -0,0 +1,200 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CoefficientSelectionForm</class>
<widget class="QWidget" name="CoefficientSelectionForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>543</width>
<height>351</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>221</width>
<height>111</height>
</rect>
</property>
<property name="title">
<string>参数</string>
</property>
<widget class="QWidget" name="formLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>201</width>
<height>78</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="jGLabel">
<property name="text">
<string>理论熔融热焓(J/g):</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="LineEditTheory"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="jGLabel_2">
<property name="text">
<string>实测熔融热焓(J/g):</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="LineEditActualMeasurement"/>
</item>
</layout>
</widget>
</widget>
<widget class="QPushButton" name="pushButtonExit">
<property name="geometry">
<rect>
<x>400</x>
<y>320</y>
<width>80</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>退出</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButtonMultiPointCoefficient">
<property name="geometry">
<rect>
<x>250</x>
<y>10</y>
<width>91</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>多点系数</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>10</x>
<y>170</y>
<width>221</width>
<height>81</height>
</rect>
</property>
<property name="title">
<string>计算结果</string>
</property>
<widget class="QWidget" name="formLayoutWidget_2">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>191</width>
<height>41</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="kLabel">
<property name="text">
<string>仪器系数 K:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="LineEditCoefficient"/>
</item>
</layout>
</widget>
</widget>
<widget class="QRadioButton" name="radioButtonSinglePointCoefficient">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>91</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>单点系数</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonConfirm">
<property name="geometry">
<rect>
<x>290</x>
<y>320</y>
<width>80</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>确定</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonCalculate">
<property name="geometry">
<rect>
<x>110</x>
<y>270</y>
<width>85</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>计算</string>
</property>
</widget>
<widget class="QLabel" name="labelFilePath">
<property name="geometry">
<rect>
<x>250</x>
<y>40</y>
<width>281</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>当前热焓文件:</string>
</property>
</widget>
<widget class="QTextEdit" name="textEditFileContent">
<property name="geometry">
<rect>
<x>250</x>
<y>90</y>
<width>261</width>
<height>221</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButtonSelectFile">
<property name="geometry">
<rect>
<x>410</x>
<y>60</y>
<width>85</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>选择文件</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,3 +1,11 @@
#include <cmath>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>
#include <QJsonDocument>
#include <QDebug>
#include <QFileDialog>
#include "enthalpydatacorrectionform.h"
#include "ui_enthalpydatacorrectionform.h"
@ -7,12 +15,11 @@ EnthalpyDataCorrectionForm::EnthalpyDataCorrectionForm(QWidget *parent) :
{
ui->setupUi(this);
setWindowTitle("热焓校正");
// ui->lineEditTheoryIn->setText("28.6");
// ui->lineEditTheorySn->setText("60.5");
// ui->lineEditTheoryBi->setText("53.3");
setWindowTitle("热焓校正参数编辑");
// ui->lineEditTheoryIn->setText("28.6");
// ui->lineEditTheorySn->setText("60.5");
// ui->lineEditTheoryBi->setText("53.3");
}
@ -23,10 +30,160 @@ EnthalpyDataCorrectionForm::~EnthalpyDataCorrectionForm()
void EnthalpyDataCorrectionForm::on_pushButtonSave_clicked()
{
if(ui->checkBoxC6H12->isChecked()){
float theory = ui->lineEditTheoryC6H12->text().toFloat();
float measure = ui->lineEditMeasC6H12->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxHg->isChecked()){
float theory = ui->lineEditTheoryHg->text().toFloat();
float measure = ui->lineEditMeasHg->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxC6H5COOH->isChecked()){
float theory = ui->lineEditTheoryC6H5COOH->text().toFloat();
float measure = ui->lineEditMeasC6H5COOH->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxIn->isChecked()){
float theory = ui->lineEditTheoryIn->text().toFloat();
float measure = ui->lineEditMeasIn->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxSn->isChecked()){
float theory = ui->lineEditTheorySn->text().toFloat();
float measure = ui->lineEditMeasSn->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxBi->isChecked()){
float theory = ui->lineEditTheoryBi->text().toFloat();
float measure = ui->lineEditMeasBi->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxKC1O3->isChecked()){
float theory = ui->lineEditTheoryKC1O3->text().toFloat();
float measure = ui->lineEditMeasKC103->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxPb->isChecked()){
float theory = ui->lineEditTheoryPb->text().toFloat();
float measure = ui->lineEditMeasPb->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxKNO3->isChecked()){
float theory = ui->lineEditTheoryKNO3->text().toFloat();
float measure = ui->lineEditMeasKNO3->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxZn->isChecked()){
float theory = ui->lineEditTheoryZn->text().toFloat();
float measure = ui->lineEditMeasZn->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxAg2SO4->isChecked()){
float theory = ui->lineEditTheoryAg2SO4->text().toFloat();
float measure = ui->lineEditMeasAg2SO4->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxCsCl->isChecked()){
float theory = ui->lineEditTheoryCsC1->text().toFloat();
float measure = ui->lineEditMeasCsCl->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxSiO2->isChecked()){
float theory = ui->lineEditTheorySiO2->text().toFloat();
float measure = ui->lineEditMeasSiO2->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxK2SO4->isChecked()){
float theory = ui->lineEditTheoryK2SO4->text().toFloat();
float measure = ui->lineEditMeasK2SO4->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxK2CrO4->isChecked()){
float theory = ui->lineEditTheoryK2CrO4->text().toFloat();
float measure = ui->lineEditMeasK2CrO4->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxBaCO3->isChecked()){
float theory = ui->lineEditTheoryBaCO3->text().toFloat();
float measure = ui->lineEditMeasBaCO3->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxAg->isChecked()){
float theory = ui->lineEditTheoryAg->text().toFloat();
float measure = ui->lineEditMeasAg->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
if(ui->checkBoxCu->isChecked()){
float theory = ui->lineEditTheoryCu->text().toFloat();
float measure = ui->lineEditMeasCu->text().toFloat();
_theoryDataVtr.push_back({theory,theory/measure});
}
//
saveJson();
}
void EnthalpyDataCorrectionForm::on_pushButtonExit_clicked()
{
hide();
}
void EnthalpyDataCorrectionForm::saveJson()
{
// 创建一个 QJsonArray 来存储数据
QJsonArray jsonArray;
for (const TheoryData &data : _theoryDataVtr) {
QJsonObject jsonObj;
jsonObj["theory"] = data.theory;
jsonObj["rate"] = data.rate;
jsonArray.append(jsonObj);
}
// 创建一个 QJsonDocument 并设置根数组
QJsonDocument doc(jsonArray);
// 打开保存文件对话框,让用户选择保存位置
QString fileName = QFileDialog::getSaveFileName(nullptr, "保存 JSON 文件",
"new.json", "JSON Files (*.json)");
if (fileName.isEmpty()) {
qDebug() << "用户取消了操作";
return;
}
// 确保文件名以 .json 扩展名结尾
if (!fileName.endsWith(".json")) {
fileName.append(".json");
}
// 写入 JSON 数据到文件
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
qDebug() << "无法打开文件进行写入:" << file.errorString();
return ;
}
file.write(doc.toJson(QJsonDocument::Indented)); // 以格式化的方式写入 JSON 数据
file.close();
}

View File

@ -19,8 +19,15 @@ private slots:
void on_pushButtonSave_clicked();
void on_pushButtonExit_clicked();
private:
void saveJson();
private:
struct TheoryData{
float theory;
float rate;
};
QVector<TheoryData> _theoryDataVtr;
Ui::EnthalpyDataCorrectionForm *ui;
};

View File

@ -19,7 +19,7 @@
<x>40</x>
<y>50</y>
<width>431</width>
<height>518</height>
<height>520</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@ -142,9 +142,18 @@
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_6">
<property name="maximumSize">
<size>
<width>9999</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>理论温度(℃)</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="15" column="3">
@ -254,9 +263,18 @@
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_2">
<property name="maximumSize">
<size>
<width>9999</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>标样</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
@ -316,9 +334,18 @@
</item>
<item row="0" column="5">
<widget class="QLabel" name="label_4">
<property name="maximumSize">
<size>
<width>9999</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>实测热焓(J/g)</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="16" column="2">
@ -501,9 +528,18 @@
</item>
<item row="0" column="4">
<widget class="QLabel" name="label_5">
<property name="maximumSize">
<size>
<width>9999</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>理论热焓(J/g)</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
<item row="3" column="5">
@ -592,11 +628,11 @@
<string>退出</string>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>40</x>
<y>10</y>
<y>20</y>
<width>344</width>
<height>24</height>
</rect>

View File

@ -14,6 +14,9 @@ InstrumentCoefficientForm::InstrumentCoefficientForm(QWidget *parent) :
QString::number(
ConfigHandler::_configMap[ConInstrumentCoefficientStr].toFloat(),
'f',3));
ui->LineEditTheory->text().clear();
ui->LineEditActualMeasurement->text().clear();
}
InstrumentCoefficientForm::~InstrumentCoefficientForm()