Skip to content

Commit a3503e6

Browse files
author
Mich
committed
Fixed app messages missing new-line
1 parent c411720 commit a3503e6

File tree

3 files changed

+124
-126
lines changed

3 files changed

+124
-126
lines changed

src/mainwindow.cpp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void MainWindow::settingsLoadAll()
257257
appSettings.value("Info/applicationName").value<QString>() != appSettings.applicationName())
258258
{
259259
qDebug() << "Abort loading settings ! organizationName or applicationName incorrect. Config file might be missing.";
260-
addLog("App >>\t Error loading settings. Config file incorrect !");
260+
addLog("App >>\t Error loading settings. Config file incorrect !",true);
261261
return;
262262
}
263263
}
@@ -866,11 +866,11 @@ void MainWindow::on_updateSerialDeviceList()
866866
void MainWindow::on_pushButtonRefresh_clicked()
867867
{
868868
qDebug() << "Refreshing serial device list...";
869-
this->addLog("App >>\t Searching for COM ports...");
869+
this->addLog("App >>\t Searching for COM ports...",true);
870870
this->on_updateSerialDeviceList();
871871
}
872872

873-
void MainWindow::addLog(QString text)
873+
void MainWindow::addLog(QString text, bool appendAsLine)
874874
{
875875
if (ui->pushButtonTextLogToggle->isChecked() == false)
876876
{
@@ -879,9 +879,7 @@ void MainWindow::addLog(QString text)
879879
if (ui->checkBoxShowTime->isChecked())
880880
text = currentDateTime + text;
881881

882-
// while (text.endsWith('\n') || text.endsWith('\r'))
883-
// text.chop(1);
884-
if (ui->comboBoxAddTextMode->currentIndex() == 0)
882+
if (!appendAsLine)
885883
{
886884
int sliderPosVertical = ui->textBrowserLogs->verticalScrollBar()->value();
887885
int sliderPosHorizontal = ui->textBrowserLogs->horizontalScrollBar()->value();
@@ -897,14 +895,14 @@ void MainWindow::addLog(QString text)
897895
else
898896
ui->textBrowserLogs->verticalScrollBar()->setValue( ui->textBrowserLogs->verticalScrollBar()->maximum());
899897
}
900-
else if (ui->comboBoxAddTextMode->currentIndex() == 1)
898+
else
901899
{
902900
ui->textBrowserLogs->appendPlainText(text);
903901
}
904902
}
905903
}
906904

907-
void MainWindow::addLogBytes(QByteArray bytes, bool hexToBinary)
905+
void MainWindow::addLogBytes(QByteArray bytes, bool hexToBinary, bool appendAsLine)
908906
{
909907
if (ui->pushButtonTextLogToggle->isChecked() == false)
910908
{
@@ -925,7 +923,7 @@ void MainWindow::addLogBytes(QByteArray bytes, bool hexToBinary)
925923
if (ui->checkBoxShowTime->isChecked())
926924
bytesText = currentDateTime + bytesText;
927925

928-
if (ui->comboBoxAddTextMode->currentIndex() == 0)
926+
if (!appendAsLine)
929927
{
930928
int sliderPosVertical = ui->textBrowserLogs->verticalScrollBar()->value();
931929
int sliderPosHorizontal = ui->textBrowserLogs->horizontalScrollBar()->value();
@@ -941,7 +939,7 @@ void MainWindow::addLogBytes(QByteArray bytes, bool hexToBinary)
941939
ui->textBrowserLogs->verticalScrollBar()->setValue( ui->textBrowserLogs->verticalScrollBar()->maximum());
942940

943941
}
944-
else if (ui->comboBoxAddTextMode->currentIndex() == 1)
942+
else
945943
{
946944
ui->textBrowserLogs->appendPlainText(bytesText);
947945
}
@@ -972,15 +970,15 @@ void MainWindow::on_processSerial()
972970

973971
if (ui->comboBoxFormat->currentIndex() == 0 && serialInput.isEmpty() == false)
974972
{
975-
addLog(serialInput);
973+
addLog(serialInput, ui->comboBoxAddTextMode->currentIndex());
976974
}
977975
else if (ui->comboBoxFormat->currentIndex() == 1 && serialInput.length() > 0)
978976
{
979-
addLogBytes(serialInput.toUtf8());
977+
addLogBytes(serialInput.toUtf8(), false, ui->comboBoxAddTextMode->currentIndex());
980978
}
981979
else if (ui->comboBoxFormat->currentIndex() == 2 && serialInput.length() > 0)
982980
{
983-
addLogBytes(serialInput.toUtf8(), true);
981+
addLogBytes(serialInput.toUtf8(), true, ui->comboBoxAddTextMode->currentIndex());
984982
}
985983

986984
if (serialInput.isEmpty() == false)
@@ -1025,11 +1023,11 @@ void MainWindow::on_processUDP()
10251023
}
10261024
else if (ui->comboBoxFormat->currentIndex() == 1 && udpInput.length() > 0)
10271025
{
1028-
addLogBytes(udpInput.toUtf8());
1026+
addLogBytes(udpInput.toUtf8(),false, ui->comboBoxAddTextMode->currentIndex());
10291027
}
10301028
else if (ui->comboBoxFormat->currentIndex() == 2 && udpInput.length() > 0)
10311029
{
1032-
addLogBytes(udpInput.toUtf8(), true);
1030+
addLogBytes(udpInput.toUtf8(), true, ui->comboBoxAddTextMode->currentIndex());
10331031
}
10341032

10351033
if (udpInput.isEmpty() == false)
@@ -1050,7 +1048,7 @@ void MainWindow::sendUDPDatagram(QString message)
10501048
{
10511049
if (!networkUDP.isOpen())
10521050
{
1053-
addLog("App >>\t Unable to send - port closed.");
1051+
addLog("App >>\t Unable to send - port closed.", true);
10541052
return;
10551053
}
10561054

@@ -1247,7 +1245,7 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
12471245
void MainWindow::sendSerial(QString message)
12481246
{
12491247
if (!serial.send(message))
1250-
this->addLog("App >>\t Unable to send! Serial port closed !");
1248+
this->addLog("App >>\t Unable to send! Serial port closed !", true);
12511249
}
12521250

12531251
void MainWindow::saveToRAM(QStringList newlabelList, QList<double> newDataList, QList<long> newTimeList, bool saveText, QString text)
@@ -1590,8 +1588,8 @@ void MainWindow::on_pushButtonSerialConnect_toggled(bool checked)
15901588
{
15911589
if (serial.getAvailiblePortsCount() < 1)
15921590
{
1593-
addLog("App >>\t No devices available");
1594-
addLog("App >>\t Unable to open serial port!");
1591+
addLog("App >>\t No devices available", true);
1592+
addLog("App >>\t Unable to open serial port!", true);
15951593
ui->pushButtonSerialConnect->setChecked(false);
15961594
return;
15971595
}
@@ -1613,13 +1611,13 @@ void MainWindow::on_pushButtonSerialConnect_toggled(bool checked)
16131611

16141612
connect(serialStringProcessingTimer, SIGNAL(timeout()), this, SLOT(on_processSerial()));
16151613

1616-
addLog("App >>\t Serial port opened. " + serial.getSerialInfo() + " DTR: " + QString::number(ui->checkBoxDTR->isChecked()));
1614+
addLog("App >>\t Serial port opened. " + serial.getSerialInfo() + " DTR: " + QString::number(ui->checkBoxDTR->isChecked()), true);
16171615
ui->pushButtonSerialConnect->setText("Disconnect");
16181616
}
16191617
else
16201618
{
16211619
ui->pushButtonSerialConnect->setChecked(false);
1622-
addLog("App >>\t Unable to open serial port!");
1620+
addLog("App >>\t Unable to open serial port!", true);
16231621
}
16241622
}
16251623
else
@@ -1630,13 +1628,13 @@ void MainWindow::on_pushButtonSerialConnect_toggled(bool checked)
16301628

16311629
if (serial.end())
16321630
{
1633-
addLog("App >>\t Connection closed.");
1631+
addLog("App >>\t Connection closed.", true);
16341632
ui->pushButtonSerialConnect->setText("Connect");
16351633
}
16361634
else
16371635
{
16381636
ui->pushButtonSerialConnect->setChecked(true);
1639-
addLog("App >>\t ERROR: Unable to close cennection !");
1637+
addLog("App >>\t ERROR: Unable to close cennection !", true);
16401638
}
16411639

16421640
if (!ui->pushButtonSerialConnect->isChecked() && !ui->pushButtonUDPConnect->isChecked())
@@ -1651,7 +1649,7 @@ void MainWindow::on_actionSave_As_triggered()
16511649

16521650
if (fileName.isEmpty())
16531651
{
1654-
addLog("App >>\t Saving file aborted - filename not specified.");
1652+
addLog("App >>\t Saving file aborted - filename not specified.", true);
16551653
return;
16561654
}
16571655
else
@@ -1796,13 +1794,13 @@ void MainWindow::on_pushButtonUDPConnect_toggled(bool checked)
17961794

17971795
connect(udpStringProcessingTimer, SIGNAL(timeout()), this, SLOT(on_processUDP()));
17981796

1799-
addLog("App >>\t UDP port opened.");
1797+
addLog("App >>\t UDP port opened.", true);
18001798

18011799
ui->pushButtonUDPConnect->setText("Close Connection");
18021800
}
18031801
else
18041802
{
1805-
addLog("App >>\t UDP error. Unable to bind");
1803+
addLog("App >>\t UDP error. Unable to bind",true);
18061804
}
18071805
}
18081806
else
@@ -1811,7 +1809,7 @@ void MainWindow::on_pushButtonUDPConnect_toggled(bool checked)
18111809
{
18121810
udpStringProcessingTimer->stop();
18131811

1814-
addLog("App >>\t UDP port closed.");
1812+
addLog("App >>\t UDP port closed.",true);
18151813

18161814
disconnect(udpStringProcessingTimer, SIGNAL(timeout()), this, SLOT(on_processUDP()));
18171815

@@ -1861,7 +1859,7 @@ void MainWindow::on_pushButtonLogging_toggled(bool checked)
18611859
{
18621860
if (ui->checkBoxAutoLogging->isChecked() == false && ui->lineEditSaveFileName->text().isEmpty())
18631861
{
1864-
addLog("App >>\t logger error - filename not specified !");
1862+
addLog("App >>\t logger error - filename not specified !", true);
18651863
ui->pushButtonLogging->setChecked(false);
18661864
return;
18671865
}
@@ -1872,7 +1870,7 @@ void MainWindow::on_pushButtonLogging_toggled(bool checked)
18721870
{
18731871
if (!fileLogger.beginLog(ui->lineEditSaveLogPath->text(), ui->checkBoxAutoLogging->isChecked(), ui->lineEditSaveFileName->text()))
18741872
{
1875-
addLog("App >>\t logger error - unable to open File");
1873+
addLog("App >>\t logger error - unable to open File",true);
18761874
ui->pushButtonLogging->setChecked(false);
18771875
return;
18781876
}
@@ -2116,18 +2114,18 @@ void MainWindow::on_pushButtonLoadFile_clicked()
21162114

21172115
if (fileReader.readAllAtOnce(&inputFile))
21182116
{
2119-
addLog("App >>\t Read file succesfully... ");
2117+
addLog("App >>\t Read file succesfully... ",true);
21202118
}
21212119
else
21222120
{
2123-
addLog("App >>\t invalid file !");
2121+
addLog("App >>\t invalid file !",true);
21242122
ui->pushButtonLoadFile->setText("Load File");
21252123
ui->progressBarLoadFile->setValue(0);
21262124
}
21272125
}
21282126
else
21292127
{
2130-
addLog("App >>\t file reader error - invalid file path !");
2128+
addLog("App >>\t file reader error - invalid file path !",true);
21312129
ui->pushButtonLoadFile->setText("Load File");
21322130
ui->progressBarLoadFile->setValue(0);
21332131
}
@@ -2242,7 +2240,7 @@ void MainWindow::on_comboBoxAddTextMode_currentIndexChanged(int index)
22422240
if (index == 1)
22432241
{
22442242
ui->radioButtonScrollToButtom->setCheckable(false);
2245-
// ui->radioButtonScrollToButtom->setChecked(false);
2243+
// ui->radioButtonScrollToButtom->setChecked(false);
22462244
}
22472245
else
22482246
{

src/mainwindow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private slots:
161161
Serial serial;
162162
Ui::MainWindow *ui;
163163
Highlighter *highlighter;
164-
void addLog(QString text);
164+
void addLog(QString text, bool appendAsLine = false);
165165
void chartPrintPreview();
166166
void clearGraphData(bool replot);
167167
void clearGraphs(bool replot);
@@ -182,7 +182,7 @@ private slots:
182182
void setupGUI();
183183
void setupTable();
184184
void writeLogToFile(QString rawLine, QStringList labelList, QList<double> dataList, QList<long> timeList);
185-
void addLogBytes(QByteArray bytes, bool hexToBinary = false);
185+
void addLogBytes(QByteArray bytes, bool hexToBinary = false, bool appendAsLine = false);
186186
protected:
187187
void keyPressEvent(QKeyEvent *event);
188188
};

0 commit comments

Comments
 (0)