-
Notifications
You must be signed in to change notification settings - Fork 6
/
mainwindow.cpp
814 lines (695 loc) · 28.4 KB
/
mainwindow.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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "plotWindows/scatter/scatterwindow.h"
#include "plotWindows/orientation_3d/orientationwindow.h"
#include "plotWindows/line/lineplot.h"
#include "helperObjects/graphHeaderWidget/graphheaderwidget.h"
#include <QApplication>
#include <QLabel>
#include <QSurfaceFormat>
#include <QDateTime>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFontComboBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMessageBox>
#include <QtGui/QScreen>
#include <QtGui/QFontDatabase>
#include <QMdiSubWindow>
#include <QFileDialog>
#include <QSerialPortInfo>
const QString __appVersion__ = "1.0";
QString __configVersion__;
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWindow),
_pendingDeletion(false),
_loggingInitialized(false)
{
// Setup UI made in designer
ui->setupUi(this);
setWindowIcon(QIcon(":/icons/icon.png"));
// Collect handles for checkboxes and names for math channels into arrays
mathChEnabled.push_back(ui->mathCh1en);
mathChEnabled.push_back(ui->mathCh2en);
mathChEnabled.push_back(ui->mathCh3en);
mathChEnabled.push_back(ui->mathCh4en);
mathChEnabled.push_back(ui->mathCh5en);
mathChEnabled.push_back(ui->mathCh6en);
mathChName.push_back(ui->mathCh1name);
mathChName.push_back(ui->mathCh2name);
mathChName.push_back(ui->mathCh3name);
mathChName.push_back(ui->mathCh4name);
mathChName.push_back(ui->mathCh5name);
mathChName.push_back(ui->mathCh6name);
// Initialize objects
dataAdapter = new SerialAdapter();
netAdapter = new NetworkAdapter();
mainTimer = new QTimer();
mux = DataMultiplexer::GetP();
settings = new QSettings(QString("config.ini"), QSettings::IniFormat);
connect(mux, &DataMultiplexer::logLine, this, &MainWindow::logLine);
logLine("Starting up..");
/**
* Check presence of OpenGL drivers
*/
Q3DScatter *graph = new Q3DScatter();
// Check that OpenGL exists
if (!graph->hasContext()) {
QMessageBox msgBox;
msgBox.setText("Couldn't initialize the OpenGL context.");
msgBox.exec();
return;
}
delete graph;
/**
* Configure parameters for serial port
*/
// Port selector
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos)
ui->portSelector->addItem(info.portName());
// Port baud
ui->portBaud->addItem("1000000");
ui->portBaud->addItem("115200");
ui->portBaud->addItem("9600");
ui->portBaud->setCurrentIndex(1);
// 'Connect' button opens serial port connection
QObject::connect(ui->connectButton, &QPushButton::clicked,
this, &MainWindow::toggleConnection);
// Serial adapter objects logs data into a MainWindow logger
QObject::connect(dataAdapter, &SerialAdapter::logLine,
this, &MainWindow::logLine);
// Serial adapter objects logs data into a MainWindow logger
QObject::connect(netAdapter, &NetworkAdapter::logLine,
this, &MainWindow::logLine);
// Connect channel enable signals to slot
for (uint8_t i = 0; i < mathChEnabled.size(); i++)
QObject::connect(mathChEnabled[i], &QCheckBox::clicked,
this, &MainWindow::UpdateAvailMathCh);
//TODO: Add data bits, parity and flow control fields
// For now assume 8bits, no parity, no flow control, 1 stop bit
// Connect/disconnect button
logLine("Start-up completed, loading settings...");
LoadSettings();
// Timer ticks at 1s, refreshing certain UI elements
mainTimer->setInterval(1000);
QObject::connect(mainTimer, &QTimer::timeout, this, &MainWindow::refreshUI);
mainTimer->start();
}
/**
* @brief Clean up and backup settings on exit
* When exiting the window, save all settings and clean up
*/
MainWindow::~MainWindow()
{
logLine("Deleting main window");
_pendingDeletion = true;
// Save port options
settings->setValue("port/name",
ui->portSelector->itemText(ui->portSelector->currentIndex()));
settings->setValue("port/baud",
ui->portBaud->itemText(ui->portBaud->currentIndex()));
settings->setValue("port/enabled",ui->enableNetwork->isChecked());
settings->setValue("channel/startChar", ui->frameStartCh->text());
settings->setValue("channel/separator", ui->frameChSeparator->text());
settings->setValue("channel/endChar", ui->frameEndSep->text());
settings->setValue("channel/endCharR", ui->termSlashR->isChecked());
settings->setValue("channel/endCharN", ui->termSlashN->isChecked());
// Save channel settings
for (uint8_t i = 0; i < ch.size(); i++)
{
QString chID_str = QString::number(i);
settings->setValue("channel/channel"+chID_str+"ID", ch[i]->GetId());
settings->setValue("channel/channel"+chID_str+"name", ch[i]->GetName());
}
// Save math channels
for (uint8_t i = 0; i < mathComp.size(); i++)
{
QString id_str = QString::number(i);
settings->setValue("math/component"+id_str+"inCh",
mathComp[i]->GetInCh());
settings->setValue("math/component"+id_str+"mathCh",
mathComp[i]->GetMathCh());
settings->setValue("math/component"+id_str+"math",
mathComp[i]->GetMath());
}
settings->setValue("math/componentCount", (uint8_t)mathComp.size());
// Save math channel labels
for (uint8_t i = 0; i < mathChEnabled.size(); i++)
if (mathChEnabled[i]->isChecked())
settings->setValue("math/channel"+QString::number(i+1)+"name",
mathChName[i]->text());
// Save file logging settings to file
settings->setValue("fileLogging/append", ui->appendButton->isChecked());
settings->setValue("fileLogging/folder", ui->logfilePath->text());
settings->setValue("fileLogging/fileName", ui->logfileName->text());
settings->setValue("fileLogging/channelSeparator", ui->logfileChSep->text());
// Save currently open page
settings->setValue("ui/startPage", ui->tabWidget->currentIndex());
// Save network input settings
settings->setValue("network/port",ui->netportSelector->value());
settings->setValue("network/enabled",ui->enableNetwork->isChecked());
settings->setValue("port/enabled",ui->enableSerial->isChecked());
settings->sync();
for (Channel *X : ch)
delete X;
ch.clear();
for (UIMathChannelComponent *X : mathComp)
delete X;
mathComp.clear();
// Clean-up for program run log
_loggingInitialized = false;
_logFile->close();
delete _logFileStream;
_logFile->deleteLater();
delete ui;
}
/**
* @brief Load settings from the configuration file
*/
void MainWindow::LoadSettings()
{
// Config file versioning
__configVersion__ =
settings->value("misc/configVersion",__appVersion__).toString();
settings->setValue("misc/configVersion",__configVersion__);
settings->sync();
// Data frame settings
ui->frameStartCh->setText(
settings->value("channel/startChar","").toString());
ui->frameChSeparator->setText(
settings->value("channel/separator","").toString());
ui->frameEndSep->setText(
settings->value("channel/endChar","").toString());
ui->termSlashN->setChecked(
settings->value("channel/endCharN","false").toBool());
ui->termSlashR->setChecked(
settings->value("channel/endCharR","false").toBool());
// Number of data channels
uint8_t nInChannels = settings->value("channel/numOfChannels","1").toInt();
ui->channelNumber->setValue(nInChannels);
on_channelNumber_valueChanged(ui->channelNumber->value());
// Load number of math components (components must be added before
// enabling channels)
uint8_t mathComponentCount = settings->value("math/componentCount","0").toUInt();
for (uint8_t i = 0; i < mathComponentCount; i++)
on_addMathComp_clicked();
// Read mask of enabled math channels and apply UI changes
uint8_t mathChMask = settings->value("math/channelMask","0").toUInt();
for (uint8_t i = 0; i < mathChEnabled.size(); i++)
if ( mathChMask & (uint8_t)(1<<(i+1)) )
{
mathChEnabled[i]->setChecked(true);
}
UpdateAvailMathCh();
// Load file logging settings
ui->appendButton->setChecked(
settings->value("fileLogging/append","true").toBool());
ui->overwriteButton->setChecked(
!settings->value("fileLogging/append","true").toBool());
ui->logfilePath->setText(
settings->value("fileLogging/folder","").toString());
ui->logfileName->setText(
settings->value("fileLogging/fileName","").toString());
ui->logfileChSep->setText(
settings->value("fileLogging/channelSeparator",",").toString());
// Restore last opened tab
ui->tabWidget->setCurrentIndex(settings->value("ui/startPage","0").toUInt());
// Load settings for network connection
ui->netportSelector->setValue(settings->value("network/port","5555").toUInt());
ui->enableNetwork->setChecked(settings->value("network/enabled","false").toBool());
ui->enableSerial->setChecked(settings->value("port/enabled","true").toBool());
if (ui->enableNetwork->isChecked())
ui->networkGroup->setEnabled(true);
if (ui->enableSerial->isChecked())
ui->serialGroup->setEnabled(true);
}
/**
* @brief Trigger refresh of various UI elements
* Usually called periodically every 1s from a main timer
*/
void MainWindow::refreshUI()
{
ui->timestamp->setText(QDateTime::currentDateTime().time().toString());
// Refresh port selector if nothing is selected
if (ui->portSelector->currentText() == "")
{
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos)
ui->portSelector->addItem(info.portName());
}
ui->sampleRate->setText("Data rate: "+
QString::number(mux->GetSampleRateEst())+" Hz");
}
/**
* @brief Toggle a connection to data adapter
* Turn a connection to the underlying data adapter on or off
*/
void MainWindow::toggleConnection()
{
if (ui->connectButton->text() == "Connect")
{
// Update frame information in MUX
QString termSeq = ui->frameEndSep->text();
if (ui->termSlashR->isChecked())
termSeq += QChar(0x000D);
if (ui->termSlashN->isChecked())
termSeq += QChar(0x000A);
if (ui->frameChSeparator->text() == "" ||
termSeq == "")
{
logLine("Frame channel separator and frame terminator cannot be empty!");
return;
}
mux->SetSerialFrameFormat(ui->frameStartCh->text(), \
ui->frameChSeparator->text(), \
termSeq);
// Collect channel labels and register them in the mux
QString *chLabels = new QString[ch.size()];
for (uint8_t i = 0; i < ch.size(); i++)
{
chLabels[i] = ch[i]->GetName();
}
mux->RegisterSerialCh(ch.size(), chLabels);
// Clean up before exit
delete[] chLabels;
if (ui->enableSerial->isChecked())
{
// Configure serial port
dataAdapter->UpdatePort(ui->portSelector->itemText(
ui->portSelector->currentIndex()), \
ui->portBaud->itemText(ui->portBaud->currentIndex()));
// Prevent edits to serial port while connection is open
ui->serialGroup->setEnabled(false);
dataAdapter->StartListening();
//TODO: How to handle a case where function is called, but results in an error?
}
if (ui->enableNetwork->isChecked())
{
// TODO: Input validation on port!
netAdapter->SetNetPort(ui->netportSelector->value());
ui->networkGroup->setEnabled(false);
netAdapter->StartListening();
}
// Rename the button
ui->connectButton->setText("Disconnect");
}
else if (ui->connectButton->text() == "Disconnect")
{
if (ui->enableSerial->isChecked())
{
ui->serialGroup->setEnabled(true);
dataAdapter->StopListening();
}
if (ui->enableNetwork->isChecked())
{
ui->networkGroup->setEnabled(true);
netAdapter->StopListening();
}
ui->connectButton->setText("Connect");
}
}
/**
* @brief [Slot function] Log a line to UI and an external run log file
* @param line
*/
void MainWindow::logLine(const QString &line)
{
QString time = QDateTime::currentDateTime().time().toString();
// There's a chance this function is called after the UI has been deleted
// Make sure we never try to access UI elements if MainWindow destructor
// has been called.
if (_pendingDeletion)
return;
// Handle opening and rotating logs between the program launches. On
// every launch, increments the log descriptor and open new logfile to
// write to.
if (!_loggingInitialized)
{
// Load logfile info
uint8_t lastLogIndex = settings->value("appLog/index","0").toUInt();
const uint8_t maxLogIndex = settings->value("appLog/maxIndex","3").toUInt();
uint8_t currentLogIndex = (lastLogIndex + 1) % maxLogIndex;
_logFile = new QFile("datadashboard_run"+QString::number(currentLogIndex)+".log");
if (!_logFile->open(QIODevice::WriteOnly | QIODevice::Text))
{
ui->logLine->setText(time + ": " + "Error opening log file");
return;
}
_logFileStream = new QTextStream(_logFile);
settings->setValue("appLog/index", currentLogIndex);
_loggingInitialized = true;
}
ui->logLine->setText(time + ": " + line);
// If log file is initialized, append a line in there as well
if (_loggingInitialized)
(*_logFileStream) << time + ": " + line << Qt::endl;
}
/**
* @brief [Slot function] Handles dynamic construction of data channels
* When called, it destroys all existing channel entries, and constructs
* a number of new ones corresponding to the argument.
* At the same time, number of channels is saved into a config file,
* and existing data from config file is used to populate new fields
* @param arg1
*/
void MainWindow::on_channelNumber_valueChanged(int arg1)
{
settings->setValue("channel/numOfChannels", arg1);
settings->sync();
logLine("Channel number changed to "\
+QString::number(arg1)+", reconstructing UI");
// Clear existing list of channels
clearLayout(ui->channelList, true);
// Clear old list with channel elements
ch.clear();
// Reconstruct part of UI to offer requested number of channels
for (uint8_t i = 0; i < arg1; i++)
{
QString chID_str = QString::number(i);
QHBoxLayout *entry = new QHBoxLayout();
// Extract settings for this channel from config file, if existing
int chID = settings->value("channel/channel"+chID_str+"ID", chID_str).toInt();
QString chName = settings->value("channel/channel" + chID_str + "name","Serial "+ chID_str).toString();
// Construct UI elements for channel configuration
Channel *tmp = new Channel("Channel " + chID_str, chID, chName);
ch.push_back(tmp);
// Add UI elements to a layout, then push layout into the UI
entry->addWidget(tmp->chLabel, 0, Qt::AlignLeft);
entry->addWidget(tmp->channelName, 0, Qt::AlignLeft);
ui->channelList->addLayout(entry);
}
}
/**
* @brief Delete all elements in a layout provided in arguments
* @param layout Layout to delete objects from
* @param deleteWidgets If true, delete widgets
*/
void MainWindow::clearLayout(QLayout* layout, bool deleteWidgets)
{
while (QLayoutItem* item = layout->takeAt(0))
{
if (deleteWidgets)
{
if (QWidget* widget = item->widget())
{
widget->deleteLater();
}
}
if (QLayout* childLayout = item->layout())
clearLayout(childLayout, deleteWidgets);
delete item;
}
}
///////////////////////////////////////////////////////////////////////////////
////
/// Math components UI manipulations
///
///////////////////////////////////////////////////////////////////////////////
/**
* @brief Register a math channel with the given ID in the mux
* @param chID channel Id to be registered
*/
void MainWindow::RegisterMathChannel(uint8_t chID)
{
MathChannel *mc = new MathChannel();
logLine("Attempting to register math channel. Looking up components...");
mc->SetLabel(mathChName[chID-1]->text());
// Look up all the components of this channel ID
for (UIMathChannelComponent *X : mathComp)
{
// T
if (X->GetMathCh() == (chID))
{
mc->AddComponent(static_cast<MathOperation>(X->GetMath()), X->GetInCh());
}
}
logLine("Registering math channel "+QString::number(chID)+" with "\
+QString::number(mc->_component.size())+" components");
mux->RegisterMathChannel(chID, mc);
}
/**
* @brief [Slot function] Add new math component to the scroll list
*/
void MainWindow::on_addMathComp_clicked()
{
static uint32_t _id = 0;
// Convert current id to string for easier manipulation
QString id_str = QString::number(_id);
logLine("Adding math component "+id_str);
// Construct component for channel math and save it to global variable
UIMathChannelComponent *tmp = new UIMathChannelComponent((uint8_t)mathComp.size());
mathComp.push_back(tmp);
// Add new component to the UI
ui->mathCompLayout->addLayout(tmp->GetLayout());
// Update available math channels in the component
logLine("Math component "+id_str+" added to UI");
// Set values from settings, if exist, otherwise load defaults
tmp->SetInCh(settings->value("math/component"+id_str+"inCh","0").toInt());
tmp->SetMathCh(settings->value("math/component"+id_str+"mathCh","1").toInt());
tmp->SetMath(settings->value("math/component"+id_str+"math","0").toInt());
connect(tmp, &UIMathChannelComponent::deleteRequested, \
this, &MainWindow::on_delete_updateMathComp);
logLine("Saved math component "+id_str);
_id++;
}
/**
* @brief [Slot function] Update a list of available math channels used by
* other components. Function called whenever a match channel checkbox
* has been clicked
*/
void MainWindow::UpdateAvailMathCh()
{
// List of channels currently enabled, to be passed to QComboBoxes
// in math components list -> not used for now
int mathCh[6] = {0};
int count = 0;
// Collapse all enabled channels into a binary mask,
// save mask into a config file
static uint8_t chMask = 0;
logLine("Updating available math channels in UI...");
// Loop through all QCheckBox elements and configure UI look based on
// whether they are checked or not
for (uint8_t i = 0; i < mathChEnabled.size(); i++)
{
QString id_str = QString::number(i+1);
if (mathChEnabled[i]->isChecked())
{
mathCh[count++] = (i+1);
mathChName[i]->setEnabled(true);
// Load channel name from settings, if it exists and there
// isn't one already set
if (mathChName[i]->text() == "")
mathChName[i]->setText(
settings->value("math/channel"+id_str+"name",
"Math "+id_str).toString());
logLine("Channel "+QString::number(i+1)+" enabled in UI");
}
else
mathChName[i]->setEnabled(false);
// If it's enabled, but it wasn't in the last call
if (mathChEnabled[i]->isChecked() && !(((1<<(i+1)) & chMask) > 0))
{
logLine("Channel "+QString::number(i+1)+" has been enabled");
chMask |= (1<<(i+1));
RegisterMathChannel(i+1);
}
// If it's disabled, but it was enabled in the last call
else if (!mathChEnabled[i]->isChecked() && (((1<<(i+1)) & chMask) > 0))
{
chMask &= ~(1<<(i+1));
mux->UnegisterMathChannel(i+1);
logLine("Channel "+QString::number(i+1)+" has been disabled");
}
}
// Save channel mask
settings->setValue("math/channelMask", chMask);
settings->sync();
// Go through existing math components list and update QComboBox with new
// available math channels
// for (MathChannelComponent* X : mathComp)
// X->UpdateMathCh(mathCh, count);
}
/**
* @brief [Slot function] Called by MathChannelComponent class when the delete
* button has been pressed. It handles deletion in UI and clean up in backend
* @param id ID of MathChannelComponent::_id to be deleted
*/
void MainWindow::on_delete_updateMathComp(uint8_t id)
{
// Math component got destroyed
logLine("Requested to delete math channel "+QString::number(id));
// Find component in vector
uint8_t i;
for (i = 0; i < mathComp.size(); i++)
if (mathComp[i]->GetID() == id)
break;
// Clear UI elements
clearLayout(mathComp[i]->GetLayout());
// Delete remainder
delete mathComp[i];
// Remove the entry from vector
mathComp.erase(mathComp.begin()+i);
// Update IDs of entries in the vector
for (i = 0; i < mathComp.size(); i++)
mathComp[i]->SetID(i);
}
///////////////////////////////////////////////////////////////////////////////
////
/// Dynamic creation of graphs
///
///////////////////////////////////////////////////////////////////////////////
/**
* @brief [Slot] Create new 3D orientation graph
*/
void MainWindow::on_add3D_clicked()
{
logLine("UI: Creating 3D plot");
static uint8_t _3DgraphCount = 0;
QString winID = QString::number(_3DgraphCount);
OrientationWindow *orient3DWindow = new OrientationWindow(this, "orientationWindow_"+winID);
//orient3DWindow->setObjectName("orientationWindow_"+winID);
QObject::connect(orient3DWindow, &OrientationWindow::logLine,
this, &MainWindow::logLine);
QMdiSubWindow *plotWindow = ui->mdiArea->addSubWindow(orient3DWindow);
plotWindow->setWindowFlags(Qt::WindowCloseButtonHint);
plotWindow->setAttribute(Qt::WA_DeleteOnClose, true);
plotWindow->setWindowTitle("3D Orientation " + winID);
plotWindow->setWindowIcon(QIcon(":/icons/icon.png"));
plotWindow->show();
_3DgraphCount++;
}
/**
* @brief [Slot] Create new scatter graph
*/
void MainWindow::on_addScatter_clicked()
{
logLine("UI: Creating scatter plot");
static uint8_t _ScatterCount = 0;
QString winID = QString::number(_ScatterCount);
// Create scatter plot
ScatterWindow *scatterWindow = new ScatterWindow("scatterWindow_"+winID);
//scatterWindow->setObjectName("scatterWindow_"+winID);
QObject::connect(scatterWindow, &ScatterWindow::logLine,
this, &MainWindow::logLine);
QMdiSubWindow *plotWindow = ui->mdiArea->addSubWindow(scatterWindow);
plotWindow->setWindowFlags(Qt::WindowCloseButtonHint);
plotWindow->setAttribute(Qt::WA_DeleteOnClose, true);
plotWindow->setWindowTitle("Scatter " + winID);
plotWindow->setWindowIcon(QIcon(":/icons/icon.png"));
plotWindow->show();
_ScatterCount++;
}
/**
* @brief [Slot] Create new line plot
*/
void MainWindow::on_addLine_clicked()
{
logLine("UI: Creating line plot");
static uint8_t _LineCount = 0;
QString winID = QString::number(_LineCount);
// Create line plot
LinePlot *lineplotWindow = new LinePlot("lineWindow_"+winID);
//lineplotWindow->setObjectName("lineWindow_"+winID);
QObject::connect(lineplotWindow, &LinePlot::logLine,
this, &MainWindow::logLine);
QMdiSubWindow *plotWindow = ui->mdiArea->addSubWindow(lineplotWindow);
plotWindow->setWindowFlags(Qt::WindowCloseButtonHint);
plotWindow->setAttribute(Qt::WA_DeleteOnClose, true);
plotWindow->setWindowTitle("Line plot " + winID);
plotWindow->setWindowIcon(QIcon(":/icons/icon.png"));
plotWindow->show();
_LineCount++;
}
///////////////////////////////////////////////////////////////////////////////
////
/// Logging channel data to file
///
///////////////////////////////////////////////////////////////////////////////
/**
* @brief [Slot] Open file dialog when 'Path' button has been click
* Once the path has been selected, update textbox in UI
*/
void MainWindow::on_logfilePathDialog_clicked()
{
QString saveDir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
ui->logfilePath->setText(saveDir);
}
/**
* @brief [Slot] Handle enabling/disabling logging to file
* Handles click events to the 'Enable' checkbox which toggles logging to
* the file. Updates UI and communicates with the MUX
* @param arg1 State of the checkbox
*/
void MainWindow::on_fileloggingEnabled_stateChanged(int arg1)
{
// Checked can have PartiallyChecked and Checked states, so instead
// evaluate if Unchecked
if (arg1 == Qt::Unchecked)
{
ui->overwriteButton->setEnabled(true);
ui->appendButton->setEnabled(true);
ui->logfilePathDialog->setEnabled(true);
ui->logfilePath->setEnabled(true);
ui->logfileName->setEnabled(true);
ui->logfileChSep->setEnabled(true);
// Disable file logging in mux
mux->DisableFileLogging();
}
else
{
ui->overwriteButton->setEnabled(false);
ui->appendButton->setEnabled(false);
ui->logfilePathDialog->setEnabled(false);
ui->logfilePath->setEnabled(false);
ui->logfileName->setEnabled(false);
ui->logfileChSep->setEnabled(false);
// Save file logging settings to file
settings->setValue("fileLogging/append", ui->appendButton->isChecked());
settings->setValue("fileLogging/folder", ui->logfilePath->text());
settings->setValue("fileLogging/fileName", ui->logfileName->text());
settings->setValue("fileLogging/channelSeparator", ui->logfileChSep->text());
// Enable file logging in mux
QString logPath = ui->logfilePath->text()+'/'+ui->logfileName->text();
int retVal = mux->EnableFileLogging(logPath,
ui->appendButton->isChecked(),
ui->logfileChSep->text()[0].cell());
if (retVal != 0)
ui->fileloggingEnabled->setChecked(false);
}
}
/**
* @brief [Slot] Enabled serial data input radio button
* Handler for click event on radio button
*/
void MainWindow::on_enableSerial_clicked()
{
// Return if network thread is running
if (netAdapter->isRunning())
return;
ui->networkGroup->setEnabled(false);
ui->serialGroup->setEnabled(true);
ui->enableSerial->setChecked(true);
}
/**
* @brief [Slot] Enabled network data input radio button
* Handler for click event on radio button
*/
void MainWindow::on_enableNetwork_clicked()
{
// Return if serial thread is running
if (dataAdapter->isRunning())
return;
ui->serialGroup->setEnabled(false);
ui->networkGroup->setEnabled(true);
ui->enableNetwork->setChecked(true);
}