2025-04-09T17:30:31

This commit is contained in:
yuntang 2025-04-09 17:30:32 +08:00
parent 6cf14dfce7
commit ba28c29ec8
9 changed files with 3943 additions and 34 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -370,7 +370,8 @@ QPointF PointCalculate::getIntersectionBySlope(const LineStruct& line1, const Li
}
QPointF PointCalculate::getClosestPointByX(const float targetX)
{
#if 0
#if 1
QPointF resultPointF;
float minDiff = std::numeric_limits<float>::max();
for(FileManager::ExperimentData &ed:_dataVtr){
@ -380,8 +381,11 @@ QPointF PointCalculate::getClosestPointByX(const float targetX)
resultPointF = QPointF(ed.sampleTemp,ed.dsc);
}
}
return resultPointF;
#endif
#if 0
int left = 0;
int right = _dataVtr.size() - 1;
@ -408,6 +412,7 @@ QPointF PointCalculate::getClosestPointByX(const float targetX)
}
return resultPointF;
#endif
}
QString PointCalculate::textFormatNumbericalLabel(const QPointF point)
@ -469,7 +474,7 @@ QString PointCalculate::textFormatGlassTranstion(const float t1,const float tg,c
{
return QString("T1%1℃\n"
"Tg%2℃\n"
"T2%3℃\n"
"T2%3℃"
).arg(QString::number(t1, 'f', 3))
.arg(QString::number(tg, 'f', 3))
.arg(QString::number(t2, 'f', 3));

View File

@ -196,13 +196,13 @@ void MainWindow::on_actionNumericalLabel_triggered()
void MainWindow::on_actionPeakSynthesisAnalysis_triggered()
{
//峰综合分析
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::PeakSynthesisAnalysis);
}
void MainWindow::on_actionClearAllData_triggered()
{
_rightWidget->hide();
_centralWidget->clearAllData();
}

View File

@ -38,9 +38,15 @@ CentralWidget::CentralWidget(QWidget *parent)
_line2->setSelectable(true);
// 安装事件过滤器
_graph = _customPlot->addGraph(0);
_eventHandler = new DragLineHandler(_customPlot, _line1, _line2, _graph, nullptr);
// _graph = _customPlot->addGraph(0);
// _eventHandler = new DragLineHandler(_customPlot, _line1, _line2, _graph, nullptr);
_eventHandler = new DragLineHandler(_customPlot, _line1, _line2, nullptr);
_eventHandler->setEnable(true);
_customPlot->installEventFilter(_eventHandler);
_customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
connect(_eventHandler,&DragLineHandler::sigSendLineXCoord,
this,&CentralWidget::sigSendLineXCoord);
@ -94,11 +100,13 @@ void CentralWidget::slotModeModify(const Global::Mode mode)
{
if (Global::Mode::ExperimentStart == mode)
{
if (_customPlot->graphCount() > 0 && _graph)
#if 0
if (_customPlot->graphCount() > 0 && _currentGraph)
{
// 清除第一个图表上的数据
_graph->setData(QVector<double>(), QVector<double>());
_currentGraph->setData(QVector<double>(), QVector<double>());
}
#endif
// 创建画布,设置画布上的点数据
// _graph = _customPlot->addGraph();
@ -133,7 +141,7 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &fileName)
qDebug() << "slotRecvAnalysisFileName" << fileName;
//
clearData(ClearDataMode::All);
// clearData(ClearDataMode::All);
//
_dataVtr.clear();
FileManager::readExperimentFile(fileName, _dataVtr);
@ -159,22 +167,36 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &fileName)
_customPlot->yAxis->setLabel("DSC/mW");
_customPlot->xAxis->setLabel("Temp/℃");
QVector<double> xVtr, yVtr;
QVector<double> tVtr,xVtr, yVtr;
int index = 0;
for (FileManager::ExperimentData &ed : _dataVtr)
{
tVtr.push_back(index++);
xVtr.push_back(ed.sampleTemp);
yVtr.push_back(ed.dsc);
}
_currentCurve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis);
_currentCurve->setData(tVtr, xVtr, yVtr);
// _currentCurve->setPen(QPen(Qt::red)); // 设置线条颜色为红色
// _currentCurve->setBrush(QBrush(QColor(255, 0, 0, 20))); // 设置填充颜色并带有透明度
_currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选
// 清除第一个图表上的数据
#if 0
if (_customPlot->graphCount() > 0 && _graph)
{
// 清除第一个图表上的数据
_graph->setData(QVector<double>(), QVector<double>());
}
#endif
_graph->addData(xVtr, yVtr);
#if 0
_currentGraph = _customPlot->addGraph();
_graphVtr.push_back(_currentGraph);
_currentGraph->addData(xVtr, yVtr);
#endif
_customPlot->replot();
}
@ -321,7 +343,7 @@ void CentralWidget::glassTransitionHandle()
logde<<"point1:"<<point1.x()<<","<<point1.y();
logde<<"point2:"<<point2.x()<<","<<point2.y();
#if 1
#if 0
QCPItemStraightLine *line1 = new QCPItemStraightLine(_customPlot);
line1->point1->setCoords(point1.x() - 5,point1.y());
line1->point2->setCoords(point1.x() + 5,point1.y());
@ -371,9 +393,9 @@ void CentralWidget::glassTransitionHandle()
<<",Tg:"<<averagePoint.x()
<<",T2:"<<intersection2.x();
QString str = PointCalculate::textFormatGlassTranstion(intersection1.x(),
QString str = PointCalculate::textFormatGlassTranstion(intersection2.x(),
averagePoint.x(),
intersection2.x());
intersection1.x());
drawText(averagePoint,str);
#if 0
@ -390,7 +412,7 @@ void CentralWidget::glassTransitionHandle()
circle->setPen(QPen(Qt::blue));
#endif
#if 1
#if 0
QCPItemStraightLine *line3 = new QCPItemStraightLine(_customPlot);
line3->point1->setCoords(averagePoint.x() + 1,averagePoint.y() + 1);
line3->point2->setCoords(averagePoint.x() - 1,averagePoint.y() - 1);
@ -413,7 +435,7 @@ void CentralWidget::setEventHandlerEnable(const bool flag)
};
// todo. 当竖线隐藏时,需要设置不可选择模式。
_eventHandler->setEnable(flag);
// _eventHandler->setEnable(flag);
#if 1
// move line to suitable position.
@ -480,8 +502,10 @@ void CentralWidget::fillGraph(const double x1, const double x2)
// 样式配置
mainGraph->setPen(QPen(Qt::red, 1));
_graph->setBrush(QBrush(Qt::lightGray));
_graph->setChannelFillGraph(mainGraph);
#if 0
_currentGraph->setBrush(QBrush(Qt::lightGray));
_currentGraph->setChannelFillGraph(mainGraph);
#endif
// customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));
// _customPlot->graph(1);
@ -492,26 +516,32 @@ void CentralWidget::clearData(const CentralWidget::ClearDataMode mode)
{
if(mode == ClearDataMode::All){
// Clear the data of graph.
if (_customPlot->graphCount() > 0 && _graph)
#if 0
if (_customPlot->graphCount() > 0 && _currentGraph)
{
_graph->setData(QVector<double>(), QVector<double>());
_currentGraph->setData(QVector<double>(), QVector<double>());
}
#endif
// Set lines visiable false.
_line1->setVisible(false);
_line2->setVisible(false);
}
#if 0
// Clear filled area.
_graph->setBrush(QBrush(Qt::transparent));
if(_currentGraph){
_currentGraph->setBrush(QBrush(Qt::transparent));
}
// Clear graph on plot.
for (int i = _customPlot->graphCount() - 1; i >= 0; --i) {
QCPGraph *graph = _customPlot->graph(i);
if (graph != _graph) {
if (graph != _currentGraph) {
_customPlot->removeGraph(graph);
}
}
#endif
// Delete items.
QList<QCPAbstractItem *> itemsToKeep;
itemsToKeep << _line1 << _line2;

View File

@ -59,7 +59,10 @@ private:
private:
AnalysisMode _analysisMode;
QCustomPlot *_customPlot;
QCPGraph* _graph;
QCPCurve *_currentCurve;
// QVector<QCPCurve *> _curveVtr;
// QCPGraph* _currentGraph;
// QVector<QCPGraph*> _graphVtr;
DragLineHandler* _eventHandler;
QCPItemStraightLine *_line1,*_line2;
QVector<FileManager::ExperimentData> _dataVtr;

View File

@ -1,5 +1,19 @@
#include "draglinehandler.h"
#include "logger.h"
DragLineHandler::DragLineHandler(QCustomPlot *plot,
QCPItemStraightLine *line1,
QCPItemStraightLine *line2,
QObject *parent)
: QObject(parent), _plot(plot), _line1(line1), _line2(line2)
,_enableFlag(false),_mode(Mode::SelectTwoLines),_menu(new QMenu(_plot))
{
_plot->setInteractions(QCP::iSelectItems);
initMenu();
}
#if 0
DragLineHandler::DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1,
QCPItemStraightLine *line2, QCPGraph*graph,
QObject *parent)
@ -8,6 +22,7 @@ DragLineHandler::DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1,
{
_plot->setInteractions(QCP::iSelectItems);
}
#endif
DragLineHandler::~DragLineHandler()
{
@ -17,6 +32,7 @@ bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
{
if(!_enableFlag){
// qDebug()<<"_enableFlag false.";
logde<<"eventFilter false.";
#if 0
if(mPlot){
mPlot->setCursor(Qt::ArrowCursor);
@ -66,20 +82,37 @@ bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
{
// qDebug()<<"mouse press...";
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::LeftButton)
{
QPoint mousePos = mouseEvent->pos();
if (isNearLine(_line1, mousePos))
if(Mode::SelectTwoLines == _mode){
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::LeftButton)
{
_draggingLine = _line1;
_line1->setSelected(true);
QPoint mousePos = mouseEvent->pos();
if (isNearLine(_line1, mousePos))
{
_draggingLine = _line1;
_line1->setSelected(true);
}
else if (isNearLine(_line2, mousePos))
{
_draggingLine = _line2;
_line2->setSelected(true);
}
}
else if (isNearLine(_line2, mousePos))
}else{
#if 0
// 检查是否有选中的曲线
if (event->button() == Qt::LeftButton && selectedPlottables().size() > 0)
{
_draggingLine = _line2;
_line2->setSelected(true);
// 获取选中的曲线
QCPCurve *selectedCurve = qobject_cast<QCPCurve*>(selectedPlottables().first());
if (selectedCurve)
{
// 改变曲线的颜色
selectedCurve->setPen(QPen(Qt::green)); // 设置线条颜色为绿色
replot(); // 重新绘制
}
}
#endif
}
}
else if (event->type() == QEvent::MouseButtonRelease)
@ -89,11 +122,50 @@ bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
_draggingLine->setSelected(false);
_draggingLine = nullptr;
}
}else if (event->type() == QEvent::ContextMenu) {
logde<<"context menu...";
#if 0
for (QCPAbstractPlottable *plottable : _plot->plottables()) {
if (plottable->selected()) {
std::cout << "选中的曲线: " << plottable->name().toStdString() << std::endl;
}
}
#endif
// for (QCPItem *item : _customPlot->selectedItems()) {
// if (item->selected()) {
// }
// }
if(_plot->selectedItems().size() > 0){
QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent *>(event);
_menu->move(contextMenuEvent->globalPos());
_menu->show();
}else{
logde<<"not selected...";
}
}
}
return QObject::eventFilter(obj, event);
}
void DragLineHandler::initMenu()
{
_specificHeatItemAction = new QAction("比热项",_plot);
_baseLineAction = new QAction("基线",_plot);
_standardSampleAction = new QAction("标样",_plot);
_sampleAction = new QAction("样品",_plot);
_menu->addAction(_specificHeatItemAction);
QMenu *specificHeatItemMenu = new QMenu(_plot);
specificHeatItemMenu->addAction(_baseLineAction);
specificHeatItemMenu->addAction(_standardSampleAction);
specificHeatItemMenu->addAction(_sampleAction);
_specificHeatItemAction->setMenu(specificHeatItemMenu);
}
bool DragLineHandler::isNearLine(QCPItemStraightLine *line, const QPoint &pos)
{
double lineX = line->point1->coords().x();

View File

@ -7,6 +7,7 @@
#include <QPixmap>
#include <QLabel>
#include <QCursor>
#include <QMenu>
#include "qcustomplot.h"
@ -14,26 +15,40 @@ class DragLineHandler : public QObject
{
Q_OBJECT
public:
DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1, QCPItemStraightLine *line2,
QObject *parent);
#if 0
DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1, QCPItemStraightLine *line2,
QCPGraph*graph,QObject *parent);
#endif
~DragLineHandler();
void setGraph(QCPGraph* g){ _graph = g;}
void setEnable(const bool flag){_enableFlag = flag;}
enum Mode{
Null,
SelectCurve,
SelectTwoLines
};
void setMode(const Mode mode){ _mode = mode;}
signals:
void sigSendLineXCoord(const int,const double);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
void initMenu();
int findClosestIndex(const QVector<double> &data, double target);
void updateSelectedRegion();
bool isNearLine(QCPItemStraightLine *line, const QPoint &pos);
private:
Mode _mode;
bool _enableFlag;
QCustomPlot *_plot;
QCPItemStraightLine *_line1,*_line2;
QCPItemStraightLine *_draggingLine = nullptr;
QCPGraph *_graph;
QMenu* _menu;
QAction* _specificHeatItemAction,*_baseLineAction,*_standardSampleAction,*_sampleAction;
};
#endif