From d64d48f0e65073138a9940d578183d991f9ea645 Mon Sep 17 00:00:00 2001 From: yuntang <123@qq.com> Date: Sun, 27 Apr 2025 15:27:07 +0800 Subject: [PATCH] 2025-04-27T15:27:06 --- src/mainwindow.cpp | 3 +++ src/ui/centralwidget.cpp | 22 ++++++++++++++++++++++ src/ui/centralwidget.h | 13 ++++++++----- src/ui/degreeofcrystallinityform.cpp | 9 +++++++-- src/ui/degreeofcrystallinityform.h | 3 ++- src/ui/degreeofcureform.cpp | 4 +++- src/ui/degreeofcureform.h | 1 + src/ui/localcustomplot.cpp | 5 +++++ 8 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 868185e..6e56e1c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -145,6 +145,9 @@ void MainWindow::connections() connect(_centralWidget,&CentralWidget::sigRightDockWidgetHide, [&](){ _rightWidget->hide(); }); + connect(_degreeOfCrystallinityForm,&DegreeOfCrystallinityForm::sigDrawCustomText, + _centralWidget,&CentralWidget::slotDrawCustomText); + //SpecificHeatComparisonMethodForm connect(_eventHandler,&EventHandler::sigSetCurve, _specificHeatComparisonMethodForm, diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index 985392b..f2f66e0 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -360,6 +360,28 @@ void CentralWidget::slotAnalysisSettingLineXPoint(const int index, const double) } +void CentralWidget::slotDrawCustomText(const QString str) +{ + QCPItemText* customLegendItem = new QCPItemText(_customPlot); + customLegendItem->position->setTypeX(QCPItemPosition::ptAbsolute); + customLegendItem->position->setTypeY(QCPItemPosition::ptAbsolute); + customLegendItem->position->setCoords(150, 50); // 稍微向下移动 + customLegendItem->setText(str); + + QFont font("Arial", 10); + customLegendItem->setFont(font); + + // 设置边框和背景 + customLegendItem->setPen(QPen(Qt::black)); + customLegendItem->setBrush(QBrush(Qt::white)); + + // 禁止点选 + customLegendItem->setSelectable(false); + customLegendItem->setObjectName("fixed"); + + _customPlot->replot(); +} + void CentralWidget::timerEvent(QTimerEvent *event) { _customPlot->replot(); diff --git a/src/ui/centralwidget.h b/src/ui/centralwidget.h index d2c437f..691cf7b 100644 --- a/src/ui/centralwidget.h +++ b/src/ui/centralwidget.h @@ -51,6 +51,8 @@ public slots: void slotAnalysisSettingCancel(); void slotAnalysisSettingLineXPoint(const int index,const double); + + void slotDrawCustomText(const QString); protected: void timerEvent(QTimerEvent* event); void contextMenuEvent(QContextMenuEvent *event); @@ -67,6 +69,7 @@ private: void drawText(const QPointF,const QString); void fillGraph(const double x1,const double x2); + enum ClearDataMode{ All, Undo @@ -75,14 +78,14 @@ private: private: AnalysisMode _analysisMode; LocalCustomPlot *_customPlot; -// QCustomPlot*_customPlot; + // QCustomPlot*_customPlot; QCPCurve *_currentCurve; -// QVector _curveVtr; -// QCPGraph* _currentGraph; -// QVector _graphVtr; + // QVector _curveVtr; + // QCPGraph* _currentGraph; + // QVector _graphVtr; EventHandler* _eventHandler; QCPItemStraightLine *_line1,*_line2; -// QVector _dataVtr; + // QVector _dataVtr; QVector _lineVtr; }; diff --git a/src/ui/degreeofcrystallinityform.cpp b/src/ui/degreeofcrystallinityform.cpp index 10f91b1..3b2a4d6 100644 --- a/src/ui/degreeofcrystallinityform.cpp +++ b/src/ui/degreeofcrystallinityform.cpp @@ -6,6 +6,7 @@ DegreeOfCrystallinityForm::DegreeOfCrystallinityForm(QWidget *parent) : ui(new Ui::DegreeOfCrystallinityForm) { ui->setupUi(this); + setWindowTitle("结晶度"); } DegreeOfCrystallinityForm::~DegreeOfCrystallinityForm() @@ -18,9 +19,13 @@ void DegreeOfCrystallinityForm::on_pushButtonCalculate_clicked() float enthalpy = ui->LineEditEnthalpyOfCrystallization->text().toFloat(); float enthalpyCold = ui->LineEditEnthalpyOfColdCrystallization->text().toFloat(); float enthalpyTheory = ui->LineEditTheoreticalEnthalpy->text().toFloat(); - float Xc = (enthalpy - enthalpyCold) / enthalpyTheory / 100; + float Xc = (enthalpy - enthalpyCold) / enthalpyTheory * 100; - ui->xcLineEditDegreedOfCrystallinity->setText(QString::number(Xc,'f',3)); + QString xcStr = QString::number(Xc,'f',3); + ui->xcLineEditDegreedOfCrystallinity->setText(xcStr); + + QString str = QString("结晶度Xc(%)= %1%").arg(xcStr); + emit sigDrawCustomText(str); } void DegreeOfCrystallinityForm::on_pushButtonQuit_clicked() diff --git a/src/ui/degreeofcrystallinityform.h b/src/ui/degreeofcrystallinityform.h index d61576d..6f1f499 100644 --- a/src/ui/degreeofcrystallinityform.h +++ b/src/ui/degreeofcrystallinityform.h @@ -14,7 +14,8 @@ class DegreeOfCrystallinityForm : public QWidget public: explicit DegreeOfCrystallinityForm(QWidget *parent = nullptr); ~DegreeOfCrystallinityForm(); - +signals: + void sigDrawCustomText(const QString); private slots: void on_pushButtonCalculate_clicked(); diff --git a/src/ui/degreeofcureform.cpp b/src/ui/degreeofcureform.cpp index a7944dc..830e72d 100644 --- a/src/ui/degreeofcureform.cpp +++ b/src/ui/degreeofcureform.cpp @@ -6,6 +6,8 @@ DegreeOfCureForm::DegreeOfCureForm(QWidget *parent) : ui(new Ui::DegreeOfCureForm) { ui->setupUi(this); + + setWindowTitle("固化度"); } DegreeOfCureForm::~DegreeOfCureForm() @@ -18,7 +20,7 @@ void DegreeOfCureForm::on_pushButtonCalculate_clicked() float precure = ui->LineEditPrecure->text().toFloat(); float afterCuring = ui->jGLineEditAfterCuring->text().toFloat(); - float degree = (precure - afterCuring)/afterCuring/100; + float degree = (precure - afterCuring)/afterCuring * 100; ui->LineEditDegreeOfCure->setText(QString::number(degree,'f',3)); } diff --git a/src/ui/degreeofcureform.h b/src/ui/degreeofcureform.h index cd1cc8d..c6b0df7 100644 --- a/src/ui/degreeofcureform.h +++ b/src/ui/degreeofcureform.h @@ -15,6 +15,7 @@ public: explicit DegreeOfCureForm(QWidget *parent = nullptr); ~DegreeOfCureForm(); + private slots: void on_pushButtonCalculate_clicked(); diff --git a/src/ui/localcustomplot.cpp b/src/ui/localcustomplot.cpp index ef750a9..1574394 100644 --- a/src/ui/localcustomplot.cpp +++ b/src/ui/localcustomplot.cpp @@ -19,6 +19,11 @@ void LocalCustomPlot::mousePressEvent(QMouseEvent *event) { if (QCPItemText* textItem = qobject_cast(item(i))) { +#if 1 + if(textItem->objectName() == "fixed"){ + continue; + } +#endif QRectF rect = getTextBoundingRect(textItem); if(rect.contains(event->pos())) {