Bugfix: Remove group separator when converting string to number

Fixes #240
This commit is contained in:
Srivats P 2018-09-14 20:24:30 +05:30
parent 9c319f97e5
commit c673141f33
3 changed files with 47 additions and 8 deletions

View File

@ -28,6 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "fileformat.pb.h" #include "fileformat.pb.h"
#include "xlocale.h"
#include <QFileInfo> #include <QFileInfo>
#include <QInputDialog> #include <QInputDialog>
#include <QItemSelectionModel> #include <QItemSelectionModel>
@ -435,7 +437,7 @@ void PortsWindow::on_averagePacketsPerSec_editingFinished()
Q_ASSERT(plm->isPort(current)); Q_ASSERT(plm->isPort(current));
bool isOk; bool isOk;
double pps = QLocale().toDouble(averagePacketsPerSec->text(), &isOk); double pps = XLocale().toDouble(averagePacketsPerSec->text(), &isOk);
plm->port(current).setAveragePacketRate(pps); plm->port(current).setAveragePacketRate(pps);
} }
@ -450,7 +452,7 @@ void PortsWindow::on_averageBitsPerSec_editingFinished()
Q_ASSERT(plm->isPort(current)); Q_ASSERT(plm->isPort(current));
bool isOk; bool isOk;
double bps = QLocale().toDouble(averageBitsPerSec->text(), &isOk); double bps = XLocale().toDouble(averageBitsPerSec->text(), &isOk);
plm->port(current).setAverageBitRate(bps); plm->port(current).setAverageBitRate(bps);
} }

View File

@ -30,6 +30,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "../common/protocolmanager.h" #include "../common/protocolmanager.h"
#include "../common/protocolwidgetfactory.h" #include "../common/protocolwidgetfactory.h"
#include "xlocale.h"
#include <QButtonGroup> #include <QButtonGroup>
#include <QMessageBox> #include <QMessageBox>
@ -1124,9 +1126,9 @@ void StreamConfigDialog::StoreCurrentStream()
pStream->setNumBursts(leNumBursts->text().toULong(&isOk)); pStream->setNumBursts(leNumBursts->text().toULong(&isOk));
pStream->setBurstSize(lePacketsPerBurst->text().toULong(&isOk)); pStream->setBurstSize(lePacketsPerBurst->text().toULong(&isOk));
pStream->setPacketRate( pStream->setPacketRate(
QLocale().toDouble(lePacketsPerSec->text(), &isOk)); XLocale().toDouble(lePacketsPerSec->text(), &isOk));
pStream->setBurstRate( 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()) if (rbSendPackets->isChecked())
{ {
double pktsPerSec = QLocale().toDouble(text, &isOk); double pktsPerSec = XLocale().toDouble(text, &isOk);
double bitsPerSec = pktsPerSec * double((frameLen+kEthFrameOverHead)*8); double bitsPerSec = pktsPerSec * double((frameLen+kEthFrameOverHead)*8);
if (rbPacketsPerSec->isChecked()) if (rbPacketsPerSec->isChecked())
@ -1197,7 +1199,7 @@ void StreamConfigDialog::on_leBurstsPerSec_textChanged(const QString &text)
if (rbSendBursts->isChecked()) if (rbSendBursts->isChecked())
{ {
double burstsPerSec = QLocale().toDouble(text, &isOk); double burstsPerSec = XLocale().toDouble(text, &isOk);
double bitsPerSec = burstsPerSec * double bitsPerSec = burstsPerSec *
double(burstSize * (frameLen + kEthFrameOverHead) * 8); double(burstSize * (frameLen + kEthFrameOverHead) * 8);
if (rbBurstsPerSec->isChecked()) if (rbBurstsPerSec->isChecked())
@ -1222,13 +1224,13 @@ void StreamConfigDialog::on_leBitsPerSec_textEdited(const QString &text)
if (rbSendPackets->isChecked()) if (rbSendPackets->isChecked())
{ {
double pktsPerSec = QLocale().toDouble(text, &isOk)/ double pktsPerSec = XLocale().toDouble(text, &isOk)/
double((frameLen+kEthFrameOverHead)*8); double((frameLen+kEthFrameOverHead)*8);
lePacketsPerSec->setText(QString("%L1").arg(pktsPerSec, 0, 'f', 4)); lePacketsPerSec->setText(QString("%L1").arg(pktsPerSec, 0, 'f', 4));
} }
else if (rbSendBursts->isChecked()) else if (rbSendBursts->isChecked())
{ {
double burstsPerSec = QLocale().toDouble(text, &isOk)/ double burstsPerSec = XLocale().toDouble(text, &isOk)/
double(burstSize * (frameLen + kEthFrameOverHead) * 8); double(burstSize * (frameLen + kEthFrameOverHead) * 8);
leBurstsPerSec->setText(QString("%L1").arg(burstsPerSec, 0, 'f', 4)); leBurstsPerSec->setText(QString("%L1").arg(burstsPerSec, 0, 'f', 4));
} }

35
client/xlocale.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>
*/
#ifndef _X_LOCALE_H
#define _X_LOCALE_H
#include <QLocale>
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