Skip to content

Commit 18dcefb

Browse files
committed
完善界面逻辑
1 parent 7ec7991 commit 18dcefb

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

MindViewer/dataparser.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ DataParser::DataParser()
99
,m_total(0)
1010
,m_loss(0)
1111
,m_rawCnt(0)
12+
,m_eType(None)
13+
,m_bSave(false)
1214
{
1315
//初始化数据
1416
mBuff.clear();
@@ -18,6 +20,13 @@ DataParser::DataParser()
1820

1921
DataParser::~DataParser()
2022
{
23+
if(!m_bSave){
24+
if(file.isOpen()){
25+
file.remove();
26+
}
27+
}
28+
file.close();
29+
2130
if(m_comRetriver){
2231
m_comRetriver->stopCOM();
2332
m_comRetriver->deleteLater();
@@ -29,17 +38,25 @@ DataParser::~DataParser()
2938
}
3039
}
3140

41+
void DataParser::saveLocalFile()
42+
{
43+
file.close();
44+
m_bSave = true;
45+
}
46+
3247
void DataParser::setFilePath(QString path)
3348
{
3449
m_filePath = path;
3550
}
3651

3752
void DataParser::setSource(DataSourceType type)
3853
{
54+
m_eType = type;
3955
switch(type){
4056
case None:
4157
break;
4258
case COM:
59+
{
4360
if(!m_comRetriver){
4461
m_comRetriver = new Retriver(NULL);
4562
}
@@ -52,8 +69,16 @@ void DataParser::setSource(DataSourceType type)
5269
if(m_lf){
5370
m_lf->disconnect();
5471
}
72+
//本地文件
73+
QString fileName = QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss")+".txt";
74+
QFile file(fileName);
75+
if(!file.open(QFile::WriteOnly)){
76+
qDebug()<<"Cannot open local file.";
77+
}
5578
break;
79+
}
5680
case Sim:
81+
{
5782
if(!m_sim){
5883
m_sim = new Simulator();
5984
}
@@ -66,7 +91,9 @@ void DataParser::setSource(DataSourceType type)
6691
m_comRetriver->disconnect();
6792
}
6893
break;
94+
}
6995
case Local:
96+
{
7097
if(!m_lf){
7198
m_lf = new LocalFile(m_filePath);
7299
}
@@ -81,6 +108,7 @@ void DataParser::setSource(DataSourceType type)
81108
}
82109
break;
83110
}
111+
}
84112
}
85113

86114
void DataParser::clearBuff()
@@ -377,6 +405,9 @@ void DataParser::run()
377405
//收到数据后填充至缓存区等待解析
378406
void DataParser::sltRcvData(QByteArray ba)
379407
{
408+
if(file.isOpen()){
409+
file.write(ba);
410+
}
380411
m_mutex.lock();
381412
mBuff.append(ba);
382413
m_mutex.unlock();

MindViewer/dataparser.h

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class DataParser : public QThread
2323
DataParser();
2424
~DataParser();
2525

26+
void saveLocalFile();
27+
2628
void setFilePath(QString path);
2729

2830
void setSource(DataSourceType type);
@@ -70,6 +72,10 @@ private slots:
7072
QMutex m_mutex;
7173

7274
QString m_filePath;
75+
76+
DataSourceType m_eType;//当前数据源类型
77+
QFile file;
78+
bool m_bSave;
7379
};
7480

7581
#endif // DATAPARSER_H

MindViewer/mainwidget.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,39 @@ void MainWidget::sltBtnLocal()
8181

8282
void MainWidget::sltBtnPlay()
8383
{
84+
if(m_eType == None){
85+
QMessageBox::warning(this,tr("警告"),tr("请先选择数据源"));
86+
return;
87+
}
88+
if(m_bStatus){
89+
QMessageBox::warning(this,tr("警告"),tr("当前处于运行状态"));
90+
return;
91+
}
8492
m_bStatus = true;
8593
ui->labelStatusValue->setText("运行");
8694
sltBtnClear();
8795
}
8896

8997
void MainWidget::sltBtnPause()
9098
{
99+
if(m_eType == None){
100+
QMessageBox::warning(this,tr("警告"),tr("请先选择数据源"));
101+
return;
102+
}
103+
if(!m_bStatus){
104+
QMessageBox::warning(this,tr("警告"),tr("当前处于暂停状态"));
105+
return;
106+
}
91107
m_bStatus = false;
92108
ui->labelStatusValue->setText("暂停");
93109
}
94110

95111
void MainWidget::sltBtnClear()
96112
{
113+
if(m_eType == None){
114+
QMessageBox::warning(this,tr("警告"),tr("当前无数据可清理"));
115+
return;
116+
}
97117
//清空界面
98118
ui->labelPowerValue->setText("0");
99119
ui->labelSignalValue->setText("0");
@@ -108,6 +128,10 @@ void MainWidget::sltBtnClear()
108128

109129
void MainWidget::sltBtnSave()
110130
{
131+
if(m_eType == None){
132+
QMessageBox::warning(this,tr("警告"),tr("当前无数据可保存"));
133+
return;
134+
}
111135
switch(m_eType){
112136
case COM:
113137
break;

MindViewer/mainwidget.ui

+12
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ QFrame#frameCurve{
128128
<height>64</height>
129129
</size>
130130
</property>
131+
<property name="statusTip">
132+
<string>运行</string>
133+
</property>
131134
<property name="text">
132135
<string/>
133136
</property>
@@ -151,6 +154,9 @@ QFrame#frameCurve{
151154
<height>64</height>
152155
</size>
153156
</property>
157+
<property name="statusTip">
158+
<string>暂停</string>
159+
</property>
154160
<property name="text">
155161
<string/>
156162
</property>
@@ -184,6 +190,9 @@ QFrame#frameCurve{
184190
<property name="toolTip">
185191
<string>清空数据</string>
186192
</property>
193+
<property name="statusTip">
194+
<string>清空缓存</string>
195+
</property>
187196
<property name="text">
188197
<string/>
189198
</property>
@@ -210,6 +219,9 @@ QFrame#frameCurve{
210219
<property name="toolTip">
211220
<string>保存数据</string>
212221
</property>
222+
<property name="statusTip">
223+
<string>保存数据</string>
224+
</property>
213225
<property name="text">
214226
<string/>
215227
</property>

0 commit comments

Comments
 (0)