From 98ffdcd46d30a536bba82704d0d27892572c6896 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Thu, 2 Apr 2015 20:59:12 +0200 Subject: [PATCH] Use system locale to convert between numbers and their string representations in ExportGraphToImageDialog --- gui/exportgraphtoimagedialog.cpp | 40 +++++++++++++++----------------- gui/exportgraphtoimagedialog.h | 2 ++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gui/exportgraphtoimagedialog.cpp b/gui/exportgraphtoimagedialog.cpp index e054eab..aebaa98 100644 --- a/gui/exportgraphtoimagedialog.cpp +++ b/gui/exportgraphtoimagedialog.cpp @@ -32,6 +32,7 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList formats, Parameters params, QWidget *parent) : QDialog(parent), m_curKey(""), + m_locale(QLocale::system()), ui(new Ui::ExportGraphToImageDialog) { ui->setupUi(this); @@ -48,9 +49,9 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList formats, Pa connect(ui->qle_destPath, SIGNAL(textChanged(QString)), this, SLOT(onFileNameChanged(QString))); ui->qle_destPath->setText(m_lastUsedPath); - ui->qle_width->setText(QString::number(params.width)); - ui->qle_height->setText(QString::number(params.height)); - ui->qle_dpi->setText(QString::number(params.dpi)); + ui->qle_width->setText(m_locale.toString(params.width)); + ui->qle_height->setText(m_locale.toString(params.height)); + ui->qle_dpi->setText(m_locale.toString(params.dpi)); ui->qcbox_outputFormat->setCurrentIndex(params.formatIdx); ui->qck_includeInteg->setChecked(params.includePeaks); } @@ -94,7 +95,7 @@ bool ExportGraphToImageDialog::includePeaks() const int ExportGraphToImageDialog::imageDpi() const { bool ok; - int dpi = ui->qle_dpi->text().toInt(&ok); + int dpi = m_locale.toInt(ui->qle_dpi->text(), &ok); if (!ok) return 0; return dpi; } @@ -102,7 +103,7 @@ int ExportGraphToImageDialog::imageDpi() const int ExportGraphToImageDialog::imageHeight() const { bool ok; - double h = ui->qle_height->text().toInt(&ok); + double h = m_locale.toInt(ui->qle_height->text(), &ok); if (!ok) return 0; return h; } @@ -152,8 +153,7 @@ double ExportGraphToImageDialog::toY() const int ExportGraphToImageDialog::imageWidth() const { bool ok; - double w = ui->qle_width->text().toInt(&ok); - + double w = m_locale.toInt(ui->qle_width->text(), &ok); if (!ok) return 0; return w; } @@ -168,7 +168,6 @@ void ExportGraphToImageDialog::onFormatChanged(const int idx) void ExportGraphToImageDialog::changeBounds(const QString& key) { - QLocale l = QLocale::system(); Bounds oldBounds, newBounds; std::string skey = key.toStdString(); double fX, fY, tX, tY; @@ -177,13 +176,13 @@ void ExportGraphToImageDialog::changeBounds(const QString& key) try { oldBounds = m_bounds.at(m_curKey); - fX = ui->qle_fromX->text().toDouble(&ok); + fX = m_locale.toDouble(ui->qle_fromX->text(), &ok); if (ok) oldBounds.fromX = fX; - fY = ui->qle_fromY->text().toDouble(&ok); + fY = m_locale.toDouble(ui->qle_fromY->text(), &ok); if (ok) oldBounds.fromY = fY; - tX = ui->qle_toX->text().toDouble(&ok); + tX = m_locale.toDouble(ui->qle_toX->text(), &ok); if (ok) oldBounds.toX = tX; - tY = ui->qle_toY->text().toDouble(&ok); + tY = m_locale.toDouble(ui->qle_toY->text(), &ok); if (ok) oldBounds.toY = tY; m_bounds[m_curKey] = oldBounds; @@ -193,10 +192,10 @@ void ExportGraphToImageDialog::changeBounds(const QString& key) try { newBounds = m_bounds.at(skey); - ui->qle_fromX->setText(l.toString(newBounds.fromX)); - ui->qle_fromY->setText(l.toString(newBounds.fromY)); - ui->qle_toX->setText(l.toString(newBounds.toX)); - ui->qle_toY->setText(l.toString(newBounds.toY)); + ui->qle_fromX->setText(m_locale.toString(newBounds.fromX)); + ui->qle_fromY->setText(m_locale.toString(newBounds.fromY)); + ui->qle_toX->setText(m_locale.toString(newBounds.toX)); + ui->qle_toY->setText(m_locale.toString(newBounds.toY)); m_curKey = skey; } catch (std::out_of_range&) { } @@ -207,17 +206,16 @@ void ExportGraphToImageDialog::checkAndAccept() try { double fX, fY, tX, tY; bool ok; - QLocale l = QLocale::system(); const std::string key = ui->qcbox_signal->currentText().toStdString(); Bounds b = m_bounds.at(key); - fX = l.toDouble(ui->qle_fromX->text(), &ok); + fX = m_locale.toDouble(ui->qle_fromX->text(), &ok); if (ok) b.fromX = fX; - fY = l.toDouble(ui->qle_fromY->text(), &ok); + fY = m_locale.toDouble(ui->qle_fromY->text(), &ok); if (ok) b.fromY = fY; - tX = l.toDouble(ui->qle_toX->text(), &ok); + tX = m_locale.toDouble(ui->qle_toX->text(), &ok); if (ok) b.toX = tX; - tY = l.toDouble(ui->qle_toY->text(), &ok); + tY = m_locale.toDouble(ui->qle_toY->text(), &ok); if (ok) b.toY = tY; m_bounds[key] = b; diff --git a/gui/exportgraphtoimagedialog.h b/gui/exportgraphtoimagedialog.h index 3df4f66..7c40e5f 100644 --- a/gui/exportgraphtoimagedialog.h +++ b/gui/exportgraphtoimagedialog.h @@ -27,6 +27,7 @@ #include "helpers.h" #include #include +#include namespace Ui { class ExportGraphToImageDialog; @@ -85,6 +86,7 @@ public: private: std::unordered_map m_bounds; std::string m_curKey; + const QLocale m_locale; std::vector m_signalKeys; QString m_lastUsedPath; Parameters m_lastUsedParameters; -- 2.43.5