diff --git a/experiment_data/sample_data/new.xlsx b/experiment_data/sample_data/new.xlsx index 259bed6..0c573b0 100644 Binary files a/experiment_data/sample_data/new.xlsx and b/experiment_data/sample_data/new.xlsx differ diff --git a/src/data/xlsxhandler.cpp b/src/data/xlsxhandler.cpp index 3ee25ca..6f28d70 100644 --- a/src/data/xlsxhandler.cpp +++ b/src/data/xlsxhandler.cpp @@ -80,6 +80,8 @@ void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet, int &startLineIndex // skip.第一段 startLineIndex++; + logde<<"startLineIndex:"<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:"<& 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 } diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index dfc0149..ebe468d 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -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:"<point1->setCoords(xMax / 3,_line1->point1->coords().y()); - _line1->point2->setCoords(xMax / 3,_line1->point2->coords().y()); + QVector ticks = _customPlot->xAxis->tickVector(); + int numTicks = ticks.size(); + logde<<"ticks:"<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:"< ticks = _customPlot->xAxis->tickVector(); + int numTicks = ticks.size(); + logde<<"ticks:"<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)); diff --git a/src/ui/centralwidget.h b/src/ui/centralwidget.h index e4ea755..d389433 100644 --- a/src/ui/centralwidget.h +++ b/src/ui/centralwidget.h @@ -60,8 +60,8 @@ private: double derivativeAt(const double a, const double b, const double x); PointCalculate::Line calculateLinearRegression(const QVector& x, const QVector& y); - void setEventHandlerEnable(const bool); + QPointF getTheCoordinatesOfTheTextBox(const QPointF point); void drawText(const QPointF,const QString); void fillGraph(const double x1,const double x2);