2025-03-21T17:28:35

This commit is contained in:
yuntang 2025-03-21 17:28:36 +08:00
parent 0cc7c09f15
commit b9d1470a6d
16 changed files with 335 additions and 40 deletions

View File

@ -18,6 +18,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
data/filemanager.cpp \
global.cpp \
rightwidget.cpp \
ui/analysissettingform.cpp \
ui/centralwidget.cpp \
main.cpp \
mainwindow.cpp \
@ -33,6 +35,8 @@ HEADERS += \
data/filemanager.h \
defines.h \
global.h \
rightwidget.h \
ui/analysissettingform.h \
ui/centralwidget.h \
mainwindow.h \
serialport/dataparser.h \

View File

@ -60,7 +60,7 @@ void test()
writeExperimentFile(cd);
}
void fileClose()
void close()
{
if(_expeFile.isOpen()){
_expeFile.close();

View File

@ -29,7 +29,7 @@ extern QFile _expeFile;
void createExperimentFile();
void writeExperimentFile(const CommonData&);
void fileClose();
void close();
void readExperimentFile(const QString fileName,QVector<ExperimentData>&);

View File

@ -8,16 +8,25 @@
#include "filemanager.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), _centralWidget(new CentralWidget), _leftWidget(new LeftWidget), _expertmentSettingForm(new ExperimentSettingForm), _realTimeDataForm(new RealTimeDataForm)
: QMainWindow(parent),
ui(new Ui::MainWindow),
_centralWidget(new CentralWidget(this)),
_leftWidget(new LeftWidget(this)),
_expertmentSettingForm(new ExperimentSettingForm(this)),
_realTimeDataForm(new RealTimeDataForm(this)),
_rightWidget(new QDockWidget(this))
,_analysisSettingWidget(new AnalysisSettingForm(this))
,_contextMenu(new QMenu(this))
{
ui->setupUi(this);
setActionEnable(false);
this->setToolTip(".....");
setCentralWidget(_centralWidget);
addDockWidget(Qt::LeftDockWidgetArea, _leftWidget);
addDockWidget(Qt::RightDockWidgetArea, _rightWidget);
_rightWidget->setWidget(_analysisSettingWidget);
_rightWidget->hide();
//
ui->statusbar->showMessage("showMessage show temp message!");
// permenent show
@ -27,12 +36,31 @@ MainWindow::MainWindow(QWidget *parent)
//
connections();
//
_realTimeDataForm->show();
_expertmentSettingForm->setWindowFlags(_expertmentSettingForm->windowFlags()| Qt::Dialog);
_realTimeDataForm->setWindowFlags(_realTimeDataForm->windowFlags()| Qt::Dialog);
// _realTimeDataForm->show();
setActionEnable(true);
}
MainWindow::~MainWindow()
{
// 删除非QObject派生类的对象
// 假设 Ui::MainWindow 不是 QObject 派生类
delete ui;
// 清理 status bar如果它不是通过 new 创建的,则不需要删除
if (_statusBar) {
delete _statusBar;
}
FileManager::close();
}
void MainWindow::slotContextMenuShow(const QPoint point)
{
_contextMenu->exec(point);
}
void MainWindow::connections()
@ -61,6 +89,13 @@ void MainWindow::connections()
//analysis
connect(_leftWidget,&LeftWidget::sigSendAnalysisFileName,
_centralWidget,&CentralWidget::slotRecvAnalysisFileName);
connect(_centralWidget,&CentralWidget::sigSendLineXCoord,
_analysisSettingWidget,&AnalysisSettingForm::slotRecvLineXCoord);
connect(_analysisSettingWidget,&AnalysisSettingForm::sigApply,
_centralWidget,&CentralWidget::slotAnalysisSettingApply);
connect(_analysisSettingWidget,&AnalysisSettingForm::sigConfirm,
_centralWidget,&CentralWidget::slotAnalysisSettingConfirm);
}
void MainWindow::setActionEnable(const bool flag)
@ -87,7 +122,7 @@ void MainWindow::on_actionStop_triggered()
SerialPort::instance()->slotSendData(ba);
// SerialPort::instance()->slotCloseSp();
FileManager::fileClose();
FileManager::close();
}
void MainWindow::on_actionNew_triggered()
@ -146,5 +181,6 @@ void MainWindow::on_actionStopPoint_triggered()
void MainWindow::on_actionNumericalLabel_triggered()
{
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::NumericalLabel);
}

View File

@ -3,12 +3,15 @@
#include <QMainWindow>
#include <QStatusBar>
#include <QDockWidget>
#include "centralwidget.h"
#include "leftwidget.h"
#include "experimentsettingform.h"
#include "realtimedataform.h"
#include "dataparser.h"
#include "rightwidget.h"
#include "analysissettingform.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -21,13 +24,21 @@ class MainWindow : public QMainWindow
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
public slots:
void slotContextMenuShow(const QPoint);
private slots:
//experiment
void on_actionConnectToDev_triggered();
void on_actionNew_triggered();
void on_actionStart_triggered();
void on_actionStop_triggered();
void on_actionReadOnly_triggered();
void on_actionRealTimeWidget_triggered();
//analysis
void on_actionNumericalLabel_triggered();
void on_actionStartPoint_triggered();
void on_actionStopPoint_triggered();
private:
void connections();
void setActionEnable(const bool);
@ -35,8 +46,11 @@ private:
Ui::MainWindow *ui;
CentralWidget *_centralWidget;
LeftWidget*_leftWidget;
QDockWidget* _rightWidget;
ExperimentSettingForm *_expertmentSettingForm;
RealTimeDataForm* _realTimeDataForm;
QStatusBar *_statusBar;
QMenu* _contextMenu;
AnalysisSettingForm* _analysisSettingWidget;
};
#endif // MAINWINDOW_H

View File

@ -44,6 +44,9 @@
<property name="title">
<string>分析</string>
</property>
<addaction name="actionNumericalLabel"/>
<addaction name="actionStartPoint"/>
<addaction name="actionStopPoint"/>
</widget>
<widget class="QMenu" name="menu_5">
<property name="title">
@ -148,6 +151,21 @@
<string>连接设备</string>
</property>
</action>
<action name="actionStartPoint">
<property name="text">
<string>起始点</string>
</property>
</action>
<action name="actionStopPoint">
<property name="text">
<string>终止点</string>
</property>
</action>
<action name="actionNumericalLabel">
<property name="text">
<string>数值标记</string>
</property>
</action>
</widget>
<resources>
<include location="images.qrc"/>

7
src/rightwidget.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "rightwidget.h"
RightWidget::RightWidget(QWidget *parent) : QDockWidget(parent)
,_analysisSettingForm(new AnalysisSettingForm(this))
{
setWidget(_analysisSettingForm);
}

20
src/rightwidget.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef RIGHTWIDGET_H
#define RIGHTWIDGET_H
#include <QDockWidget>
#include "analysissettingform.h"
class RightWidget : public QDockWidget
{
Q_OBJECT
public:
explicit RightWidget(QWidget *parent = nullptr);
signals:
private:
AnalysisSettingForm *_analysisSettingForm;
};
#endif // RIGHTWIDGET_H

View File

@ -0,0 +1,93 @@
#include <QFormLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include "analysissettingform.h"
AnalysisSettingForm::AnalysisSettingForm(QWidget *parent) :
QWidget(parent)
,_leftBorderSpinBox(new QDoubleSpinBox(this))
,_rightBorderSpinBox(new QDoubleSpinBox(this))
,_thresholdLineEdit(new QLineEdit(this))
,_applyButton(new QPushButton("应用",this))
,_undoButton(new QPushButton("撤销",this))
,_confirmButton(new QPushButton("确定",this))
,_cancelButton(new QPushButton("取消",this))
{
QVBoxLayout *layout = new QVBoxLayout(this);
// 设置间距和边距
// layout->setSpacing(0); // 设置子布局之间的间距
// layout->setContentsMargins(0, 0, 0, 0); // 设置布局的边距
QFormLayout *editLayout = new QFormLayout();
editLayout->addRow("左边界:",_leftBorderSpinBox);
editLayout->addRow("有边界:",_rightBorderSpinBox);
editLayout->addRow("阈值:",_thresholdLineEdit);
QGridLayout *buttonLayout = new QGridLayout();
buttonLayout->addWidget(_applyButton, 0, 0); // 第一行第一列
buttonLayout->addWidget(_undoButton, 0, 1); // 第一行第二列
buttonLayout->addWidget(_confirmButton, 1, 0); // 第二行第一列
buttonLayout->addWidget(_cancelButton, 1, 1); // 第二行第二列
// buttonLayout->setSpacing(0);
// 创建一个空白行
QSpacerItem *spacer =
new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
// 将 editLayout 和 buttonLayout 添加到主布局,并在它们之间添加空白行
layout->addLayout(editLayout);
layout->addSpacerItem(spacer);
layout->addLayout(buttonLayout);
layout->addLayout(editLayout);
// layout->setSpacing(1);
layout->addLayout(buttonLayout);
layout->addStretch(1);
//
connect(_applyButton,&QPushButton::click,
this,&AnalysisSettingForm::slotApply);
connect(_confirmButton,&QPushButton::click,
this,&AnalysisSettingForm::slotConfirm);
connect(_undoButton,&QPushButton::click,
this,&AnalysisSettingForm::slotUndo);
connect(_cancelButton,&QPushButton::click,
this,&AnalysisSettingForm::slotCancel);
//
_leftBorderSpinBox->setRange(0.0, 10000.0); // 设置范围
_rightBorderSpinBox->setRange(0.0, 10000.0); // 设置范围
}
AnalysisSettingForm::~AnalysisSettingForm()
{
}
void AnalysisSettingForm::slotRecvLineXCoord(const int index, const double point)
{
if(1 == index){
_leftBorderSpinBox->setValue(point);
}else{
_rightBorderSpinBox->setValue(point);
}
}
void AnalysisSettingForm::slotApply()
{
}
void AnalysisSettingForm::slotConfirm()
{
}
void AnalysisSettingForm::slotUndo()
{
}
void AnalysisSettingForm::slotCancel()
{
}

View File

@ -0,0 +1,35 @@
#ifndef ANALYSISSETTINGFORM_H
#define ANALYSISSETTINGFORM_H
#include <QWidget>
#include <QDoubleSpinBox>
#include <QLineEdit>
#include <QPushButton>
class AnalysisSettingForm : public QWidget
{
Q_OBJECT
public:
explicit AnalysisSettingForm(QWidget *parent = nullptr);
~AnalysisSettingForm();
signals:
void sigApply();
void sigConfirm();
public slots:
void slotRecvLineXCoord(const int,const double);
private slots:
void slotApply();
void slotConfirm();
void slotUndo();
void slotCancel();
private:
QDoubleSpinBox *_leftBorderSpinBox,*_rightBorderSpinBox;
QLineEdit *_thresholdLineEdit;
QPushButton *_applyButton,
*_confirmButton,
*_undoButton,
*_cancelButton;
};
#endif // ANALYSISSETTINGFORM_H

View File

@ -7,11 +7,15 @@
CentralWidget::CentralWidget(QWidget *parent)
: QWidget(parent),
_customPlot(new QCustomPlot)
,_nanlysisMode(AnalysisMode::None)
{
setMouseTracking(true);
setStyleSheet("background-color: lightgray;");
resize(888, 666);
QHBoxLayout *layout = new QHBoxLayout();
layout->setMargin(0);
layout->addWidget(_customPlot);
this->setLayout(layout);
@ -29,9 +33,15 @@ CentralWidget::CentralWidget(QWidget *parent)
_line2->setSelectable(true);
// 安装事件过滤器
_eventHandler = new DragLineHandler(_customPlot, _line1, _line2, _graph,nullptr);
_graph = _customPlot->addGraph(0);
_eventHandler = new DragLineHandler(_customPlot, _line1, _line2, _graph, nullptr);
_customPlot->installEventFilter(_eventHandler);
connect(_eventHandler,&DragLineHandler::sigSendLineXCoord,
this,&CentralWidget::sigSendLineXCoord);
setEventHandlerEnable(false);
//
#if 0
// init data
QVector<double> x(101), y(101);
@ -54,12 +64,28 @@ CentralWidget::CentralWidget(QWidget *parent)
CentralWidget::~CentralWidget()
{
FileManager::fileClose();
FileManager::close();
}
void CentralWidget::setAnalysisMode(const CentralWidget::AnalysisMode)
void CentralWidget::setAnalysisMode(const CentralWidget::AnalysisMode mode)
{
if(_nanlysisMode == mode){
return;
}else{
_nanlysisMode = mode;
}
switch (mode)
{
case AnalysisMode::NumericalLabel:
setEventHandlerEnable(true);
break;
case AnalysisMode::None:
setEventHandlerEnable(false);
break;
default:
break;
}
}
void CentralWidget::slotModeModify(const Global::Mode mode)
@ -78,14 +104,15 @@ void CentralWidget::slotModeModify(const Global::Mode mode)
}
else if (Global::Mode::Analysis == mode)
{
qDebug()<<"file close...";
FileManager::fileClose();
qDebug() << "file close...";
FileManager::close();
}
}
void CentralWidget::slotRecvCommonData(const CommonData &cd)
{
qDebug()<<"slotRevCommonData";
qDebug() << "slotRevCommonData";
_customPlot->graph(0)->addData(cd.sample_temp, cd.dsc); // 添加数据到曲线
_customPlot->replot();
//
@ -94,19 +121,23 @@ void CentralWidget::slotRecvCommonData(const CommonData &cd)
void CentralWidget::slotRecvAnalysisFileName(const QString &fileName)
{
qDebug()<<"slotRecvAnalysisFileName"<<fileName;
qDebug() << "slotRecvAnalysisFileName" << fileName;
QVector<FileManager::ExperimentData> dataVtr;
FileManager::readExperimentFile(fileName,dataVtr);
FileManager::readExperimentFile(fileName, dataVtr);
if(dataVtr.size() < 0){
if (dataVtr.size() < 0)
{
return;
}
#if 0
//判断界面上是不是有曲线,有的话先删除。
_customPlot->clearGraphs();
// 创建画布,设置画布上的点数据
_customPlot->addGraph();
#endif
// 设置坐标轴标签
_customPlot->yAxis->setLabel("DSC/mW");
@ -115,16 +146,34 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &fileName)
_customPlot->xAxis->setRange(0, 400);
_customPlot->yAxis->setRange(-20, 20);
QVector<double> xVtr,yVtr;
for(FileManager::ExperimentData &ed:dataVtr){
QVector<double> xVtr, yVtr;
for (FileManager::ExperimentData &ed : dataVtr)
{
xVtr.push_back(ed.sampleTemp);
yVtr.push_back(ed.dsc);
}
_customPlot->graph(0)->addData(xVtr,yVtr);
// 清除第一个图表上的数据
if (_customPlot->graphCount() > 0 && _graph)
{
// 清除第一个图表上的数据
_graph->setData(QVector<double>(), QVector<double>());
}
_graph->addData(xVtr, yVtr);
_customPlot->replot();
}
void CentralWidget::slotAnalysisSettingApply()
{
}
void CentralWidget::slotAnalysisSettingConfirm()
{
}
void CentralWidget::timerEvent(QTimerEvent *event)
{
// key的单位是秒
@ -151,22 +200,19 @@ void CentralWidget::timerEvent(QTimerEvent *event)
_customPlot->replot();
}
void CentralWidget::analysisMode(const bool flag)
void CentralWidget::contextMenuEvent(QContextMenuEvent *event)
{
_line1->setVisible(flag);
_line2->setVisible(flag);
_eventHandler->setEnable(flag);
#if 0
if(flag){
_line1->setVisible(true);
_line2->setVisible(true);
_eventHandler->setEnable(true);
}else{
_line1->setVisible(true);
_line2->setVisible(true);
_eventHandler->setEnable(true);
}
#endif
qDebug()<<"left menu...";
QPoint point = event->globalPos();
emit sigContextMenuShow(point);
}
void CentralWidget::setEventHandlerEnable(const bool flag)
{
_eventHandler->setEnable(flag);
_line1->setVisible(flag);
if(AnalysisMode::NumericalLabel != _nanlysisMode){
_line2->setVisible(flag);
}
_customPlot->replot();
}

View File

@ -2,6 +2,7 @@
#define CENTRALWIDGET_H
#include <QWidget>
#include <QMenu>
#include "qcustomplot.h"
#include "protocol.h"
@ -22,16 +23,24 @@ public:
~CentralWidget();
void setAnalysisMode(const AnalysisMode);
signals:
void sigContextMenuShow(const QPoint);
void sigSendLineXCoord(const int,const double);
public slots:
void slotModeModify(const Global::Mode);
void slotRecvCommonData(const CommonData&);
void slotRecvAnalysisFileName(const QString&);
//analysis setting
void slotAnalysisSettingApply();
void slotAnalysisSettingConfirm();
protected:
void timerEvent(QTimerEvent* event);
void contextMenuEvent(QContextMenuEvent *event);
private:
void analysisMode(const bool);
void setEventHandlerEnable(const bool);
private:
AnalysisMode _nanlysisMode;
QCustomPlot *_customPlot;
QCPGraph* _graph;
DragLineHandler* _eventHandler;

View File

@ -12,12 +12,16 @@ DragLineHandler::DragLineHandler(QCustomPlot *plot, QCPItemStraightLine *line1,
bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
{
if(!_enableFlag){
qDebug()<<"_enableFlag false.";
return false;
}
if (obj == mPlot)
{
if (event->type() == QEvent::MouseMove)
{
qDebug()<<"mouse move...";
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
QPoint mousePos = mouseEvent->pos();
qDebug()<<"x:"<<mousePos.x();
@ -41,6 +45,11 @@ bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
if (mDraggingLine)
{
double x = mPlot->xAxis->pixelToCoord(mousePos.x());
if(mDraggingLine == mLine1){
emit sigSendLineXCoord(1,x);
}else{
emit sigSendLineXCoord(2,x);
}
mDraggingLine->point1->setCoords(x, mPlot->yAxis->range().lower);
mDraggingLine->point2->setCoords(x, mPlot->yAxis->range().upper);
mPlot->replot();
@ -49,6 +58,8 @@ bool DragLineHandler::eventFilter(QObject *obj, QEvent *event)
}
else if (event->type() == QEvent::MouseButtonPress)
{
qDebug()<<"mouse press...";
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::LeftButton)
{

View File

@ -18,6 +18,8 @@ public:
QCPGraph*graph,QObject *parent);
void setEnable(const bool flag){_enableFlag = flag;}
signals:
void sigSendLineXCoord(const int,const double);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:

View File

@ -6,7 +6,7 @@
#include "filemanager.h"
#include "global.h"
LeftWidget::LeftWidget()
LeftWidget::LeftWidget(QWidget *parent ): QDockWidget(parent)
{
// setStyleSheet("background-color: yellow;");

View File

@ -10,7 +10,7 @@ class LeftWidget:public QDockWidget
{
Q_OBJECT
public:
LeftWidget();
LeftWidget(QWidget *parent = nullptr);
private:
void initData();
void initFileName(QTreeWidgetItem*,const QString &folderPath);