From c673141f3373c139d120682fe9b3ff572d24a1ca Mon Sep 17 00:00:00 2001 From: Srivats P Date: Fri, 14 Sep 2018 20:24:30 +0530 Subject: [PATCH] Bugfix: Remove group separator when converting string to number Fixes #240 --- client/portswindow.cpp | 6 ++++-- client/streamconfigdialog.cpp | 14 ++++++++------ client/xlocale.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 client/xlocale.h diff --git a/client/portswindow.cpp b/client/portswindow.cpp index 4ca85cb..77178d9 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -28,6 +28,8 @@ along with this program. If not, see #include "fileformat.pb.h" +#include "xlocale.h" + #include #include #include @@ -435,7 +437,7 @@ void PortsWindow::on_averagePacketsPerSec_editingFinished() Q_ASSERT(plm->isPort(current)); bool isOk; - double pps = QLocale().toDouble(averagePacketsPerSec->text(), &isOk); + double pps = XLocale().toDouble(averagePacketsPerSec->text(), &isOk); plm->port(current).setAveragePacketRate(pps); } @@ -450,7 +452,7 @@ void PortsWindow::on_averageBitsPerSec_editingFinished() Q_ASSERT(plm->isPort(current)); bool isOk; - double bps = QLocale().toDouble(averageBitsPerSec->text(), &isOk); + double bps = XLocale().toDouble(averageBitsPerSec->text(), &isOk); plm->port(current).setAverageBitRate(bps); } diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index 7b6a209..a78dfc0 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -30,6 +30,8 @@ along with this program. If not, see #include "../common/protocolmanager.h" #include "../common/protocolwidgetfactory.h" +#include "xlocale.h" + #include #include @@ -1124,9 +1126,9 @@ void StreamConfigDialog::StoreCurrentStream() pStream->setNumBursts(leNumBursts->text().toULong(&isOk)); pStream->setBurstSize(lePacketsPerBurst->text().toULong(&isOk)); pStream->setPacketRate( - QLocale().toDouble(lePacketsPerSec->text(), &isOk)); + XLocale().toDouble(lePacketsPerSec->text(), &isOk)); pStream->setBurstRate( - QLocale().toDouble(leBurstsPerSec->text(), &isOk)); + XLocale().toDouble(leBurstsPerSec->text(), &isOk)); } } @@ -1172,7 +1174,7 @@ void StreamConfigDialog::on_lePacketsPerSec_textChanged(const QString &text) if (rbSendPackets->isChecked()) { - double pktsPerSec = QLocale().toDouble(text, &isOk); + double pktsPerSec = XLocale().toDouble(text, &isOk); double bitsPerSec = pktsPerSec * double((frameLen+kEthFrameOverHead)*8); if (rbPacketsPerSec->isChecked()) @@ -1197,7 +1199,7 @@ void StreamConfigDialog::on_leBurstsPerSec_textChanged(const QString &text) if (rbSendBursts->isChecked()) { - double burstsPerSec = QLocale().toDouble(text, &isOk); + double burstsPerSec = XLocale().toDouble(text, &isOk); double bitsPerSec = burstsPerSec * double(burstSize * (frameLen + kEthFrameOverHead) * 8); if (rbBurstsPerSec->isChecked()) @@ -1222,13 +1224,13 @@ void StreamConfigDialog::on_leBitsPerSec_textEdited(const QString &text) if (rbSendPackets->isChecked()) { - double pktsPerSec = QLocale().toDouble(text, &isOk)/ + double pktsPerSec = XLocale().toDouble(text, &isOk)/ double((frameLen+kEthFrameOverHead)*8); lePacketsPerSec->setText(QString("%L1").arg(pktsPerSec, 0, 'f', 4)); } else if (rbSendBursts->isChecked()) { - double burstsPerSec = QLocale().toDouble(text, &isOk)/ + double burstsPerSec = XLocale().toDouble(text, &isOk)/ double(burstSize * (frameLen + kEthFrameOverHead) * 8); leBurstsPerSec->setText(QString("%L1").arg(burstsPerSec, 0, 'f', 4)); } diff --git a/client/xlocale.h b/client/xlocale.h new file mode 100644 index 0000000..c313964 --- /dev/null +++ b/client/xlocale.h @@ -0,0 +1,35 @@ +/* +Copyright (C) 2018 Srivats P. + +This file is part of "Ostinato" + +This is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ + +#ifndef _X_LOCALE_H +#define _X_LOCALE_H + +#include + +class XLocale: public QLocale +{ +public: + double toDouble(const QString &s, bool *ok = Q_NULLPTR) const { + QString s2 = s; + return QLocale::toDouble(s2.remove(groupSeparator()), ok); + } +}; + +#endif +