From 51732f394c89b40bcb9151ce64f9595fa48aa5f3 Mon Sep 17 00:00:00 2001 From: yuntang <123@qq.com> Date: Tue, 29 Apr 2025 17:29:14 +0800 Subject: [PATCH] 2025-04-29T17:29:14 --- experiment_data/sample_data/~$锡.xlsx | Bin 165 -> 0 bytes src/AnalysisTool.pro | 3 + src/global.cpp | 7 ++ src/global.h | 2 + src/mainwindow.cpp | 17 +++- src/mainwindow.h | 4 + src/mainwindow.ui | 12 +++ src/ui/axissettingform.cpp | 75 ++++++++++++++++ src/ui/axissettingform.h | 35 ++++++++ src/ui/axissettingform.ui | 123 ++++++++++++++++++++++++++ src/ui/centralwidget.cpp | 57 ++++++++++-- src/ui/centralwidget.h | 11 +++ 12 files changed, 335 insertions(+), 11 deletions(-) delete mode 100644 experiment_data/sample_data/~$锡.xlsx create mode 100644 src/ui/axissettingform.cpp create mode 100644 src/ui/axissettingform.h create mode 100644 src/ui/axissettingform.ui diff --git a/experiment_data/sample_data/~$锡.xlsx b/experiment_data/sample_data/~$锡.xlsx deleted file mode 100644 index d4a5841882f71e1e9259c5c320e2b84832515279..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 165 ZcmZQhOiETD9WXN_G9)o1Gbqpn0s!Zc4-)_Y diff --git a/src/AnalysisTool.pro b/src/AnalysisTool.pro index 1f1094f..97bd6e8 100644 --- a/src/AnalysisTool.pro +++ b/src/AnalysisTool.pro @@ -28,6 +28,7 @@ SOURCES += \ global.cpp \ logger/logger.cpp \ ui/aboutform.cpp \ + ui/axissettingform.cpp \ ui/coefficientselectionform.cpp \ ui/enthalpydatacorrectionform.cpp \ ui/localcustomplot.cpp \ @@ -61,6 +62,7 @@ HEADERS += \ defines.h \ logger/logger.h \ ui/aboutform.h \ + ui/axissettingform.h \ ui/coefficientselectionform.h \ ui/enthalpydatacorrectionform.h \ ui/localcustomplot.h \ @@ -88,6 +90,7 @@ HEADERS += \ FORMS += \ mainwindow.ui \ ui/aboutform.ui \ + ui/axissettingform.ui \ ui/coefficientselectionform.ui \ ui/degreeofcrystallinityform.ui \ ui/degreeofcureform.ui \ diff --git a/src/global.cpp b/src/global.cpp index fc41244..3ecb336 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -12,6 +12,13 @@ CurveExperimentData* _currentCurveExperimentDataPtr = nullptr; bool _enthalpyCoefficientEnableFlag = false; QVector _enthalpyCoefficientVtr; + +QString converDoubleToStr(const double num) +{ + return QString::number(num,'f',3); +} + + } #if 0 diff --git a/src/global.h b/src/global.h index 6016f11..934f71a 100644 --- a/src/global.h +++ b/src/global.h @@ -90,6 +90,8 @@ extern bool _enthalpyCoefficientEnableFlag; ///abc extern QVector _enthalpyCoefficientVtr; +// common func +QString converDoubleToStr(const double); } #if 0 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0b6b406..0b2811d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -28,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) ,_enthalpyDataCorrectionForm(new EnthalpyDataCorrectionForm(this)) ,_coefficientSelectionForm(new CoefficientSelectionForm(this)) ,_printPreviewForm(new PrintPreviewForm(this)) + ,_axisSettingForm(new AxisSettingForm(this)) { ui->setupUi(this); this->setToolTip("....."); @@ -56,6 +57,8 @@ MainWindow::MainWindow(QWidget *parent) setSubWidgetAttribute(_enthalpyDataCorrectionForm); setSubWidgetAttribute(_coefficientSelectionForm); setSubWidgetAttribute(_printPreviewForm); + setSubWidgetAttribute(_axisSettingForm); + // setActionEnable(true); @@ -69,8 +72,6 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { - // 删除非QObject派生类的对象 - // 假设 Ui::MainWindow 不是 QObject 派生类 delete ui; } @@ -155,6 +156,13 @@ void MainWindow::connections() _specificHeatComparisonMethodForm, &SpecificHeatComparisonMethodForm::slotSetCurve); + // Axis settings. + connect(_axisSettingForm,&AxisSettingForm::sigGetAxisInfo, + _centralWidget,&CentralWidget::slotGetAxisInfo); + connect(_centralWidget,&CentralWidget::sigGetAxisInfoWithData, + _axisSettingForm,&AxisSettingForm::slotGetAxisInfoWithData); + connect(_axisSettingForm,&AxisSettingForm::sigSetAxisSettings, + _centralWidget,&CentralWidget::slotSetAxisSettings); } void MainWindow::setActionEnable(const bool flag) @@ -394,3 +402,8 @@ void MainWindow::on_actionYAxis_triggered() { _centralWidget->switchAxisMode(); } + +void MainWindow::on_actionAxisSetting_triggered() +{ + _axisSettingForm->show(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 46279d3..5b91844 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -5,6 +5,7 @@ #include #include +#include "axissettingform.h" #include "printpreviewform.h" #include "centralwidget.h" #include "leftwidget.h" @@ -89,6 +90,8 @@ private slots: void on_actionYAxis_triggered(); + void on_actionAxisSetting_triggered(); + private: void connections(); void setActionEnable(const bool); @@ -113,5 +116,6 @@ private: EnthalpyDataCorrectionForm* _enthalpyDataCorrectionForm; CoefficientSelectionForm * _coefficientSelectionForm; PrintPreviewForm *_printPreviewForm; + AxisSettingForm * _axisSettingForm; }; #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 1c31be1..088578e 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -84,9 +84,16 @@ + + + 设置 + + + + @@ -297,6 +304,11 @@ Y轴 + + + 坐标轴设置 + + diff --git a/src/ui/axissettingform.cpp b/src/ui/axissettingform.cpp new file mode 100644 index 0000000..0489027 --- /dev/null +++ b/src/ui/axissettingform.cpp @@ -0,0 +1,75 @@ +#include "axissettingform.h" +#include "ui_axissettingform.h" +#include "global.h" + +AxisSettingForm::AxisSettingForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::AxisSettingForm) +{ + ui->setupUi(this); + + +} + +AxisSettingForm::~AxisSettingForm() +{ + delete ui; +} + +void AxisSettingForm::slotGetAxisInfoWithData(const QVector vtr) +{ + ui->lineEditXMin->setText(Global::converDoubleToStr(vtr.first().lower)); + ui->lineEditXMax->setText(Global::converDoubleToStr(vtr.first().upper)); + + ui->lineEditYLeftMin->setText(Global::converDoubleToStr(vtr.at(1).lower)); + ui->lineEditYLeftMax->setText(Global::converDoubleToStr(vtr.at(1).upper)); + + //Axis Y right. + ui->lineEditYRightMin->setEnabled(vtr.last().visiable); + ui->lineEditYRightMax->setEnabled(vtr.last().visiable); + + if(vtr.last().visiable){ + ui->lineEditYRightMin->setText(Global::converDoubleToStr(vtr.last().lower)); + ui->lineEditYRightMax->setText(Global::converDoubleToStr(vtr.last().upper)); + }else{ + ui->lineEditYRightMin->setText(0); + ui->lineEditYRightMax->setText(0); + } +} + +void AxisSettingForm::showEvent(QShowEvent *event) +{ + emit sigGetAxisInfo(); + QWidget::showEvent(event); +} + +void AxisSettingForm::on_pushButtonConfirm_clicked() +{ + QVector vtr; + +#if 0 + double xMin = ui->lineEditXMin->text().toDouble(); + double xMax = ui->lineEditXMin->text().toDouble(); + double yLeftMin = ui->lineEditYLeftMin->text().toDouble(); + double yLeftMax = ui->lineEditYLeftMax->text().toDouble(); + + double yRightMin = ui->lineEditYRightMin->text().toDouble(); + double yRightMax = ui->lineEditYRightMax->text().toDouble(); +#endif + + vtr.push_back(ui->lineEditXMin->text().toDouble()); + vtr.push_back(ui->lineEditXMax->text().toDouble()); + + vtr.push_back(ui->lineEditYLeftMin->text().toDouble()); + vtr.push_back(ui->lineEditYLeftMax->text().toDouble()); + + vtr.push_back(ui->lineEditYRightMin->text().toDouble()); + vtr.push_back(ui->lineEditYRightMax->text().toDouble()); + + emit sigSetAxisSettings(vtr); +} + +void AxisSettingForm::on_pushButtonCancel_clicked() +{ + hide(); +} diff --git a/src/ui/axissettingform.h b/src/ui/axissettingform.h new file mode 100644 index 0000000..529a4af --- /dev/null +++ b/src/ui/axissettingform.h @@ -0,0 +1,35 @@ +#ifndef AXISSETTINGFORM_H +#define AXISSETTINGFORM_H + +#include +#include "centralwidget.h" + +namespace Ui { +class AxisSettingForm; +} + +class AxisSettingForm : public QWidget +{ + Q_OBJECT + +public: + explicit AxisSettingForm(QWidget *parent = nullptr); + ~AxisSettingForm(); + +signals: + void sigSetAxisSettings(const QVector); + void sigGetAxisInfo(); +public slots: + void slotGetAxisInfoWithData(const QVector); +protected: + void showEvent(QShowEvent *event) override; +private slots: + void on_pushButtonConfirm_clicked(); + + void on_pushButtonCancel_clicked(); + +private: + Ui::AxisSettingForm *ui; +}; + +#endif // AXISSETTINGFORM_H diff --git a/src/ui/axissettingform.ui b/src/ui/axissettingform.ui new file mode 100644 index 0000000..59c65d5 --- /dev/null +++ b/src/ui/axissettingform.ui @@ -0,0 +1,123 @@ + + + AxisSettingForm + + + + 0 + 0 + 387 + 163 + + + + Form + + + + + 20 + 10 + 351 + 111 + + + + + + + + + + + + + + + + + + + 坐标轴 + + + + + + + 最大值 + + + Qt::AlignCenter + + + + + + + + + + 最小值 + + + Qt::AlignCenter + + + + + + + + + + X + + + + + + + Y 左侧 + + + + + + + Y 右侧 + + + + + + + + + 170 + 130 + 80 + 20 + + + + 应用 + + + + + + 270 + 130 + 80 + 20 + + + + 关闭 + + + + + + diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index be47f78..a71245c 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -126,20 +126,25 @@ void CentralWidget::switchAxisMode() QCPCurve* curve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis2); curve->setData(tVtr, xVtr, yVtr); - + curve->setPen(QPen(QColor(Qt::red))); curve->setObjectName(Global::CurveOfTimeTypeObjectName); + + // logde<<"plottableCount count:"<<_customPlot->plottableCount(); } } - }else{ _axisMode = AxisMode::SingleY; _customPlot->yAxis2->setVisible(false); - for (int i = _customPlot->graphCount() - 1; i >= 0; --i) { - QCPGraph *graph = _customPlot->graph(i); - if(graph && graph->objectName() == Global::CurveOfTimeTypeObjectName){ - _customPlot->removeGraph(graph); + // logde<<"graph count:"<<_customPlot->plottableCount(); + + for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { + QCPAbstractPlottable* plottable = _customPlot->plottable(i); + if (auto curve = dynamic_cast(plottable)) { + if(curve && curve->objectName() == Global::CurveOfTimeTypeObjectName){ + _customPlot->removePlottable(curve); + } } } } @@ -235,9 +240,11 @@ void CentralWidget::slotRecvCommonData(const CommonData &cd) void CentralWidget::slotRecvAnalysisFileName(const QString &filePath) { - qDebug() << "slotRecvAnalysisFileName" << filePath; + if(_analysisFilePathVtr.contains(filePath)){ + return; + } - // todo.禁止重复文件添加。 + qDebug() << "slotRecvAnalysisFileName" << filePath; Global::CurveFileData cfd; if(XlsxHandler::readFile(filePath,cfd) != 0){ @@ -439,6 +446,38 @@ void CentralWidget::slotDrawCustomText(const QString str) _customPlot->replot(); } +void CentralWidget::slotGetAxisInfo() +{ + QVector vtr; + + auto func = [&](QCPAxis* axis){ + AxisInfo ai; + ai.visiable = axis->visible(); + ai.lower = axis->range().lower; + ai.upper = axis->range().upper; + + vtr.push_back(ai); + }; + + func(_customPlot->xAxis); + func(_customPlot->yAxis); + func(_customPlot->yAxis2); + + emit sigGetAxisInfoWithData(vtr); +} + +void CentralWidget::slotSetAxisSettings(const QVectorvtr) +{ + _customPlot->xAxis->setRange(vtr.at(0),vtr.at(1)); + _customPlot->yAxis->setRange(vtr.at(2),vtr.at(3)); + + if(_customPlot->yAxis2->visible()){ + _customPlot->yAxis2->setRange(vtr.at(4),vtr.at(5)); + } + + _customPlot->replot(); +} + void CentralWidget::timerEvent(QTimerEvent *event) { _customPlot->replot(); @@ -952,7 +991,7 @@ void CentralWidget::clearData(const CentralWidget::ClearDataMode mode) _line2->setVisible(false); } -#if 1 +#if 0 // Clear graph on plot. for (int i = _customPlot->graphCount() - 1; i >= 0; --i) { QCPGraph *graph = _customPlot->graph(i); diff --git a/src/ui/centralwidget.h b/src/ui/centralwidget.h index 01cc380..f90d050 100644 --- a/src/ui/centralwidget.h +++ b/src/ui/centralwidget.h @@ -41,10 +41,17 @@ public: DoubleY }; void switchAxisMode(); + struct AxisInfo{ + bool visiable; + double lower; + double upper; + }; signals: void sigContextMenuShow(const QPoint); void sigSendLineXCoord(const int,const double); void sigRightDockWidgetHide(); + + void sigGetAxisInfoWithData(const QVector); public slots: // experiment void slotAxisModify(const float temp); @@ -61,6 +68,9 @@ public slots: void slotAnalysisSettingLineXPoint(const int index,const double); void slotDrawCustomText(const QString); + // + void slotGetAxisInfo(); + void slotSetAxisSettings(const QVector); protected: void timerEvent(QTimerEvent* event); void contextMenuEvent(QContextMenuEvent *event); @@ -95,6 +105,7 @@ private: // QVector _dataVtr; QVector _lineVtr; AxisMode _axisMode; + QVector _analysisFilePathVtr; }; #endif // CENTRALWIDGET_H