#include "thermalwidget.h" #include "xlsxdocument.h" #include #include #include #include #include extern double g_area; extern double g_quality; QuadraticFitResult g_result1, g_result2; ThermalWidget::ThermalWidget(QWidget *parent) : QWidget(parent) { // g_result1.a = 0.000141348; // g_result1.b = -0.0374065; // g_result1.c = 6.98113; g_result1.a = 0; g_result1.b = 0; g_result1.c = 1; QGridLayout* layout = new QGridLayout(this); QLabel* label1 = new QLabel(this); label1->setText("序号"); QLabel* label2 = new QLabel(this); label2->setText("样品"); QLabel* label3 = new QLabel(this); label3->setText("理论温度(C)"); QLabel* label4 = new QLabel(this); label4->setText("理论热焓(J/g)"); QLabel* label5 = new QLabel(this); label5->setText("实测热焓(J/g)"); QLabel* slabel1 = new QLabel(this); slabel1->setText("C6H12"); QLabel* slabel2 = new QLabel(this); slabel2->setText("Hg"); QLabel* slabel3 = new QLabel(this); slabel3->setText("C6H5COOH"); QLabel* slabel4 = new QLabel(this); slabel4->setText("In"); QLabel* slabel5 = new QLabel(this); slabel5->setText("Sn"); QLabel* slabel6 = new QLabel(this); slabel6->setText("Bi"); QLabel* slabel7 = new QLabel(this); slabel7->setText("KC1O3"); QLabel* slabel8 = new QLabel(this); slabel8->setText("Pb"); QLabel* slabel9 = new QLabel(this); slabel9->setText("KNO3"); QLabel* slabel10 = new QLabel(this); slabel10->setText("Zn"); QLabel* slabel11 = new QLabel(this); slabel11->setText("Ag2SO4"); QLabel* slabel12 = new QLabel(this); slabel12->setText("CsCl"); QLabel* slabel13 = new QLabel(this); slabel13->setText("SiO2"); QLabel* slabel14 = new QLabel(this); slabel14->setText("K2SO4"); QLabel* slabel15 = new QLabel(this); slabel15->setText("K2CrO4"); QLabel* slabel16 = new QLabel(this); slabel16->setText("BaCO3"); QLabel* slabel17 = new QLabel(this); slabel17->setText("Ag"); QLabel* slabel18 = new QLabel(this); slabel18->setText("Cu"); tlabel1 = new QLabel(this); tlabel1->setText("-86.0"); tlabel2 = new QLabel(this); tlabel2->setText("-38.8"); tlabel3 = new QLabel(this); tlabel3->setText("122.1"); tlabel4 = new QLabel(this); tlabel4->setText("156.6"); tlabel5 = new QLabel(this); tlabel5->setText("231.9"); tlabel6 = new QLabel(this); tlabel6->setText("271.4"); tlabel7 = new QLabel(this); tlabel7->setText("299.5"); tlabel8 = new QLabel(this); tlabel8->setText("327.4"); tlabel9 = new QLabel(this); tlabel9->setText("334.0"); tlabel10 = new QLabel(this); tlabel10->setText("419.5"); tlabel11 = new QLabel(this); tlabel11->setText("430.0"); tlabel12 = new QLabel(this); tlabel12->setText("476.0"); tlabel13 = new QLabel(this); tlabel13->setText("573.0"); tlabel14 = new QLabel(this); tlabel14->setText("583.0"); tlabel15 = new QLabel(this); tlabel15->setText("665.0"); tlabel16 = new QLabel(this); tlabel16->setText("810.0"); tlabel17 = new QLabel(this); tlabel17->setText("961.8"); tlabel18 = new QLabel(this); tlabel18->setText("1083.0"); checkBox1 = new QCheckBox(this); checkBox1->setText("1"); checkBox2 = new QCheckBox(this); checkBox2->setText("2"); checkBox3 = new QCheckBox(this); checkBox3->setText("3"); checkBox4 = new QCheckBox(this); checkBox4->setText("4"); checkBox5 = new QCheckBox(this); checkBox5->setText("5"); checkBox6 = new QCheckBox(this); checkBox6->setText("6"); checkBox7 = new QCheckBox(this); checkBox7->setText("7"); checkBox8 = new QCheckBox(this); checkBox8->setText("8"); checkBox9 = new QCheckBox(this); checkBox9->setText("9"); checkBox10 = new QCheckBox(this); checkBox10->setText("10"); checkBox11 = new QCheckBox(this); checkBox11->setText("11"); checkBox12 = new QCheckBox(this); checkBox12->setText("12"); checkBox13 = new QCheckBox(this); checkBox13->setText("13"); checkBox14 = new QCheckBox(this); checkBox14->setText("14"); checkBox15 = new QCheckBox(this); checkBox15->setText("15"); checkBox16 = new QCheckBox(this); checkBox16->setText("16"); checkBox17 = new QCheckBox(this); checkBox17->setText("17"); checkBox18 = new QCheckBox(this); checkBox18->setText("18"); deal1Button = new QPushButton(this); deal1Button->setText("校正"); deal2Button = new QPushButton(this); deal2Button->setText("再校正"); saveButton = new QPushButton(this); saveButton->setText("保存"); exitButton = new QPushButton(this); exitButton->setText("退出"); m_ttlineEdit1 = new QLineEdit(this); m_ttlineEdit1->setAlignment( Qt::AlignHCenter); m_ttlineEdit1->setStyleSheet("border:1px solid black;"); m_ttlineEdit2 = new QLineEdit(this); m_ttlineEdit2->setAlignment( Qt::AlignHCenter); m_ttlineEdit2->setStyleSheet("border:1px solid black;"); m_ttlineEdit3 = new QLineEdit(this); m_ttlineEdit3->setAlignment( Qt::AlignHCenter); m_ttlineEdit3->setStyleSheet("border:1px solid black;"); m_ttlineEdit4 = new QLineEdit(this); m_ttlineEdit4->setAlignment( Qt::AlignHCenter); m_ttlineEdit4->setStyleSheet("border:1px solid black;"); m_ttlineEdit4->setText("28.6"); m_ttlineEdit4->setAlignment( Qt::AlignHCenter); m_ttlineEdit5 = new QLineEdit(this); m_ttlineEdit5->setStyleSheet("border:1px solid black;"); m_ttlineEdit5->setText("60.5"); m_ttlineEdit5->setAlignment( Qt::AlignHCenter); m_ttlineEdit6 = new QLineEdit(this); m_ttlineEdit6->setAlignment( Qt::AlignHCenter); m_ttlineEdit6->setStyleSheet("border:1px solid black;"); m_ttlineEdit6->setText("53.3"); m_ttlineEdit7 = new QLineEdit(this); m_ttlineEdit7->setAlignment( Qt::AlignHCenter); m_ttlineEdit7->setStyleSheet("border:1px solid black;"); m_ttlineEdit8 = new QLineEdit(this); m_ttlineEdit8->setAlignment( Qt::AlignHCenter); m_ttlineEdit8->setStyleSheet("border:1px solid black;"); m_ttlineEdit8->setText("23.02"); m_ttlineEdit9 = new QLineEdit(this); m_ttlineEdit9->setAlignment( Qt::AlignHCenter); m_ttlineEdit9->setStyleSheet("border:1px solid black;"); m_ttlineEdit10 = new QLineEdit(this); m_ttlineEdit10->setAlignment( Qt::AlignHCenter); m_ttlineEdit10->setText("107.6"); m_ttlineEdit10->setStyleSheet("border:1px solid black;"); m_ttlineEdit11 = new QLineEdit(this); m_ttlineEdit11->setAlignment( Qt::AlignHCenter); m_ttlineEdit11->setStyleSheet("border:1px solid black;"); m_ttlineEdit12 = new QLineEdit(this); m_ttlineEdit12->setAlignment( Qt::AlignHCenter); m_ttlineEdit12->setStyleSheet("border:1px solid black;"); m_ttlineEdit13 = new QLineEdit(this); m_ttlineEdit13->setAlignment( Qt::AlignHCenter); m_ttlineEdit13->setStyleSheet("border:1px solid black;"); m_ttlineEdit14 = new QLineEdit(this); m_ttlineEdit14->setAlignment( Qt::AlignHCenter); m_ttlineEdit14->setStyleSheet("border:1px solid black;"); m_ttlineEdit15 = new QLineEdit(this); m_ttlineEdit15->setAlignment( Qt::AlignHCenter); m_ttlineEdit15->setStyleSheet("border:1px solid black;"); m_ttlineEdit16 = new QLineEdit(this); m_ttlineEdit16->setAlignment( Qt::AlignHCenter); m_ttlineEdit16->setStyleSheet("border:1px solid black;"); m_ttlineEdit17 = new QLineEdit(this); m_ttlineEdit17->setAlignment( Qt::AlignHCenter); m_ttlineEdit17->setStyleSheet("border:1px solid black;"); m_ttlineEdit18 = new QLineEdit(this); m_ttlineEdit18->setAlignment( Qt::AlignHCenter); m_ttlineEdit18->setStyleSheet("border:1px solid black;"); m_rtlineEdit1 = new QLineEdit(this); m_rtlineEdit1->setStyleSheet("border:1px solid black;"); m_rtlineEdit2 = new QLineEdit(this); m_rtlineEdit2->setStyleSheet("border:1px solid black;"); m_rtlineEdit3 = new QLineEdit(this); m_rtlineEdit3->setStyleSheet("border:1px solid black;"); m_rtlineEdit4 = new QLineEdit(this); m_rtlineEdit4->setStyleSheet("border:1px solid black;"); m_rtlineEdit5 = new QLineEdit(this); m_rtlineEdit5->setStyleSheet("border:1px solid black;"); m_rtlineEdit6 = new QLineEdit(this); m_rtlineEdit6->setStyleSheet("border:1px solid black;"); m_rtlineEdit7 = new QLineEdit(this); m_rtlineEdit7->setStyleSheet("border:1px solid black;"); m_rtlineEdit8 = new QLineEdit(this); m_rtlineEdit8->setStyleSheet("border:1px solid black;"); m_rtlineEdit9 = new QLineEdit(this); m_rtlineEdit9->setStyleSheet("border:1px solid black;"); m_rtlineEdit10 = new QLineEdit(this); m_rtlineEdit10->setStyleSheet("border:1px solid black;"); m_rtlineEdit11 = new QLineEdit(this); m_rtlineEdit11->setStyleSheet("border:1px solid black;"); m_rtlineEdit12 = new QLineEdit(this); m_rtlineEdit12->setStyleSheet("border:1px solid black;"); m_rtlineEdit13 = new QLineEdit(this); m_rtlineEdit13->setStyleSheet("border:1px solid black;"); m_rtlineEdit14 = new QLineEdit(this); m_rtlineEdit14->setStyleSheet("border:1px solid black;"); m_rtlineEdit15 = new QLineEdit(this); m_rtlineEdit15->setStyleSheet("border:1px solid black;"); m_rtlineEdit16 = new QLineEdit(this); m_rtlineEdit16->setStyleSheet("border:1px solid black;"); m_rtlineEdit17 = new QLineEdit(this); m_rtlineEdit17->setStyleSheet("border:1px solid black;"); m_rtlineEdit18 = new QLineEdit(this); m_rtlineEdit18->setStyleSheet("border:1px solid black;"); layout->addWidget(label1, 0, 0); layout->addWidget(label2, 0, 1); layout->addWidget(label3, 0, 2); layout->addWidget(label4, 0, 3); layout->addWidget(label5, 0, 4); layout->addWidget(checkBox1, 1, 0); layout->addWidget(checkBox2, 2, 0); layout->addWidget(checkBox3, 3, 0); layout->addWidget(checkBox4, 4, 0); layout->addWidget(checkBox5, 5, 0); layout->addWidget(checkBox6, 6, 0); layout->addWidget(checkBox7, 7, 0); layout->addWidget(checkBox8, 8, 0); layout->addWidget(checkBox9, 9, 0); layout->addWidget(checkBox10, 10, 0); layout->addWidget(checkBox11, 11, 0); layout->addWidget(checkBox12, 12, 0); layout->addWidget(checkBox13, 13, 0); layout->addWidget(checkBox14, 14, 0); layout->addWidget(checkBox15, 15, 0); layout->addWidget(checkBox16, 16, 0); layout->addWidget(checkBox17, 17, 0); layout->addWidget(checkBox18, 18, 0); layout->addWidget(slabel1, 1, 1); layout->addWidget(slabel2, 2, 1); layout->addWidget(slabel3, 3, 1); layout->addWidget(slabel4, 4, 1); layout->addWidget(slabel5, 5, 1); layout->addWidget(slabel6, 6, 1); layout->addWidget(slabel7, 7, 1); layout->addWidget(slabel8, 8, 1); layout->addWidget(slabel9, 9, 1); layout->addWidget(slabel10, 10, 1); layout->addWidget(slabel11, 11, 1); layout->addWidget(slabel12, 12, 1); layout->addWidget(slabel13, 13, 1); layout->addWidget(slabel14, 14, 1); layout->addWidget(slabel15, 15, 1); layout->addWidget(slabel16, 16, 1); layout->addWidget(slabel17, 17, 1); layout->addWidget(slabel18, 18, 1); layout->addWidget(tlabel1, 1, 2); layout->addWidget(tlabel2, 2, 2); layout->addWidget(tlabel3, 3, 2); layout->addWidget(tlabel4, 4, 2); layout->addWidget(tlabel5, 5, 2); layout->addWidget(tlabel6, 6, 2); layout->addWidget(tlabel7, 7, 2); layout->addWidget(tlabel8, 8, 2); layout->addWidget(tlabel9, 9, 2); layout->addWidget(tlabel10, 10, 2); layout->addWidget(tlabel11, 11, 2); layout->addWidget(tlabel12, 12, 2); layout->addWidget(tlabel13, 13, 2); layout->addWidget(tlabel14, 14, 2); layout->addWidget(tlabel15, 15, 2); layout->addWidget(tlabel16, 16, 2); layout->addWidget(tlabel17, 17, 2); layout->addWidget(tlabel18, 18, 2); layout->addWidget(m_ttlineEdit1, 1, 3); layout->addWidget(m_ttlineEdit2, 2, 3); layout->addWidget(m_ttlineEdit3, 3, 3); layout->addWidget(m_ttlineEdit4, 4, 3); layout->addWidget(m_ttlineEdit5, 5, 3); layout->addWidget(m_ttlineEdit6, 6, 3); layout->addWidget(m_ttlineEdit7, 7, 3); layout->addWidget(m_ttlineEdit8, 8, 3); layout->addWidget(m_ttlineEdit9, 9, 3); layout->addWidget(m_ttlineEdit10, 10, 3); layout->addWidget(m_ttlineEdit11, 11, 3); layout->addWidget(m_ttlineEdit12, 12, 3); layout->addWidget(m_ttlineEdit13, 13, 3); layout->addWidget(m_ttlineEdit14, 14, 3); layout->addWidget(m_ttlineEdit15, 15, 3); layout->addWidget(m_ttlineEdit16, 16, 3); layout->addWidget(m_ttlineEdit17, 17, 3); layout->addWidget(m_ttlineEdit18, 18, 3); layout->addWidget(m_rtlineEdit1, 1, 4); layout->addWidget(m_rtlineEdit2, 2, 4); layout->addWidget(m_rtlineEdit3, 3, 4); layout->addWidget(m_rtlineEdit4, 4, 4); layout->addWidget(m_rtlineEdit5, 5, 4); layout->addWidget(m_rtlineEdit6, 6, 4); layout->addWidget(m_rtlineEdit7, 7, 4); layout->addWidget(m_rtlineEdit8, 8, 4); layout->addWidget(m_rtlineEdit9, 9, 4); layout->addWidget(m_rtlineEdit10, 10, 4); layout->addWidget(m_rtlineEdit11, 11, 4); layout->addWidget(m_rtlineEdit12, 12, 4); layout->addWidget(m_rtlineEdit13, 13, 4); layout->addWidget(m_rtlineEdit14, 14, 4); layout->addWidget(m_rtlineEdit15, 15, 4); layout->addWidget(m_rtlineEdit16, 16, 4); layout->addWidget(m_rtlineEdit17, 17, 4); layout->addWidget(m_rtlineEdit18, 18, 4); layout->addWidget(deal1Button, 19, 3); layout->addWidget(deal2Button, 19, 4); ///layout->addWidget(saveButton, 19, 3); ///layout->addWidget(exitButton, 19, 4); layout->setSpacing(20); setLayout(layout); connect(deal1Button, SIGNAL(clicked()), this, SLOT(deal_checkbox_data())); connect(deal2Button, SIGNAL(clicked()), this, SLOT(redo_deal_checkbox_data())); connect(saveButton, SIGNAL(clicked()), this, SLOT(fit_test())); } ThermalWidget::~ThermalWidget() { } void ThermalWidget::redo_deal_checkbox_data() { QVector points; if(checkBox1->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel1->text(); ttstr = m_ttlineEdit1->text(); rtstr = m_rtlineEdit1->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox2->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel2->text(); ttstr = m_ttlineEdit2->text(); rtstr = m_rtlineEdit2->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); ///tmpoint.setY((ttstr.toDouble()/thermal4)-1); points.append(tmpoint); } if(checkBox3->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel3->text(); ttstr = m_ttlineEdit3->text(); rtstr = m_rtlineEdit3->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); ///tmpoint.setY((ttstr.toDouble()/thermal4)-1); points.append(tmpoint); } if(checkBox4->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel4->text(); ttstr = m_ttlineEdit4->text(); rtstr = m_rtlineEdit4->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); ///tmpoint.setY((ttstr.toDouble()/thermal4)-1); points.append(tmpoint); } if(checkBox5->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel5->text(); ttstr = m_ttlineEdit5->text(); rtstr = m_rtlineEdit5->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); ///tmpoint.setY((ttstr.toDouble()/thermal5)-1); points.append(tmpoint); } if(checkBox6->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel6->text(); ttstr = m_ttlineEdit6->text(); rtstr = m_rtlineEdit6->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox7->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel7->text(); ttstr = m_ttlineEdit7->text(); rtstr = m_rtlineEdit7->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox8->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel8->text(); ttstr = m_ttlineEdit8->text(); rtstr = m_rtlineEdit8->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); ///tmpoint.setY(ttstr.toDouble()/thermal8); points.append(tmpoint); } if(checkBox9->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel9->text(); ttstr = m_ttlineEdit9->text(); rtstr = m_rtlineEdit9->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox10->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel10->text(); ttstr = m_ttlineEdit10->text(); rtstr = m_rtlineEdit10->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); ///tmpoint.setY((ttstr.toDouble()/thermal10)-1); points.append(tmpoint); } if(checkBox11->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel11->text(); ttstr = m_ttlineEdit11->text(); rtstr = m_rtlineEdit11->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox12->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel12->text(); ttstr = m_ttlineEdit12->text(); rtstr = m_rtlineEdit12->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox13->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel13->text(); ttstr = m_ttlineEdit13->text(); rtstr = m_rtlineEdit13->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox14->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel14->text(); ttstr = m_ttlineEdit14->text(); rtstr = m_rtlineEdit14->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox15->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel15->text(); ttstr = m_ttlineEdit15->text(); rtstr = m_rtlineEdit15->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox16->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel16->text(); ttstr = m_ttlineEdit16->text(); rtstr = m_rtlineEdit16->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox17->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel17->text(); ttstr = m_ttlineEdit17->text(); rtstr = m_rtlineEdit17->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } if(checkBox18->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel18->text(); ttstr = m_ttlineEdit18->text(); rtstr = m_rtlineEdit18->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY((ttstr.toDouble()/rtstr.toDouble())-1); points.append(tmpoint); } result2 = quadraticFit(points); qDebug() << "拟合方程1: y = " << result1.a << "x² + " << result1.b << "x + " << result1.c; qDebug() << "拟合方程2: y = " << result2.a << "x² + " << result2.b << "x + " << result2.c; qDebug() << "拟合方程总: y = " << (result1.a+result2.a) << "x² + " << (result1.b+result2.b) << "x + " << (result1.c+result2.c); g_result1.a = result1.a+result2.a; g_result1.b = result1.b+result2.b; g_result1.c = result1.c+result2.c; /*if(checkBox4->isChecked()==true) { double temper=start4string.toDouble(); double thermal = ((result1.a+result2.a)*temper*temper+(result1.b+result2.b)*temper+(result1.c+result2.c))*area4string.toDouble()/qua4string.toDouble(); ///m_rtlineEdit4->setText(QString("%1").arg(thermal)); } if(checkBox5->isChecked()==true) { double temper=start5string.toDouble(); double thermal = ((result1.a+result2.a)*temper*temper+(result1.b+result2.b)*temper+(result1.c+result2.c))*area5string.toDouble()/qua5string.toDouble(); ///m_rtlineEdit5->setText(QString("%1").arg(thermal)); } if(checkBox8->isChecked()==true) { double temper=start8string.toDouble(); double thermal = ((result1.a+result2.a)*temper*temper+(result1.b+result2.b)*temper+(result1.c+result2.c))*area8string.toDouble()/qua8string.toDouble(); ///m_rtlineEdit8->setText(QString("%1").arg(thermal)); } if(checkBox10->isChecked()==true) { double temper=start10string.toDouble(); double thermal = ((result1.a+result2.a)*temper*temper+(result1.b+result2.b)*temper+(result1.c+result2.c))*area10string.toDouble()/qua10string.toDouble(); ///m_rtlineEdit10->setText(QString("%1").arg(thermal)); }*/ } void ThermalWidget::deal_checkbox_data() { QVector points; if(checkBox1->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel1->text(); ttstr = m_ttlineEdit1->text(); rtstr = m_rtlineEdit1->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox2->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel2->text(); ttstr = m_ttlineEdit2->text(); rtstr = m_rtlineEdit2->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox3->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel3->text(); ttstr = m_ttlineEdit3->text(); rtstr = m_rtlineEdit3->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox4->isChecked()==true) { /*QXlsx::Document xlsx("sample.ana"); xlsx.selectSheet("In"); QXlsx::Worksheet *workSheet = xlsx.currentWorksheet(); qua4string = workSheet->cellAt(1, 2)->value().toString(); area4string = workSheet->cellAt(1, 3)->value().toString(); start4string = workSheet->cellAt(1, 4)->value().toString(); xlsx.deleteLater();*/ QString temperstr, ttstr, rtstr; temperstr = tlabel4->text(); ttstr = m_ttlineEdit4->text(); rtstr = m_rtlineEdit4->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); ///tmpoint.setY(ttstr.toDouble()/area4string.toDouble()*qua4string.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox5->isChecked()==true) { /*QXlsx::Document xlsx("sample.ana"); xlsx.selectSheet("Sn"); QXlsx::Worksheet *workSheet = xlsx.currentWorksheet(); qua5string = workSheet->cellAt(1, 2)->value().toString(); area5string = workSheet->cellAt(1, 3)->value().toString(); start5string = workSheet->cellAt(1, 4)->value().toString(); xlsx.deleteLater();*/ QString temperstr, ttstr, rtstr; temperstr = tlabel5->text(); ttstr = m_ttlineEdit5->text(); rtstr = m_rtlineEdit5->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); ///tmpoint.setY(ttstr.toDouble()/area5string.toDouble()*qua5string.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } QString start6string, qua6string, area6string; if(checkBox6->isChecked()==true) { /*QXlsx::Document xlsx("sample.ana"); xlsx.selectSheet("Bi"); QXlsx::Worksheet *workSheet = xlsx.currentWorksheet(); qua6string = workSheet->cellAt(1, 2)->value().toString(); area6string = workSheet->cellAt(1, 3)->value().toString(); start6string = workSheet->cellAt(1, 4)->value().toString(); xlsx.deleteLater();*/ QString temperstr, ttstr, rtstr; temperstr = tlabel6->text(); ttstr = m_ttlineEdit6->text(); rtstr = m_rtlineEdit6->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); ///tmpoint.setY(ttstr.toDouble()/area6string.toDouble()*qua6string.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox7->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel7->text(); ttstr = m_ttlineEdit7->text(); rtstr = m_rtlineEdit7->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox8->isChecked()==true) { /*QXlsx::Document xlsx("sample.ana"); xlsx.selectSheet("Pb"); QXlsx::Worksheet *workSheet = xlsx.currentWorksheet(); qua8string = workSheet->cellAt(1, 2)->value().toString(); area8string = workSheet->cellAt(1, 3)->value().toString(); start8string = workSheet->cellAt(1, 4)->value().toString(); xlsx.deleteLater();*/ QString temperstr, ttstr, rtstr; temperstr = tlabel8->text(); ttstr = m_ttlineEdit8->text(); rtstr = m_rtlineEdit8->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); ///tmpoint.setY(ttstr.toDouble()/area8string.toDouble()*qua8string.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox9->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel9->text(); ttstr = m_ttlineEdit9->text(); rtstr = m_rtlineEdit9->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox10->isChecked()==true) { /*QXlsx::Document xlsx("sample.ana"); xlsx.selectSheet("Zn"); QXlsx::Worksheet *workSheet = xlsx.currentWorksheet(); qua10string = workSheet->cellAt(1, 2)->value().toString(); area10string = workSheet->cellAt(1, 3)->value().toString(); start10string = workSheet->cellAt(1, 4)->value().toString(); xlsx.deleteLater();*/ QString temperstr, ttstr, rtstr; temperstr = tlabel10->text(); ttstr = m_ttlineEdit10->text(); rtstr = m_rtlineEdit10->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); ///tmpoint.setY(ttstr.toDouble()/area10string.toDouble()*qua10string.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox11->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel11->text(); ttstr = m_ttlineEdit11->text(); rtstr = m_rtlineEdit11->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox12->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel12->text(); ttstr = m_ttlineEdit12->text(); rtstr = m_rtlineEdit12->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox13->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel13->text(); ttstr = m_ttlineEdit13->text(); rtstr = m_rtlineEdit13->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox14->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel14->text(); ttstr = m_ttlineEdit14->text(); rtstr = m_rtlineEdit14->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox15->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel15->text(); ttstr = m_ttlineEdit15->text(); rtstr = m_rtlineEdit15->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox16->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel16->text(); ttstr = m_ttlineEdit16->text(); rtstr = m_rtlineEdit16->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox17->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel17->text(); ttstr = m_ttlineEdit17->text(); rtstr = m_rtlineEdit17->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } if(checkBox18->isChecked()==true) { QString temperstr, ttstr, rtstr; temperstr = tlabel18->text(); ttstr = m_ttlineEdit18->text(); rtstr = m_rtlineEdit18->text(); QPointF tmpoint; tmpoint.setX(temperstr.toDouble()); tmpoint.setY(ttstr.toDouble()/rtstr.toDouble()); points.append(tmpoint); qDebug()<< ttstr.toDouble()<< rtstr.toDouble()<< Qt::endl; } result1 = quadraticFit(points); qDebug() << "拟合方程: y = " << result1.a << "x² + " << result1.b << "x + " << result1.c; g_result1 = result1; /*if(checkBox4->isChecked()==true) { double temper=start4string.toDouble(); thermal4 = (result1.a*temper*temper+result1.b*temper+result1.c)*area4string.toDouble()/qua4string.toDouble(); ///m_rtlineEdit4->setText(QString("%1").arg(thermal4)); } if(checkBox5->isChecked()==true) { double temper=start5string.toDouble(); thermal5 = (result1.a*temper*temper+result1.b*temper+result1.c)*area5string.toDouble()/qua5string.toDouble(); ///m_rtlineEdit5->setText(QString("%1").arg(thermal5)); } if(checkBox8->isChecked()==true) { double temper=start8string.toDouble(); thermal8 = (result1.a*temper*temper+result1.b*temper+result1.c)*area8string.toDouble()/qua8string.toDouble(); ///m_rtlineEdit8->setText(QString("%1").arg(thermal8)); } if(checkBox10->isChecked()==true) { double temper=start10string.toDouble(); thermal10 = (result1.a*temper*temper+result1.b*temper+result1.c)*area10string.toDouble()/qua10string.toDouble(); ///m_rtlineEdit10->setText(QString("%1").arg(thermal10)); }*/ } // 拟合函数:y = a*x² + b*x + c QuadraticFitResult ThermalWidget::quadraticFit(const QVector& points) { double sum_x = 0, sum_x2 = 0, sum_x3 = 0, sum_x4 = 0; double sum_y = 0, sum_xy = 0, sum_x2y = 0; for (const QPointF& p : points) { double x = p.x(); double y = p.y(); double x2 = x * x; double x3 = x2 * x; double x4 = x3 * x; sum_x += x; sum_x2 += x2; sum_x3 += x3; sum_x4 += x4; sum_y += y; sum_xy += x * y; sum_x2y += x2 * y; } double n = points.size(); double matrix[3][3] = { {sum_x4, sum_x3, sum_x2}, {sum_x3, sum_x2, sum_x}, {sum_x2, sum_x, n} }; double rhs[3] = {sum_x2y, sum_xy, sum_y}; // 高斯消元法解方程组 double coeff[3] = {}; for (int i = 0; i < 3; ++i) { // 寻找主元 int maxRow = i; for (int j = i + 1; j < 3; ++j) { if (qAbs(matrix[j][i]) > qAbs(matrix[maxRow][i])) { maxRow = j; } } // 交换行 if (maxRow != i) { for (int k = 0; k < 3; ++k) { qSwap(matrix[i][k], matrix[maxRow][k]); } qSwap(rhs[i], rhs[maxRow]); } // 消元 for (int j = i + 1; j < 3; ++j) { double factor = matrix[j][i] / matrix[i][i]; rhs[j] -= factor * rhs[i]; for (int k = i; k < 3; ++k) { matrix[j][k] -= factor * matrix[i][k]; } } } // 回代求解 for (int i = 2; i >= 0; --i) { coeff[i] = rhs[i]; for (int j = i + 1; j < 3; ++j) { coeff[i] -= matrix[i][j] * coeff[j]; } coeff[i] /= matrix[i][i]; } return {coeff[0], coeff[1], coeff[2]}; } // 使用示例 void ThermalWidget::fit_test() { // 生成带噪声的测试数据 y = 2x² + 3x + 1 ± 随机噪声 QVector points; for (int i = 0; i < 10; ++i) { double x = i; double noise = QRandomGenerator::global()->bounded(2.0); double y = 5 * x*x + 3 * x + 1 + noise; points.append(QPointF(x, y)); } // 进行二次曲线拟合 QuadraticFitResult result = quadraticFit(points); // 打印拟合结果 qDebug() << "拟合方程: y = " << result.a << "x² + " << result.b << "x + " << result.c; }