Skip to content

Commit

Permalink
完善界面逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
JackeyLea committed Nov 1, 2024
1 parent 7ec7991 commit 18dcefb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
31 changes: 31 additions & 0 deletions MindViewer/dataparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ DataParser::DataParser()
,m_total(0)
,m_loss(0)
,m_rawCnt(0)
,m_eType(None)
,m_bSave(false)
{
//初始化数据
mBuff.clear();
Expand All @@ -18,6 +20,13 @@ DataParser::DataParser()

DataParser::~DataParser()
{
if(!m_bSave){
if(file.isOpen()){
file.remove();
}
}
file.close();

if(m_comRetriver){
m_comRetriver->stopCOM();
m_comRetriver->deleteLater();
Expand All @@ -29,17 +38,25 @@ DataParser::~DataParser()
}
}

void DataParser::saveLocalFile()
{
file.close();
m_bSave = true;
}

void DataParser::setFilePath(QString path)
{
m_filePath = path;
}

void DataParser::setSource(DataSourceType type)
{
m_eType = type;
switch(type){
case None:
break;
case COM:
{
if(!m_comRetriver){
m_comRetriver = new Retriver(NULL);
}
Expand All @@ -52,8 +69,16 @@ void DataParser::setSource(DataSourceType type)
if(m_lf){
m_lf->disconnect();
}
//本地文件
QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss")+".txt";
QFile file(fileName);
if(!file.open(QFile::WriteOnly)){
qDebug()<<"Cannot open local file.";
}
break;
}
case Sim:
{
if(!m_sim){
m_sim = new Simulator();
}
Expand All @@ -66,7 +91,9 @@ void DataParser::setSource(DataSourceType type)
m_comRetriver->disconnect();
}
break;
}
case Local:
{
if(!m_lf){
m_lf = new LocalFile(m_filePath);
}
Expand All @@ -81,6 +108,7 @@ void DataParser::setSource(DataSourceType type)
}
break;
}
}
}

void DataParser::clearBuff()
Expand Down Expand Up @@ -377,6 +405,9 @@ void DataParser::run()
//收到数据后填充至缓存区等待解析
void DataParser::sltRcvData(QByteArray ba)
{
if(file.isOpen()){
file.write(ba);
}
m_mutex.lock();
mBuff.append(ba);
m_mutex.unlock();
Expand Down
6 changes: 6 additions & 0 deletions MindViewer/dataparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class DataParser : public QThread
DataParser();
~DataParser();

void saveLocalFile();

void setFilePath(QString path);

void setSource(DataSourceType type);
Expand Down Expand Up @@ -70,6 +72,10 @@ private slots:
QMutex m_mutex;

QString m_filePath;

DataSourceType m_eType;//当前数据源类型
QFile file;
bool m_bSave;
};

#endif // DATAPARSER_H
24 changes: 24 additions & 0 deletions MindViewer/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,39 @@ void MainWidget::sltBtnLocal()

void MainWidget::sltBtnPlay()
{
if(m_eType == None){
QMessageBox::warning(this,tr("警告"),tr("请先选择数据源"));
return;
}
if(m_bStatus){
QMessageBox::warning(this,tr("警告"),tr("当前处于运行状态"));
return;
}
m_bStatus = true;
ui->labelStatusValue->setText("运行");
sltBtnClear();
}

void MainWidget::sltBtnPause()
{
if(m_eType == None){
QMessageBox::warning(this,tr("警告"),tr("请先选择数据源"));
return;
}
if(!m_bStatus){
QMessageBox::warning(this,tr("警告"),tr("当前处于暂停状态"));
return;
}
m_bStatus = false;
ui->labelStatusValue->setText("暂停");
}

void MainWidget::sltBtnClear()
{
if(m_eType == None){
QMessageBox::warning(this,tr("警告"),tr("当前无数据可清理"));
return;
}
//清空界面
ui->labelPowerValue->setText("0");
ui->labelSignalValue->setText("0");
Expand All @@ -108,6 +128,10 @@ void MainWidget::sltBtnClear()

void MainWidget::sltBtnSave()
{
if(m_eType == None){
QMessageBox::warning(this,tr("警告"),tr("当前无数据可保存"));
return;
}
switch(m_eType){
case COM:
break;
Expand Down
12 changes: 12 additions & 0 deletions MindViewer/mainwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ QFrame#frameCurve{
<height>64</height>
</size>
</property>
<property name="statusTip">
<string>运行</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -151,6 +154,9 @@ QFrame#frameCurve{
<height>64</height>
</size>
</property>
<property name="statusTip">
<string>暂停</string>
</property>
<property name="text">
<string/>
</property>
Expand Down Expand Up @@ -184,6 +190,9 @@ QFrame#frameCurve{
<property name="toolTip">
<string>清空数据</string>
</property>
<property name="statusTip">
<string>清空缓存</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -210,6 +219,9 @@ QFrame#frameCurve{
<property name="toolTip">
<string>保存数据</string>
</property>
<property name="statusTip">
<string>保存数据</string>
</property>
<property name="text">
<string/>
</property>
Expand Down

0 comments on commit 18dcefb

Please sign in to comment.