diff --git a/src/datatab.cpp b/src/datatab.cpp index 27efb2b..21e9eaa 100644 --- a/src/datatab.cpp +++ b/src/datatab.cpp @@ -38,8 +38,6 @@ DataTab::DataTab(QByteArray* RxBuf, QVector* RxMetadataBuf, QByteArray connect(ui->sendEdit, &QLineEdit::returnPressed, this, &DataTab::on_sendButton_clicked); connect(repeatTimer, &QTimer::timeout, this, &DataTab::on_sendButton_clicked); - connect(RxSlider, &QScrollBar::valueChanged, this, &DataTab::onRxSliderValueChanged); - connect(RxSlider, &QScrollBar::sliderMoved, this, &DataTab::onRxSliderMoved); } DataTab::~DataTab() @@ -183,7 +181,7 @@ void DataTab::loadPreference() // setChecked() will trigger on_xxx_stateChanged(), but on_xxx_clicked() will not be triggered settings->beginGroup("SerialTest_Data"); ui->receivedHexBox->setChecked(settings->value("Recv_Hex", false).toBool()); - ui->receivedLatestBox->setChecked(settings->value("Recv_Latest", false).toBool()); + ui->receivedLatestBox->setChecked(settings->value("Recv_Latest", true).toBool()); ui->receivedTimestampBox->setChecked(settings->value("Recv_Timestamp", false).toBool()); ui->receivedRealtimeBox->setChecked(settings->value("Recv_Realtime", true).toBool()); ui->sendedHexBox->setChecked(settings->value("Send_Hex", false).toBool()); @@ -207,18 +205,6 @@ void DataTab::on_data_suffixTypeBox_currentIndexChanged(int index) ui->data_suffixEdit->setVisible(index != 2 && index != 3); ui->data_suffixEdit->setPlaceholderText(tr("Suffix") + ((index == 1) ? "(Hex)" : "")); } -void DataTab::onRxSliderValueChanged(int value) -{ - // qDebug() << "valueChanged" << value; - currRxSliderPos = value; -} - -void DataTab::onRxSliderMoved(int value) -{ - // slider is moved by user - // qDebug() << "sliderMoved" << value; - userRequiredRxSliderPos = value; -} void DataTab::on_sendedHexBox_stateChanged(int arg1) { @@ -486,19 +472,12 @@ void DataTab::appendReceivedData(const QByteArray &data, const QVector int cursorPos; int sliderPos; - if(ui->receivedLatestBox->isChecked()) - { - userRequiredRxSliderPos = RxSlider->maximum(); - RxSlider->setSliderPosition(RxSlider->maximum()); - } - else + if(!ui->receivedLatestBox->isChecked()) { - userRequiredRxSliderPos = currRxSliderPos; - RxSlider->setSliderPosition(currRxSliderPos); + // Record slider position + sliderPos = RxSlider->sliderPosition(); } - sliderPos = RxSlider->sliderPosition(); - cursorPos = ui->receivedEdit->textCursor().position(); ui->receivedEdit->moveCursor(QTextCursor::End); if(isReceivedDataHex) @@ -555,7 +534,16 @@ void DataTab::appendReceivedData(const QByteArray &data, const QVector lastReceivedByte = *dataItem.crbegin(); } ui->receivedEdit->textCursor().setPosition(cursorPos); - RxSlider->setSliderPosition(sliderPos); + if(!ui->receivedLatestBox->isChecked()) + { + // Restore slider position + RxSlider->setSliderPosition(sliderPos); + } + else + { + // Sometimes the slider position is a few lines above the maximum position + RxSlider->setSliderPosition(RxSlider->maximum()); + } } void DataTab::on_data_flowDTRBox_clicked(bool checked) diff --git a/src/datatab.h b/src/datatab.h index 2a491b6..8cea11a 100644 --- a/src/datatab.h +++ b/src/datatab.h @@ -62,8 +62,6 @@ private slots: void on_receivedExportButton_clicked(); void on_sendedExportButton_clicked(); void on_data_suffixTypeBox_currentIndexChanged(int index); - void onRxSliderValueChanged(int value); - void onRxSliderMoved(int value); void on_receivedUpdateButton_clicked(); void on_data_flowDTRBox_clicked(bool checked); void on_data_flowRTSBox_clicked(bool checked); @@ -87,8 +85,6 @@ private slots: QTimer* repeatTimer; QScrollBar* RxSlider; - int currRxSliderPos = 0; - int userRequiredRxSliderPos = 0; bool isReceivedDataHex = false; bool isSendedDataHex = false;