Skip to content

Commit

Permalink
DataTab: Fix "Show latest" mode
Browse files Browse the repository at this point in the history
This bug is fixed
#57 (comment)
  • Loading branch information
wh201906 committed Apr 5, 2024
1 parent 5743603 commit 92c4db7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
40 changes: 14 additions & 26 deletions src/datatab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ DataTab::DataTab(QByteArray* RxBuf, QVector<Metadata>* 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()
Expand Down Expand Up @@ -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());
Expand All @@ -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)
{
Expand Down Expand Up @@ -486,19 +472,12 @@ void DataTab::appendReceivedData(const QByteArray &data, const QVector<Metadata>
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)
Expand Down Expand Up @@ -555,7 +534,16 @@ void DataTab::appendReceivedData(const QByteArray &data, const QVector<Metadata>
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)
Expand Down
4 changes: 0 additions & 4 deletions src/datatab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -87,8 +85,6 @@ private slots:
QTimer* repeatTimer;

QScrollBar* RxSlider;
int currRxSliderPos = 0;
int userRequiredRxSliderPos = 0;

bool isReceivedDataHex = false;
bool isSendedDataHex = false;
Expand Down

0 comments on commit 92c4db7

Please sign in to comment.