-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwin.cpp
448 lines (387 loc) · 14.1 KB
/
mainwin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#pragma execution_character_set("utf-8")
#include "mainwin.h"
#include "ui_mainwin.h"
#include<QDebug>
#include<QGridLayout>
#include<QInputDialog>
#include<QMessageBox>
#include<QFileDialog>
#include<QDialogButtonBox>
#include<QFormLayout>
#include"md5.h"
#include<QThread>
//#include"login.h"
MainWin::MainWin(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWin)
{
ui->setupUi(this);
device_system = new DeviceSystem();
// login_widget = new Login(this);
settingui = new Setting(device_system,this);
settingui->setWindowFlags(settingui->windowFlags() | Qt::Window);
calibration_dialog = new Calibration(device_system);
//chart_widgt
chart_widget = new chartswidgt(device_system);
QGridLayout *layout= new QGridLayout();
layout->setSpacing(0);
layout->setMargin(0);
layout->setContentsMargins(0,0,0,0);
layout->addWidget(chart_widget);
ui->widget_chart->setLayout(layout);
//tabelview
standard_model = new QStandardItemModel;
standard_selection = new QItemSelectionModel(standard_model);//Item选择模型
ui->tableView->setModel(standard_model);
ui->tableView->setSelectionModel(standard_selection);
ui->tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
standard_model->setRowCount(0);
QStringList headerList;
headerList<<QString("时间")<<QString("颜色")<<QString("名称")<<QString("测量值");
standard_model->setHorizontalHeaderLabels(headerList);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
// ui->tableView->resizeColumnsToContents();
ui->tableView->setMaximumWidth(280);
ui->tableView->setVisible(false);
//widget_chart
connect(device_system,SIGNAL(UpdataTestName(QString)),this,SLOT(UpdataTestName(QString)));
connect(device_system,SIGNAL(UpdataTestTime(QString)),this,SLOT(UpdataTestTime(QString)));
connect(device_system,SIGNAL(UpdataTestDeep(QString)),this,SLOT(UpdataTestDeep(QString)));
connect(device_system, SIGNAL(UpdataDocsnames(QList<QString>,QList<QString>)),this,SLOT(on_UpdataDocsnames(QList<QString>,QList<QString>)));
//历史测试数据初始化
ui->dateEdit->setCalendarPopup(true);
ui->dateEdit->setDate(QDate::currentDate());
ui->dateEdit_2->setCalendarPopup(true);
ui->dateEdit_2->setDate(QDate::currentDate());
ui->frame_2->setMaximumWidth(600);
ui->frame_2->setMinimumWidth(400);
//历史记录
standard_model_2 = new QStandardItemModel;
standard_selection_2 = new QItemSelectionModel(standard_model_2);//Item选择模型
ui->tableView_2->setModel(standard_model_2);
ui->tableView_2->setSelectionModel(standard_selection_2);
ui->tableView_2->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui->tableView_2->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
standard_model_2->setRowCount(0);
standard_model_2->setColumnCount(2);
QStringList headerList_2;
headerList_2<<QString("测试名称")<<QString("测试时间");
standard_model_2->setHorizontalHeaderLabels(headerList_2);
ui->tableView_2->resizeColumnsToContents();
ui->tableView_2->horizontalHeader()->setStretchLastSection(true);
//widget_device
ui->widget_device->setMaximumHeight(180);
online_group = new QButtonGroup();
online_group->addButton(ui->radioButton,0);
online_group->addButton(ui->radioButton_2,1);
online_group->addButton(ui->radioButton_3,2);
online_group->addButton(ui->radioButton_4,3);
online_group->addButton(ui->radioButton_5,4);
online_group->addButton(ui->radioButton_11,5);
online_group->setExclusive(false);
enable_group =new QButtonGroup();
enable_group->addButton(ui->radioButton_6,0);
enable_group->addButton(ui->radioButton_7,1);
enable_group->addButton(ui->radioButton_8,2);
enable_group->addButton(ui->radioButton_9,3);
enable_group->addButton(ui->radioButton_10,4);
enable_group->setExclusive(false);
//定时器
timer =new QTimer();
timer->start(1000);
connect(timer,SIGNAL(timeout()),this,SLOT(on_DeviceStatus()));
//action
ui->action->setEnabled(true);
ui->action_3->setDisabled(true);
connect(chart_widget,SIGNAL(AddPointData(QString,QColor,QString,QString)),this,SLOT(on_AddPointData(QString,QColor,QString,QString)));
connect(standard_selection_2,SIGNAL(selectionChanged(const QItemSelection, const QItemSelection )),this,SLOT(on_SelectionChanged(const QItemSelection, const QItemSelection)));
for(int i=0;i<device_system->device_num;i++)
{
connect(device_system->device_vector.at(i),SIGNAL(addcanrow(double, int , int,int, QByteArray)),settingui,SLOT(on_addcanrow(double, int , int,int, QByteArray)));
}
connect(device_system, SIGNAL(SaveConfigureFile(QString)),settingui, SLOT(WriteTableView(QString)));
connect(device_system, SIGNAL(LoadConfigureFile(QString)),settingui, SLOT(ReadTableView(QString)));
connect(device_system, SIGNAL(testconfigureshow(QString)),this, SLOT(on_testconfigureshow(QString)));
}
//析构函数
MainWin::~MainWin()
{
delete device_system;
if(help_process != nullptr)help_process->kill();
delete settingui;
delete ui;
delete chart_widget;
delete help_process;
}
void MainWin::UpdataTestName(QString str)
{
ui->lineEdit->setText(str);
}
void MainWin::UpdataTestTime(QString str)
{
ui->lineEdit_2->setText(str);
}
void MainWin::UpdataTestDeep(QString str)
{
ui->lineEdit_3->setText(str);
}
void MainWin::on_action_4_triggered()
{
settingui->show();
}
//绘图窗口放大
void MainWin::on_action_5_triggered(bool checked)
{
qDebug()<<checked;
if(checked)
{
ui->frame_2->hide();
ui->widget_device->hide();
}
else
{
ui->frame_2->show();
ui->widget_device->show();
}
}
//新建实验弹出窗口
void MainWin::on_action_triggered()
{
QDialog dialog(this);
// dialog.setAttribute(Qt::WA_DeleteOnClose);
QFormLayout form(&dialog);
dialog.setWindowTitle("新建实验");
QString value1 = QString("实验名称: ");
QString test_name("实验1");
QLineEdit *line_edit = new QLineEdit("实验1");
form.addRow(value1, line_edit);
QString value2 = QString("测试时长(s): ");
QSpinBox *spinbox = new QSpinBox(&dialog);
spinbox->setMaximum(1000000);
form.addRow(value2, spinbox);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal, &dialog);
form.addRow(&buttonBox);
form.setSizeConstraint(QLayout::SetFixedSize);
QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));
if (dialog.exec() == QDialog::Accepted) {
test_name = line_edit->text();
int time = spinbox->value()*1000;
ui->action->setDisabled(true);
ui->action_3->setEnabled(true);
//新建实验
device_system->NewLocalTest(test_name);
device_system->AutoStop(time);
}
}
//结束实验
void MainWin::on_action_3_triggered()
{
ui->action->setEnabled(true);
ui->action_3->setDisabled(true);
device_system->EndLocalTest();
}
//取点
void MainWin::on_action_6_toggled(bool checked)
{
chart_widget->GetSeriesPoint(checked);
}
//删点
void MainWin::on_action_7_triggered(bool checked)
{
deltablerow =checked;
on_MovePointdata();
}
//导出数据
void MainWin::on_action_8_triggered()
{
QString curPath = QCoreApplication::applicationDirPath();
// curPath = QDir::currentPath();
QString dlgTile = "数据保存路径";
QString selectedDir = QFileDialog::getExistingDirectory(this,dlgTile,curPath,QFileDialog::ShowDirsOnly);
if(!selectedDir.isEmpty())
{
selectedDir+="/";
selectedDir+=device_system-> test_name.split('/').at(0);
QDir dir;
if(!dir.exists(selectedDir)) dir.mkpath(selectedDir);
QString data_file = selectedDir+"/"+"data.txt";
QString configure_file = selectedDir+"/"+"configure.txt";
device_system->SaveDataFile(data_file);
settingui->WriteTableView(configure_file);
}
}
//查询历史
void MainWin::on_pushButton_clicked()
{
QDate begin_date = ui->dateEdit->date();
QDate end_date = ui->dateEdit_2->date();
device_system->FindDocsNames(begin_date,end_date);
emit FindDocsNames(begin_date,end_date);
//device_system->FindDocs();
}
void MainWin::on_AddPointData(QString time,QColor color, QString name, QString value)
{
ui->action_6->setChecked(false);
if(standard_model->rowCount() ==0) ui->tableView->setVisible(true);
qDebug()<<"AddPointData receive";
QList<QStandardItem*> row;
QStandardItem *item_time= new QStandardItem(time);
QStandardItem *item_color= new QStandardItem();
QBrush brush(color);
item_color->setBackground(brush);
QStandardItem *item_name= new QStandardItem(name);
QStandardItem *item_value= new QStandardItem(value);
row.append(item_time);
row.append(item_color);
row.append(item_name);
row.append(item_value);
standard_model->appendRow(row);
ui->tableView->resizeColumnsToContents();
}
void MainWin::on_MovePointdata()
{
QModelIndex cur_index = standard_selection->currentIndex();
if(cur_index.row() == standard_model->rowCount()-1)
{
standard_model->removeRow(cur_index.row());
}
else
{
standard_model->removeRow(cur_index.row());
standard_selection->setCurrentIndex(cur_index,QItemSelectionModel::Select);
}
if(standard_model->rowCount() ==0) ui->tableView->setVisible(false);
}
void MainWin::on_DeviceStatus()
{
for(int i=0;i<device_system->device_num;i++)
{
bool status = device_system->device_vector.at(i)->online_status;
online_group->buttons().at(i)->setChecked(status);
status = device_system->device_vector.at(i)->actual_status;
enable_group->button(i)->setChecked(status);
}
bool status = device_system->clock_device_status;
online_group->buttons().at(5)->setChecked(status);
}
void MainWin::on_UpdataDocsnames(QList<QString> name,QList<QString> time)
{
qDebug()<<"on_UpdataDocsnames"<<name.size();
QList<QStandardItem*> item_column_name = standard_model_2->takeColumn(0);
item_column_name.clear();
QList<QStandardItem*> item_column_time = standard_model_2->takeColumn(0);
item_column_time.clear();
for(int i=0;i<name.size();i++)
{
QStandardItem *item_name = new QStandardItem();
item_name->setText(name.at(i));
item_column_name.append(item_name);
QStandardItem *item_time = new QStandardItem();
item_time->setText(time.at(i));
item_column_time.append(item_time);
}
standard_model_2->appendColumn(item_column_name);
standard_model_2->appendColumn(item_column_time);
QStringList labels;
labels.append("实验名称");
labels.append("实验时间");
standard_model_2->setHorizontalHeaderLabels(labels);
}
void MainWin::on_SelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
if(selected.indexes().isEmpty())return;
int index = selected.indexes().at(0).row();
device_system->FindDocs(index);
standard_selection_2->clearSelection();
qDebug()<<"current select"<< index;
}
void MainWin::on_action_9_triggered()
{
//帮助文档
// device_system->FindConfigureFile();
qDebug()<<"HELP";
if(help_process == nullptr) help_process = new QProcess();
// QString exe("./assistant/assistant.exe");
QString exe("./assistant.exe");
QStringList params;
// params << "-collectionFile" << "./assistant/assistant.qhc";
params << "-collectionFile" << "./assistant.qhc";
help_process->start(exe, params);
if (!help_process->waitForStarted()) {
QMessageBox::critical(0, QObject::tr("Tips"),
QObject::tr("Unable to launch Qt Assistant (%1)").arg(exe));
//qDebug()<<"HELPxxxxxxxxxxx";
}
}
void MainWin::on_action_10_triggered()
{
//导入数据
QString curPath = QCoreApplication::applicationDirPath();
// curPath = QDir::currentPath();
QString dlgTile = "选择一个目录";
QString selectedDir = QFileDialog::getExistingDirectory(this,dlgTile,curPath,QFileDialog::ShowDirsOnly);
QString data_file = selectedDir+"/"+"data.txt";
QString configure_file = selectedDir+"/"+"configure.txt";
settingui->ReadTableView(configure_file);
device_system->LoadDataFile(data_file);
}
void MainWin::on_action_2_triggered()
{
//清屏清除数据
device_system->ClearData();
}
void MainWin::on_action_13_triggered()
{
//弹窗取点
chart_widget->showDataDialog();
}
void MainWin::on_action_15_triggered()
{
//dialog->setAttribute(Qt::WA_DeleteOnClose);
//校准
calibration_dialog->show();
//device_system->RemoteTcpReset();
//device_system->StopSendDocs();
}
void MainWin::on_action_11_triggered()
{
//导入配置文件
QString curPath = QCoreApplication::applicationDirPath();
QString dlgTile = "选择配置文件";
QString configure_file = QFileDialog::getOpenFileName(this,dlgTile,curPath,tr("txt (*.txt)"));
if(!configure_file.isEmpty())settingui->ReadTableView(configure_file);
}
void MainWin::on_action_12_triggered()
{
//导出配置文件
QString curPath = QCoreApplication::applicationDirPath();
QString dlgTile = "配置文件保存路径";
QString selectedDir = QFileDialog::getExistingDirectory(this,dlgTile,curPath,QFileDialog::ShowDirsOnly);
if(!selectedDir.isEmpty())
{
QString configure_file = selectedDir+"/"+"configure.txt";
settingui->WriteTableView(configure_file);
}
}
void MainWin::on_action_16_triggered()
{
//适应窗口
chart_widget->XAxisAdapt();
}
void MainWin::on_testconfigureshow(QString str)
{
qDebug()<<str;
ui->plainTextEdit->setPlainText(str);
}
void MainWin::on_action_14_triggered(bool checked)
{
//远程实时
device_system->GetRtData(checked);
if(checked) device_system->SetMaxDataLen(chart_widget->plot_size*2000);
else device_system->SetMaxDataLen(60000000);
}