Skip to content

Commit 2fe3be2

Browse files
author
Mich
committed
Minor GUI and notification tweaks
1 parent ed8f447 commit 2fe3be2

File tree

3 files changed

+150
-150
lines changed

3 files changed

+150
-150
lines changed

src/mainwindow.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void MainWindow::setupGUI()
347347
ui->comboBoxSerialReadMode->addItem("bytesAvailable | readAll");
348348
ui->comboBoxSerialReadMode->setCurrentIndex(0);
349349

350-
updateDeviceList();
350+
updateSerialDeviceList();
351351

352352
emit on_checkBoxShowLegend_toggled(ui->checkBoxShowLegend->isChecked());
353353

@@ -416,7 +416,7 @@ void MainWindow::createTimers()
416416
this->serialStringProcessingTimer = new QTimer(this);
417417
this->udpStringProcessingTimer = new QTimer(this);
418418

419-
connect(serialDeviceCheckTimer, SIGNAL(timeout()), this, SLOT(updateDeviceList()));
419+
connect(serialDeviceCheckTimer, SIGNAL(timeout()), this, SLOT(updateSerialDeviceList()));
420420
connect(radioButtonTimer, &QTimer::timeout, this, [=]() { ui->radioButtonDeviceUpdate->setChecked(false); });
421421
}
422422

@@ -480,7 +480,7 @@ void MainWindow::createChart()
480480
if (ui->checkBoxEnableTracer->isChecked())
481481
{
482482
createChartTracer();
483-
connect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(showPointValue(QMouseEvent *)));
483+
connect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(tracerShowPointValue(QMouseEvent *)));
484484
}
485485
}
486486

@@ -497,7 +497,7 @@ void MainWindow::chartBeforeReplotSlot()
497497

498498
if (ui->checkBoxAutoRescaleY->isChecked())
499499
{
500-
bool atLeastOneGraphVisible = false, atLeastOneNotFlat = false;
500+
bool atLeastOneGraphVisible = false, atLeastOneGraphIsNotFlat = false;
501501

502502
for (auto i = 0; i < ui->widgetChart->graphCount(); ++i)
503503
{
@@ -508,26 +508,25 @@ void MainWindow::chartBeforeReplotSlot()
508508
bool foundRange = false;
509509
QCPRange valueRange = ui->widgetChart->graph(i)->data().data()->valueRange(foundRange);
510510

511-
if (foundRange && abs(valueRange.upper - valueRange.lower) >= 0.1)
512-
atLeastOneNotFlat = true;
511+
if (foundRange == true && abs(valueRange.upper - valueRange.lower) >= 0.1)
512+
atLeastOneGraphIsNotFlat = true;
513513
}
514514
}
515515

516-
if (atLeastOneGraphVisible && atLeastOneNotFlat)
516+
if (atLeastOneGraphVisible && atLeastOneGraphIsNotFlat)
517517
{
518518
ui->widgetChart->yAxis->rescale(true);
519-
ui->widgetChart->yAxis->scaleRange(1.20);
519+
ui->widgetChart->yAxis->scaleRange(1.20); // leave some space at the top and buttom of the chart.
520520
}
521521
}
522522
}
523523
else
524524
{
525-
// if (ui->widgetChart->graph()->visible() == false)
526-
// ui->widgetChart->rescaleAxes();
525+
// do nothing ?
527526
}
528527
}
529528

530-
void MainWindow::chartContextMenuRequest(QPoint pos)
529+
void MainWindow::chartContextMenuRequest(QPoint pos) // right click on chart
531530
{
532531
QMenu *menu = new QMenu(this);
533532
menu->setAttribute(Qt::WA_DeleteOnClose);
@@ -579,6 +578,7 @@ void MainWindow::chartContextMenuRequest(QPoint pos)
579578
void MainWindow::showSelectedGraphExclusively()
580579
{
581580
hideAllGraphs();
581+
582582
for (auto i = 0; i < ui->widgetChart->graphCount(); ++i)
583583
{
584584
if (ui->widgetChart->graph(i)->selected() || ui->widgetChart->legend->item(i)->selected())
@@ -687,7 +687,7 @@ void MainWindow::chartSelectionChanged()
687687
}
688688
}
689689

690-
void MainWindow::showPointValue(QMouseEvent *event)
690+
void MainWindow::tracerShowPointValue(QMouseEvent *event)
691691
{
692692
if (ui->widgetChart->graphCount() < 1)
693693
return;
@@ -740,14 +740,12 @@ void MainWindow::chartMousePressHandler(QMouseEvent *event)
740740
ui->widgetChart->replot();
741741
}
742742

743-
void MainWindow::updateDeviceList()
743+
void MainWindow::updateSerialDeviceList()
744744
{
745-
QList<QSerialPortInfo> devices;
745+
QList<QSerialPortInfo> devices = QSerialPortInfo::availablePorts();
746746
QList<QString> portNames;
747747
static QList<QString> portNamesOld;
748748

749-
devices = QSerialPortInfo::availablePorts();
750-
751749
foreach (auto item, devices)
752750
{
753751
portNames.append(item.portName());
@@ -777,9 +775,9 @@ void MainWindow::updateDeviceList()
777775

778776
void MainWindow::on_pushButtonRefresh_clicked()
779777
{
780-
qDebug() << "Szukam urządzeń COM...";
781-
this->addLog(">>\t Searching for COM ports...");
782-
this->updateDeviceList();
778+
qDebug() << "Refreshing serial device list...";
779+
this->addLog("App >>\t Searching for COM ports...");
780+
this->updateSerialDeviceList();
783781
}
784782

785783
void MainWindow::addLog(QString text)
@@ -822,6 +820,7 @@ void MainWindow::processSerial()
822820
}
823821
}
824822

823+
// TODO
825824
void MainWindow::writeLogToFile(QString rawLine, QStringList labelList, QList<double> dataList, QList<long> timeList)
826825
{
827826
if (ui->pushButtonLogging->isChecked()) // Write log into file
@@ -908,15 +907,15 @@ void MainWindow::processChart(QStringList labelList, QList<double> numericDataLi
908907
{
909908
if (labelList[j] == ui->widgetChart->graph(i)->name()) // If label matches the graphs name - we can start add points to it
910909
{
911-
if (timeStampsList[j] > 0) // if == 0 then we assume taht no external clock was parsed propely
910+
if (timeStampsList[j] > 0) // if == 0 then we assume that no external clock was parsed propely
912911
ui->widgetChart->graph(i)->addData(timeStampsList[j] / 1000.0, numericDataList[j]);
913912

914-
// break; // we keep checking for duplicates so we can add multiple points at once
913+
// break; // no break - slower but if we keep checking for duplicates, we can add multiple points at once
915914
}
916915
}
917916

918917
if (ui->spinBoxMaxTimeRange->value() > 0)
919-
ui->widgetChart->graph(i)->data().data()->removeBefore((timeStampsList.last() / 1000.0) - ui->spinBoxMaxTimeRange->value()); // Remove old samples
918+
ui->widgetChart->graph(i)->data().data()->removeBefore((timeStampsList.last() / 1000.0) - ui->spinBoxMaxTimeRange->value()); // Remove old points
920919

921920
if (ui->spinBoxRemoveOldLabels->value() > 0)
922921
{
@@ -928,7 +927,7 @@ void MainWindow::processChart(QStringList labelList, QList<double> numericDataLi
928927
if (missingCount[i] > ui->spinBoxRemoveOldLabels->value())
929928
{
930929
ui->widgetChart->removeGraph(i);
931-
missingCount.removeAt(i);
930+
missingCount.removeAt(i); // Remove entry for this label
932931
}
933932
}
934933
}
@@ -1023,7 +1022,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
10231022
}
10241023
}
10251024

1026-
if (event->key() == Qt::Key_F1)
1025+
if (event->key() == Qt::Key::Key_F1)
10271026
{
10281027
QWhatsThis::enterWhatsThisMode();
10291028
}
@@ -1114,11 +1113,11 @@ void MainWindow::on_checkBoxEnableTracer_toggled(bool checked)
11141113
if (checked)
11151114
{
11161115
createChartTracer();
1117-
connect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(showPointValue(QMouseEvent *)));
1116+
connect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(tracerShowPointValue(QMouseEvent *)));
11181117
}
11191118
else
11201119
{
1121-
disconnect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(showPointValue(QMouseEvent *)));
1120+
disconnect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(tracerShowPointValue(QMouseEvent *)));
11221121
delete phaseTracer;
11231122
phaseTracer = nullptr;
11241123
}
@@ -1286,13 +1285,13 @@ void MainWindow::on_comboBoxTracerStyle_currentIndexChanged(const QString &arg1)
12861285
{
12871286
if (phaseTracer != nullptr)
12881287
{
1289-
disconnect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(showPointValue(QMouseEvent *)));
1288+
disconnect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(tracerShowPointValue(QMouseEvent *)));
12901289
delete phaseTracer;
12911290
phaseTracer = nullptr;
12921291
}
12931292

12941293
createChartTracer();
1295-
connect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(showPointValue(QMouseEvent *)));
1294+
connect(ui->widgetChart, SIGNAL(mouseMove(QMouseEvent *)), this, SLOT(tracerShowPointValue(QMouseEvent *)));
12961295

12971296
ui->widgetChart->replot();
12981297
}
@@ -1304,8 +1303,8 @@ void MainWindow::on_pushButtonSerialConnect_toggled(bool checked)
13041303
{
13051304
if (serial.getAvailiblePortsCount() < 1)
13061305
{
1307-
addLog(">>\t No devices available");
1308-
addLog(">>\t Unable to open serial port!");
1306+
addLog("App >>\t No devices available");
1307+
addLog("App >>\t Unable to open serial port!");
13091308
ui->pushButtonSerialConnect->setChecked(false);
13101309
return;
13111310
}
@@ -1329,13 +1328,13 @@ void MainWindow::on_pushButtonSerialConnect_toggled(bool checked)
13291328

13301329
connect(serialStringProcessingTimer, SIGNAL(timeout()), this, SLOT(processSerial()));
13311330

1332-
addLog(">>\t Serial port opened. " + serial.getSerialInfo() + " DTR: " + QString::number(ui->checkBoxDTR->isChecked()));
1331+
addLog("App >>\t Serial port opened. " + serial.getSerialInfo() + " DTR: " + QString::number(ui->checkBoxDTR->isChecked()));
13331332
ui->pushButtonSerialConnect->setText("Disconnect");
13341333
}
13351334
else
13361335
{
13371336
ui->pushButtonSerialConnect->setChecked(false);
1338-
addLog(">>\t Unable to open serial port!");
1337+
addLog("App >>\t Unable to open serial port!");
13391338
}
13401339
}
13411340
else
@@ -1346,13 +1345,13 @@ void MainWindow::on_pushButtonSerialConnect_toggled(bool checked)
13461345

13471346
if (serial.end())
13481347
{
1349-
addLog(">>\t Connection closed.");
1348+
addLog("App >>\t Connection closed.");
13501349
ui->pushButtonSerialConnect->setText("Connect");
13511350
}
13521351
else
13531352
{
13541353
ui->pushButtonSerialConnect->setChecked(true);
1355-
addLog(">>\t ERROR: Unable to close cennection !");
1354+
addLog("App >>\t ERROR: Unable to close cennection !");
13561355
}
13571356

13581357
if (!ui->pushButtonSerialConnect->isChecked() && !ui->pushButtonUDPConnect->isChecked())
@@ -1367,6 +1366,7 @@ void MainWindow::on_actionSave_As_triggered()
13671366

13681367
if (fileName.isEmpty())
13691368
{
1369+
addLog("App >>\t Saving file aborted - filename not specified.");
13701370
return;
13711371
}
13721372
else
@@ -1415,7 +1415,7 @@ void MainWindow::on_actionPlotter_triggered()
14151415

14161416
void MainWindow::on_action3D_orientation_triggered()
14171417
{
1418-
// ui->stackedWidget->setCurrentIndex(1);
1418+
// ui->stackedWidget->setCurrentIndex(1); // WIP
14191419
}
14201420

14211421
void MainWindow::printPlot(QPrinter *printer)
@@ -1511,13 +1511,13 @@ void MainWindow::on_pushButtonUDPConnect_toggled(bool checked)
15111511

15121512
connect(udpStringProcessingTimer, SIGNAL(timeout()), this, SLOT(processUDP()));
15131513

1514-
addLog(">>\t UDP port opened.");
1514+
addLog("App >>\t UDP port opened.");
15151515

15161516
ui->pushButtonUDPConnect->setText("Close Connection");
15171517
}
15181518
else
15191519
{
1520-
addLog(">>\t UDP error. Unable to bind");
1520+
addLog("App >>\t UDP error. Unable to bind");
15211521
}
15221522
}
15231523
else
@@ -1526,7 +1526,7 @@ void MainWindow::on_pushButtonUDPConnect_toggled(bool checked)
15261526
{
15271527
udpStringProcessingTimer->stop();
15281528

1529-
addLog(">>\t UDP port closed.");
1529+
addLog("App >>\t UDP port closed.");
15301530

15311531
disconnect(udpStringProcessingTimer, SIGNAL(timeout()), this, SLOT(processUDP()));
15321532

@@ -1542,7 +1542,7 @@ void MainWindow::sendDatagram(QString message)
15421542
{
15431543
if (!networkUDP.isOpen())
15441544
{
1545-
addLog("UDP\t Unable to send. Port closed.");
1545+
addLog("App >>\t Unable to send - port closed.");
15461546
return;
15471547
}
15481548

@@ -1559,7 +1559,7 @@ void MainWindow::sendDatagram(QString message)
15591559
networkUDP.write(message, QHostAddress(ui->lineEditUDPTargetIP->text()), ui->spinBoxUDPTargetPort->value());
15601560
}
15611561

1562-
addLog("UDP >>\t" + message);
1562+
addLog("App >>\t" + message);
15631563
}
15641564

15651565
void MainWindow::on_comboBoxUDPSendMode_currentIndexChanged(const QString &arg1)
@@ -1597,7 +1597,7 @@ void MainWindow::on_pushButtonLogging_toggled(bool checked)
15971597
{
15981598
if (ui->checkBoxAutoLogging->isChecked() == false && ui->lineEditSaveFileName->text().isEmpty())
15991599
{
1600-
addLog("Logger - Filename not specified !");
1600+
addLog("App >>\t logger error - filename not specified !");
16011601
ui->pushButtonLogging->setChecked(false);
16021602
return;
16031603
}
@@ -1608,7 +1608,7 @@ void MainWindow::on_pushButtonLogging_toggled(bool checked)
16081608
{
16091609
if (!fileLogger.beginLog(ui->lineEditSaveLogPath->text(), ui->checkBoxAutoLogging->isChecked(), ui->lineEditSaveFileName->text()))
16101610
{
1611-
addLog("Logger - Unable to open File");
1611+
addLog("App >>\t logger error - unable to open File");
16121612
ui->pushButtonLogging->setChecked(false);
16131613
return;
16141614
}

src/mainwindow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ private slots:
128128
void processSerial();
129129
void processUDP();
130130
void showAllGraphs();
131-
void showPointValue(QMouseEvent *event);
131+
void tracerShowPointValue(QMouseEvent *event);
132132
void showSelectedGraph();
133133
void showSelectedGraphExclusively();
134-
void updateDeviceList();
134+
void updateSerialDeviceList();
135135
void on_actionUser_guide_triggered();
136136
void on_actionInfo_triggered();
137137
void on_comboBoxLoggingMode_currentIndexChanged(int index);

0 commit comments

Comments
 (0)