#include #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::showEvent(QShowEvent *event) { } 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{ QJsonDocument doc = QJsonDocument::fromJson(_jsonStr.toUtf8()); if (doc.isNull()) { logde << "Failed to parse JSON data"; return; } if (!doc.isObject()) { logde << "JSON data is not an object"; return ; } QJsonObject majorObj = doc.object(); { QJsonObject subObj = majorObj[Global::AtomsphereData].toObject(); double temperature = subObj[Global::Atmosphere].toDouble(); double heatingRate = subObj[Global::HeatingRate].toDouble(); logde<<"temperatur:"< xVtr,yVtr; for (const QJsonValue &value : jsonArray) { QJsonObject jsonObj = value.toObject(); xVtr<LineEditTheory->clear(); ui->LineEditCoefficient->clear(); ui->labelFilePath->clear(); ui->textEditFileContent->clear(); _jsonStr.clear(); #endif 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->labelFilePath->setToolTip(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 }