2025-04-23T17:25:37

This commit is contained in:
yuntang 2025-04-23 17:25:38 +08:00
parent 12d4c03b3d
commit dbe0281c24
4 changed files with 83 additions and 44 deletions

Binary file not shown.

View File

@ -80,6 +80,8 @@ void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet, int &startLineIndex
// skip.第一段
startLineIndex++;
logde<<"startLineIndex:"<<startLineIndex;
phaseTotal.phase.cutoff_temp = workSheet->cellAt(startLineIndex++, 2)->value().toDouble();
phaseTotal.phase.temp_flow = workSheet->cellAt(startLineIndex++, 2)->value().toDouble();
phaseTotal.phase.constant_temp_time_min = (uint16_t)(workSheet->cellAt(startLineIndex++, 2)->value().toInt());
@ -111,11 +113,20 @@ void XlsxHandler::writeFile(const QString filePath)
xlsx.write(row++ , 1, ConFileDataInfo);
xlsx.write(row , 1, ConSampleName);
xlsx.write(row , 2, ei.sampleName);
QString sampleName = ei.sampleName;
if(sampleName.isEmpty()){
sampleName = "sample";
}
xlsx.write(row , 2, sampleName);
row++;
xlsx.write(row , 1, ConSampleWeight);
xlsx.write(row , 2, ei.sampleWeight);
QString sampleWeight = ei.sampleWeight;
if(sampleWeight.isEmpty()){
sampleWeight = "1";
}
xlsx.write(row , 2, sampleWeight);
xlsx.write(row , 3, ConUnitMg);
row++;
@ -125,26 +136,45 @@ void XlsxHandler::writeFile(const QString filePath)
row++;
xlsx.write(row , 1, Conexperimenter);
xlsx.write(row , 2, ei.experimentor);
QString experimentor = ei.experimentor;
if(experimentor.isEmpty()){
experimentor = "experimentor";
}
xlsx.write(row , 2, experimentor);
row++;
xlsx.write(row , 1, ConDate);
xlsx.write(row , 2, ei.date);
QString date = ei.date;
if(date.isEmpty()){
date = "20250101";
}
xlsx.write(row , 2, date);
row++;
xlsx.write(row , 1, ConMeasureType);
xlsx.write(row , 2, "样品");
row++;
int phaseSizeRow = row;
int phaseCount = 0;
xlsx.write(row , 1, ConPhaseSize);
xlsx.write(row , 2, ei.phaseVtr.size());
row++;
// Write phase data.
int dataSizeRow = 0;
logde<<"phase vtr size:"<<ei.phaseVtr.size();
for(int i = 0; i < ei.phaseVtr.size();i++){
logde<<"phase index:"<<i;
const Phase& phase = ei.phaseVtr.at(i);
if(phase.onoff == 0){
logde<<"onoff == 0.";
continue;
}
phaseCount++;
xlsx.write(row , 1, ConPhaseProfix);
xlsx.write(row , 2, ConPhaseHeaderTime);
xlsx.write(row , 3, ConPhaseHeaderTemp);
@ -203,44 +233,22 @@ void XlsxHandler::writeFile(const QString filePath)
xlsx.write(row , 1, index);
xlsx.write(row , 2, ed.runTime);
xlsx.write(row , 3, ed.constantTempTime);
xlsx.write(row , 4, ed.sampleTemp);
xlsx.write(row , 5, ed.dsc);
xlsx.write(row , 3, ed.sampleTemp);
xlsx.write(row , 4, ed.dsc);
xlsx.write(row , 5, ed.constantTempTime);
row++;
}
}
//
xlsx.write(phaseSizeRow , 1, ConPhaseSize);
xlsx.write(phaseSizeRow , 2, phaseCount);
//
logde<<"before xlsx save as...";
if (!xlsx.saveAs(filePath)) {
logde<<"Save xlsx failed.";
return ;
}
#if 0
// 创建一个新的 Excel 文档
QXlsx::Document xlsx;
// 检查数据是否为空
if (data.isEmpty()) {
qWarning() << "没有数据可写入";
return ;
}
// 遍历数据并写入单元格
for (int row = 0; row < data.size(); ++row) {
const QVector<QString>& rowData = data[row];
for (int col = 0; col < rowData.size(); ++col) {
QString cellValue = rowData[col];
xlsx.write(row + 1, col + 1, cellValue); // 行和列从1开始
}
}
// 保存文件
if (!xlsx.saveAs(filePath)) {
qWarning() << "无法保存文件:" << filePath;
return ;
}
qDebug() << "文件保存成功:" << filePath;
return ;
#endif
}

View File

@ -48,9 +48,9 @@ CentralWidget::CentralWidget(QWidget *parent)
_eventHandler->setEnable(true);
_customPlot->installEventFilter(_eventHandler);
// _customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
_customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
// _customPlot->setInteractions( QCP::iRangeZoom | QCP::iSelectPlottables);
_customPlot->setInteractions(QCP::iSelectPlottables);
// _customPlot->setInteractions(QCP::iSelectPlottables);
connect(_eventHandler,&EventHandler::sigSendLineXCoord,
this,&CentralWidget::sigSendLineXCoord);
@ -91,6 +91,8 @@ CentralWidget::~CentralWidget()
void CentralWidget::setAnalysisMode(const CentralWidget::AnalysisMode mode)
{
_customPlot->setInteractions(QCP::iSelectPlottables);
_analysisMode = mode;
switch (mode)
@ -252,6 +254,7 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &filePath)
Global::_curveExperimentDataVtr.push_back({_currentCurve,fileInfo.fileName(),pti.dataVtr});
}
_customPlot->rescaleAxes();
_customPlot->replot();
}
@ -821,15 +824,24 @@ void CentralWidget::setEventHandlerEnable(const bool flag)
#if 1
// move line to suitable position.
double xMax = _customPlot->xAxis->range().upper; // X 轴的最大值
double xMax = _customPlot->xAxis->range().upper;
double xMin = _customPlot->xAxis->range().lower;
logde<<"xMax:"<<xMax;
_line1->point1->setCoords(xMax / 3,_line1->point1->coords().y());
_line1->point2->setCoords(xMax / 3,_line1->point2->coords().y());
QVector<double> ticks = _customPlot->xAxis->tickVector();
int numTicks = ticks.size();
logde<<"ticks:"<<numTicks;
_line2->point1->setCoords(xMax / 3 * 2,_line2->point1->coords().y());
_line2->point2->setCoords(xMax / 3 * 2,_line2->point2->coords().y());
double range = xMax - xMin;
double xLeft = xMin + range / 3;
double xRight = xMin + range * 2 / 3;
_line1->point1->setCoords(xLeft,_line1->point1->coords().y());
_line1->point2->setCoords(xLeft,_line1->point2->coords().y());
_line2->point1->setCoords(xRight,_line2->point1->coords().y());
_line2->point2->setCoords(xRight,_line2->point2->coords().y());
#endif
lineVisiableFunc(_line1);
if(AnalysisMode::NumericalLabel != _analysisMode){
@ -839,13 +851,32 @@ void CentralWidget::setEventHandlerEnable(const bool flag)
_customPlot->replot();
}
QPointF CentralWidget::getTheCoordinatesOfTheTextBox(const QPointF point)
{
double xMax = _customPlot->xAxis->range().upper;
double xMin = _customPlot->xAxis->range().lower;
logde<<"xMax:"<<xMax;
QVector<double> ticks = _customPlot->xAxis->tickVector();
int numTicks = ticks.size();
logde<<"ticks:"<<numTicks;
double distance = (xMax - xMin) / ticks.size();
return QPointF(point.x() + distance,point.y());
}
void CentralWidget::drawText(const QPointF point, const QString text)
{
QPointF textBoxPoint = getTheCoordinatesOfTheTextBox(point);
// 创建标注文字QCPItemText
QCPItemText *textLabel = new QCPItemText(_customPlot);
textLabel->setPositionAlignment(Qt::AlignBottom | Qt::AlignHCenter); // 对齐方式
textLabel->position->setType(QCPItemPosition::ptPlotCoords); // 使用数据坐标
textLabel->position->setCoords(point.x() + 20, point.y()); // 设置文本位置在指定点上方
textLabel->position->setCoords(textBoxPoint.x(),textBoxPoint.y()); // 设置文本位置在指定点上方
textLabel->setText(text); // 设置文本内容
// textLabel->setFont(QFont("Arial", 10));

View File

@ -60,8 +60,8 @@ private:
double derivativeAt(const double a, const double b, const double x);
PointCalculate::Line calculateLinearRegression(const QVector<double>& x, const QVector<double>& y);
void setEventHandlerEnable(const bool);
QPointF getTheCoordinatesOfTheTextBox(const QPointF point);
void drawText(const QPointF,const QString);
void fillGraph(const double x1,const double x2);