2025-04-10T15:20:55

This commit is contained in:
yuntang 2025-04-10 15:20:57 +08:00
parent 4387788970
commit ff85c72be9
8 changed files with 183 additions and 65 deletions

View File

@ -31,7 +31,7 @@ SOURCES += \
thirdparty/qcustomplot/qcustomplot.cpp \ thirdparty/qcustomplot/qcustomplot.cpp \
ui/degreeofcrystallinityform.cpp \ ui/degreeofcrystallinityform.cpp \
ui/degreeofcureform.cpp \ ui/degreeofcureform.cpp \
ui/draglinehandler.cpp \ ui/eventhandler.cpp \
ui/experimentsettingform.cpp \ ui/experimentsettingform.cpp \
ui/instrumentcoefficientform.cpp \ ui/instrumentcoefficientform.cpp \
ui/leftwidget.cpp \ ui/leftwidget.cpp \
@ -55,7 +55,7 @@ HEADERS += \
thirdparty/qcustomplot/qcustomplot.h \ thirdparty/qcustomplot/qcustomplot.h \
ui/degreeofcrystallinityform.h \ ui/degreeofcrystallinityform.h \
ui/degreeofcureform.h \ ui/degreeofcureform.h \
ui/draglinehandler.h \ ui/eventhandler.h \
ui/experimentsettingform.h \ ui/experimentsettingform.h \
ui/instrumentcoefficientform.h \ ui/instrumentcoefficientform.h \
ui/leftwidget.h \ ui/leftwidget.h \

View File

@ -39,20 +39,20 @@ CentralWidget::CentralWidget(QWidget *parent)
// 安装事件过滤器 // 安装事件过滤器
// _graph = _customPlot->addGraph(0); // _graph = _customPlot->addGraph(0);
// _eventHandler = new DragLineHandler(_customPlot, _line1, _line2, _graph, nullptr); // _eventHandler = new EventHandler(_customPlot, _line1, _line2, _graph, nullptr);
_eventHandler = new DragLineHandler(_customPlot, _line1, _line2, nullptr); _eventHandler = new EventHandler(_customPlot, _line1, _line2, nullptr);
_eventHandler->setEnable(true); _eventHandler->setEnable(true);
_customPlot->installEventFilter(_eventHandler); _customPlot->installEventFilter(_eventHandler);
_customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); _customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
connect(_eventHandler,&DragLineHandler::sigSendLineXCoord, connect(_eventHandler,&EventHandler::sigSendLineXCoord,
this,&CentralWidget::sigSendLineXCoord); this,&CentralWidget::sigSendLineXCoord);
// 连接选中信号
connect(_customPlot, &QCustomPlot::selectionChangedByUser, // connect(_customPlot, &QCustomPlot::selectionChangedByUser,
this, &CentralWidget::slotSelectionChanged); // this, &CentralWidget::slotSelectionChanged);
setEventHandlerEnable(false); setEventHandlerEnable(false);
@ -185,6 +185,7 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &fileName)
// _currentCurve->setPen(QPen(Qt::red)); // 设置线条颜色为红色 // _currentCurve->setPen(QPen(Qt::red)); // 设置线条颜色为红色
// _currentCurve->setBrush(QBrush(QColor(255, 0, 0, 20))); // 设置填充颜色并带有透明度 // _currentCurve->setBrush(QBrush(QColor(255, 0, 0, 20))); // 设置填充颜色并带有透明度
_currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选 _currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选
// _currentCurve->setSelectable(QCP::stPlottable); // 设置曲线可选
// 清除第一个图表上的数据 // 清除第一个图表上的数据
#if 0 #if 0
@ -206,6 +207,34 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &fileName)
void CentralWidget::slotSelectionChanged() void CentralWidget::slotSelectionChanged()
{ {
logde<<"selectedPlottables:"<< _customPlot->selectedPlottables().size();
logde<<"selectedGraphs:"<< _customPlot->selectedGraphs().size();
logde<<"selectedItems:"<< _customPlot->selectedItems().size();
logde<<"plottableCount:"<< _customPlot->plottableCount();
return;
for(int i = 0;i < _customPlot->plottableCount(); i++) {
QCPCurve *curve = qobject_cast<QCPCurve *>(_customPlot->plottable(i));
if(curve){
if (curve->selected()) {
logde<<"selected...";
curve->setPen(QPen(Qt::green));
_customPlot->replot();
} else {
curve->setPen(QPen(Qt::blue));
_customPlot->replot();
}
}
logde << "Current pen color:" << curve->pen().color().name().toStdString();
}
// _customPlot->replot();
// _customPlot->update();
#if 0
for (QCPAbstractPlottable *plottable : _customPlot->plottable()) { for (QCPAbstractPlottable *plottable : _customPlot->plottable()) {
QCPCurve *curve = qobject_cast<QCPCurve *>(plottable); QCPCurve *curve = qobject_cast<QCPCurve *>(plottable);
if (curve) { if (curve) {
@ -225,6 +254,8 @@ void CentralWidget::slotSelectionChanged()
} }
} }
} }
#endif
#if 0 #if 0
// 检查是否有曲线被选中 // 检查是否有曲线被选中
if (_customPlot->selectedPlottables().size() > 0) { if (_customPlot->selectedPlottables().size() > 0) {

View File

@ -7,7 +7,7 @@
#include "qcustomplot.h" #include "qcustomplot.h"
#include "protocol.h" #include "protocol.h"
#include "global.h" #include "global.h"
#include "draglinehandler.h" #include "eventhandler.h"
#include "filemanager.h" #include "filemanager.h"
class CentralWidget:public QWidget class CentralWidget:public QWidget
@ -64,7 +64,7 @@ private:
// QVector<QCPCurve *> _curveVtr; // QVector<QCPCurve *> _curveVtr;
// QCPGraph* _currentGraph; // QCPGraph* _currentGraph;
// QVector<QCPGraph*> _graphVtr; // QVector<QCPGraph*> _graphVtr;
DragLineHandler* _eventHandler; EventHandler* _eventHandler;
QCPItemStraightLine *_line1,*_line2; QCPItemStraightLine *_line1,*_line2;
QVector<FileManager::ExperimentData> _dataVtr; QVector<FileManager::ExperimentData> _dataVtr;
QVector<QCPItemStraightLine*> _lineVtr; QVector<QCPItemStraightLine*> _lineVtr;

View File

@ -1,7 +1,7 @@
#include "draglinehandler.h" #include "eventhandler.h"
#include "logger.h" #include "logger.h"
DragLineHandler::DragLineHandler(QCustomPlot *plot, EventHandler::EventHandler(QCustomPlot *plot,
QCPItemStraightLine *line1, QCPItemStraightLine *line1,
QCPItemStraightLine *line2, QCPItemStraightLine *line2,
QObject *parent) QObject *parent)
@ -14,7 +14,7 @@ DragLineHandler::DragLineHandler(QCustomPlot *plot,
} }
#if 0 #if 0
DragLineHandler::DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1, EventHandler::EventHandler(QCustomPlot *plot, QCPItemStraightLine *line1,
QCPItemStraightLine *line2, QCPGraph*graph, QCPItemStraightLine *line2, QCPGraph*graph,
QObject *parent) QObject *parent)
: QObject(parent), _plot(plot), _line1(line1), _line2(line2),_graph(graph) : QObject(parent), _plot(plot), _line1(line1), _line2(line2),_graph(graph)
@ -24,11 +24,11 @@ DragLineHandler::DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1,
} }
#endif #endif
DragLineHandler::~DragLineHandler() EventHandler::~EventHandler()
{ {
} }
bool DragLineHandler::eventFilter(QObject *obj, QEvent *event) bool EventHandler::eventFilter(QObject *obj, QEvent *event)
{ {
if(!_enableFlag){ if(!_enableFlag){
// qDebug()<<"_enableFlag false."; // qDebug()<<"_enableFlag false.";
@ -132,15 +132,18 @@ bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
} }
} }
#endif #endif
// for (QCPItem *item : _customPlot->selectedItems()) { if(_plot->selectedPlottables().size() > 0){
// if (item->selected()) { logde<<"selected...";
// } QCPCurve *curve = qobject_cast<QCPCurve *>(_plot->selectedPlottables().front());
// } if(!curve){
return QObject::eventFilter(obj, event);
}
if(_plot->selectedItems().size() > 0){
QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent *>(event); QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent *>(event);
_menu->move(contextMenuEvent->globalPos()); _menu->move(contextMenuEvent->globalPos());
_menu->show(); _menu->show();
}else{ }else{
logde<<"not selected..."; logde<<"not selected...";
} }
@ -149,7 +152,7 @@ bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
return QObject::eventFilter(obj, event); return QObject::eventFilter(obj, event);
} }
void DragLineHandler::initMenu() void EventHandler::initMenu()
{ {
_specificHeatItemAction = new QAction("比热项",_plot); _specificHeatItemAction = new QAction("比热项",_plot);
_baseLineAction = new QAction("基线",_plot); _baseLineAction = new QAction("基线",_plot);
@ -164,16 +167,58 @@ void DragLineHandler::initMenu()
specificHeatItemMenu->addAction(_sampleAction); specificHeatItemMenu->addAction(_sampleAction);
_specificHeatItemAction->setMenu(specificHeatItemMenu); _specificHeatItemAction->setMenu(specificHeatItemMenu);
connect(_baseLineAction,&QAction::triggered,
this,&EventHandler::slotBaseLine);
connect(_standardSampleAction,&QAction::triggered,
this,&EventHandler::slotStandardSample);
connect(_sampleAction,&QAction::triggered,
this,&EventHandler::slotSample);
} }
bool DragLineHandler::isNearLine(QCPItemStraightLine *line, const QPoint &pos) bool EventHandler::isNearLine(QCPItemStraightLine *line, const QPoint &pos)
{ {
double lineX = line->point1->coords().x(); double lineX = line->point1->coords().x();
int linePixelX = _plot->xAxis->coordToPixel(lineX); int linePixelX = _plot->xAxis->coordToPixel(lineX);
return qAbs(pos.x() - linePixelX) < 5; return qAbs(pos.x() - linePixelX) < 5;
} }
void DragLineHandler::updateSelectedRegion() void EventHandler::slotBaseLine()
{
logde<<"slotBaseLine...";
QCPCurve *curve = qobject_cast<QCPCurve *>(_plot->selectedPlottables().front());
if(!curve){
return;
}
curve->setPen(QPen(Qt::red));
_plot->replot();
}
void EventHandler::slotStandardSample()
{
QCPCurve *curve = qobject_cast<QCPCurve *>(_plot->selectedPlottables().front());
if(!curve){
return;
}
curve->setPen(QPen(Qt::darkGreen));
_plot->replot();
}
void EventHandler::slotSample()
{
#if 1
QCPCurve *curve = qobject_cast<QCPCurve *>(_plot->selectedPlottables().front());
if(!curve){
return;
}
curve->setPen(QPen(Qt::black));
_plot->replot();
#endif
}
void EventHandler::updateSelectedRegion()
{ {
double x1 = _line1->point1->coords().x(); double x1 = _line1->point1->coords().x();
double x2 = _line1->point1->coords().x(); double x2 = _line1->point1->coords().x();
@ -197,7 +242,7 @@ void DragLineHandler::updateSelectedRegion()
// qDebug() << "Selected region: [" << xData[index1] << ", " << xData[index2] << "]"; // qDebug() << "Selected region: [" << xData[index1] << ", " << xData[index2] << "]";
} }
int DragLineHandler::findClosestIndex(const QVector<double> &data, double target) int EventHandler::findClosestIndex(const QVector<double> &data, double target)
{ {
auto it = std::min_element(data.begin(), data.end(), [target](double a, double b) { auto it = std::min_element(data.begin(), data.end(), [target](double a, double b) {
return qAbs(a - target) < qAbs(b - target); return qAbs(a - target) < qAbs(b - target);

View File

@ -1,5 +1,5 @@
#ifndef DRAGlINEHANDLER_H #ifndef EventHandler_H
#define DRAGlINEHANDLER_H #define EventHandler_H
#include <QApplication> #include <QApplication>
#include <QMouseEvent> #include <QMouseEvent>
@ -11,17 +11,17 @@
#include "qcustomplot.h" #include "qcustomplot.h"
class DragLineHandler : public QObject class EventHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1, QCPItemStraightLine *line2, EventHandler(QCustomPlot *plot, QCPItemStraightLine *line1, QCPItemStraightLine *line2,
QObject *parent); QObject *parent);
#if 0 #if 0
DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1, QCPItemStraightLine *line2, EventHandler(QCustomPlot *plot, QCPItemStraightLine *line1, QCPItemStraightLine *line2,
QCPGraph*graph,QObject *parent); QCPGraph*graph,QObject *parent);
#endif #endif
~DragLineHandler(); ~EventHandler();
void setGraph(QCPGraph* g){ _graph = g;} void setGraph(QCPGraph* g){ _graph = g;}
void setEnable(const bool flag){_enableFlag = flag;} void setEnable(const bool flag){_enableFlag = flag;}
@ -35,11 +35,17 @@ signals:
void sigSendLineXCoord(const int,const double); void sigSendLineXCoord(const int,const double);
protected: protected:
bool eventFilter(QObject *obj, QEvent *event) override; bool eventFilter(QObject *obj, QEvent *event) override;
private slots:
void slotBaseLine();
void slotStandardSample();
void slotSample();
private: private:
void initMenu(); void initMenu();
int findClosestIndex(const QVector<double> &data, double target); int findClosestIndex(const QVector<double> &data, double target);
void updateSelectedRegion(); void updateSelectedRegion();
bool isNearLine(QCPItemStraightLine *line, const QPoint &pos); bool isNearLine(QCPItemStraightLine *line, const QPoint &pos);
private: private:
Mode _mode; Mode _mode;
bool _enableFlag; bool _enableFlag;
@ -48,7 +54,8 @@ private:
QCPItemStraightLine *_draggingLine = nullptr; QCPItemStraightLine *_draggingLine = nullptr;
QCPGraph *_graph; QCPGraph *_graph;
QMenu* _menu; QMenu* _menu;
QAction* _specificHeatItemAction,*_baseLineAction,*_standardSampleAction,*_sampleAction; QAction* _specificHeatItemAction,*_baseLineAction,
*_standardSampleAction,*_sampleAction;
}; };
#endif #endif

View File

@ -1,11 +1,44 @@
#include <QHBoxLayout>
#include <math.h>
#include "specificheatcomparisonmethodform.h" #include "specificheatcomparisonmethodform.h"
#include "ui_specificheatcomparisonmethodform.h" #include "ui_specificheatcomparisonmethodform.h"
SpecificHeatComparisonMethodForm::SpecificHeatComparisonMethodForm(QWidget *parent) : SpecificHeatComparisonMethodForm::SpecificHeatComparisonMethodForm(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::SpecificHeatComparisonMethodForm) ui(new Ui::SpecificHeatComparisonMethodForm)
{ {
ui->setupUi(this); ui->setupUi(this);
_baseLineLineEdit = new QLineEdit(ui->groupBoxDataFile);
_baseLineLabel = new QLabel(ui->groupBoxDataFile);
_baseLineLabel->setStyleSheet("background-color: red;");
_standardSampleLineEdit = new QLineEdit(ui->groupBoxDataFile);
_standardSampleLabel = new QLabel(ui->groupBoxDataFile);
_standardSampleLabel->setStyleSheet("background-color: green;");
_sampleLineEdit = new QLineEdit(ui->groupBoxDataFile);
_sampleLabel = new QLabel(ui->groupBoxDataFile);
_sampleLabel->setStyleSheet("background-color: black;");
QHBoxLayout *baseLineLayout = new QHBoxLayout;
baseLineLayout->addWidget(_baseLineLineEdit);
baseLineLayout->addWidget(_baseLineLabel);
QHBoxLayout *standardSampleLayout = new QHBoxLayout;
standardSampleLayout->addWidget(_standardSampleLineEdit);
standardSampleLayout->addWidget(_standardSampleLabel);
QHBoxLayout *sampleLayout = new QHBoxLayout;
sampleLayout->addWidget(_sampleLineEdit);
sampleLayout->addWidget(_sampleLabel);
ui->formLayoutDataFile->addRow("基线",baseLineLayout);
ui->formLayoutDataFile->addRow("标样",standardSampleLayout);
ui->formLayoutDataFile->addRow("样品",sampleLayout);
} }
SpecificHeatComparisonMethodForm::~SpecificHeatComparisonMethodForm() SpecificHeatComparisonMethodForm::~SpecificHeatComparisonMethodForm()
@ -22,3 +55,29 @@ void SpecificHeatComparisonMethodForm::on_pushButtonQuit_clicked()
{ {
hide(); hide();
} }
double calculateHeatCapacity(double theta) {
// 系数A_i
const double A0 = 1.12705;
const double A1 = 0.23260;
const double A2 = -0.21704;
const double A3 = 0.26410;
const double A4 = -0.23778;
const double A5 = -0.10023;
const double A6 = 0.15393;
const double A7 = 0.54579;
const double A8 = -0.47824;
const double A9 = -0.37623;
const double A10 = 0.34407;
// 温度转换
double T = theta + 273.15; // 摄氏温度转开尔文
double x = (T - 650.0) / 550.0; // 归一化温度变量
// 计算比热容
double Cp = A0 + A1 * x + A2 * std::pow(x, 2) + A3 * std::pow(x, 3) + A4 * std::pow(x, 4) +
A5 * std::pow(x, 5) + A6 * std::pow(x, 6) + A7 * std::pow(x, 7) + A8 * std::pow(x, 8) +
A9 * std::pow(x, 9) + A10 * std::pow(x, 10);
return Cp;
}

View File

@ -2,6 +2,8 @@
#define SPECIFICHEATCOMPARISONMETHODFORM_H #define SPECIFICHEATCOMPARISONMETHODFORM_H
#include <QWidget> #include <QWidget>
#include <QLineEdit>
#include <QLabel>
namespace Ui { namespace Ui {
class SpecificHeatComparisonMethodForm; class SpecificHeatComparisonMethodForm;
@ -19,9 +21,14 @@ private slots:
void on_pushButtonCalculate_clicked(); void on_pushButtonCalculate_clicked();
void on_pushButtonQuit_clicked(); void on_pushButtonQuit_clicked();
private:
double calculateHeatCapacity(double theta);
private: private:
Ui::SpecificHeatComparisonMethodForm *ui; Ui::SpecificHeatComparisonMethodForm *ui;
QLineEdit *_baseLineLineEdit,*_standardSampleLineEdit,
*_sampleLineEdit;
QLabel *_baseLineLabel,*_standardSampleLabel,*_sampleLabel;
}; };
#endif // SPECIFICHEATCOMPARISONMETHODFORM_H #endif // SPECIFICHEATCOMPARISONMETHODFORM_H

View File

@ -63,7 +63,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBoxDataFile">
<property name="title"> <property name="title">
<string>数据文件</string> <string>数据文件</string>
</property> </property>
@ -76,38 +76,7 @@
<height>81</height> <height>81</height>
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout_2"> <layout class="QFormLayout" name="formLayoutDataFile"/>
<item row="0" column="0">
<widget class="QLabel" name="LabelBaseLine">
<property name="text">
<string>基线</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="LineEdit_3"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="LabelGuideSample">
<property name="text">
<string>标样</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="LineEdit_4"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="LabelSample">
<property name="text">
<string>样品</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="LineEdit_5"/>
</item>
</layout>
</widget> </widget>
</widget> </widget>
</item> </item>