From d0f02728cad58a6b4beb51679780775629a56d35 Mon Sep 17 00:00:00 2001 From: Dan Nagle Date: Sat, 22 Aug 2015 13:58:09 -0500 Subject: [PATCH] truncate resends to a one decimal place. thats all that is supported for now. --- src/mainwindow.cpp | 13 ++++--------- src/packet.cpp | 7 +++++++ src/packet.h | 1 + src/settings.cpp | 4 +--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7af7668b..f38290dd 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -657,7 +657,7 @@ void MainWindow::on_savePacketButton_clicked() testPacket.tcpOrUdp = ui->udptcpComboBox->currentText(); testPacket.sendResponse = 0; testPacket.port = ui->packetPortEdit->text().toUInt(); - testPacket.repeat = ui->resendEdit->text().toFloat(); + testPacket.repeat = Packet::oneDecimal(ui->resendEdit->text().toFloat()); testPacket.saveToDB(); packetsSaved = Packet::fetchAllfromDB(""); @@ -708,7 +708,7 @@ void MainWindow::on_testPacketButton_clicked() testPacket.tcpOrUdp = ui->udptcpComboBox->currentText(); testPacket.sendResponse = 0; testPacket.port = ui->packetPortEdit->text().toUInt(); - testPacket.repeat = ui->resendEdit->text().toFloat(); + testPacket.repeat = Packet::oneDecimal(ui->resendEdit->text().toFloat()); if(testPacket.toIP.isEmpty()) { @@ -920,7 +920,7 @@ void MainWindow::on_packetsTable_itemChanged(QTableWidgetItem *item) } if(datatype == "repeat") { - int repeat = newText.toUInt(); + float repeat = Packet::oneDecimal(newText.toFloat()); updatePacket.repeat = repeat; } if(datatype == "tcpOrUdp") @@ -1594,11 +1594,6 @@ void MainWindow::on_actionSubnet_Calculator_triggered() void MainWindow::on_resendEdit_editingFinished() { - //truncate to 1 deciminal place. - float resendVal = ui->resendEdit->text().toFloat(); - resendVal = resendVal * 10; - int resendint = (int) resendVal; - resendVal = (float) resendint; - resendVal = resendVal / 10; + float resendVal = Packet::oneDecimal(ui->resendEdit->text().toFloat()); ui->resendEdit->setText(QString::number(resendVal)); } diff --git a/src/packet.cpp b/src/packet.cpp index 333b63e0..4582217f 100755 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -50,6 +50,13 @@ bool Packet::isTCP() return (tcpOrUdp.trimmed().toLower() == "tcp"); } +float Packet::oneDecimal(float value) { + float valueFloat = value * 10; + int valueInt = (int) valueFloat; + valueFloat = ((float) valueInt) / 10; + return valueFloat; +} + Packet::~Packet() { init(); diff --git a/src/packet.h b/src/packet.h index 6ce6b554..339ea529 100755 --- a/src/packet.h +++ b/src/packet.h @@ -82,6 +82,7 @@ class Packet QIcon getIcon(); static void sortByName(QList &packetList); static void sortByTime(QList &packetList); + static float oneDecimal(float value); private: static int hexToInt(QChar hex); diff --git a/src/settings.cpp b/src/settings.cpp index bbcd006d..873a04a1 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -128,9 +128,7 @@ void Settings::on_buttonBox_accepted() settings.setValue("cancelResendNum", ui->cancelResendNumEdit->text().toUInt()); - float multiSend = ui->multiSendDelayEdit->text().toFloat() * 10; - int multiSendInt = (int) multiSend; - multiSend = ((float) multiSendInt) / 10; + float multiSend = Packet::oneDecimal(ui->multiSendDelayEdit->text().toFloat()); settings.setValue("multiSendDelay", multiSend);