]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Use system locale to convert between numbers and their string
authorMichal Malý <madcatxster@devoid-pointer.net>
Thu, 2 Apr 2015 18:59:12 +0000 (20:59 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Thu, 2 Apr 2015 18:59:12 +0000 (20:59 +0200)
representations in ExportGraphToImageDialog

gui/exportgraphtoimagedialog.cpp
gui/exportgraphtoimagedialog.h

index e054eabb622d9f02f2e5e825a7dce221cfc5966e..aebaa9856bfff0467f838cbf183902ad0fa39129 100644 (file)
@@ -32,6 +32,7 @@
 ExportGraphToImageDialog::ExportGraphToImageDialog(QList<QByteArray> 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<QByteArray> 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;
index 3df4f6673d6d085ad47b4f8ffaec6345ee07a669..7c40e5f39607b7c192104009953c029bb0287094 100644 (file)
@@ -27,6 +27,7 @@
 #include "helpers.h"
 #include <unordered_map>
 #include <QtWidgets/QDialog>
+#include <QLocale>
 
 namespace Ui {
   class ExportGraphToImageDialog;
@@ -85,6 +86,7 @@ public:
 private:
   std::unordered_map<std::string, Bounds> m_bounds;
   std::string m_curKey;
+  const QLocale m_locale;
   std::vector<std::string> m_signalKeys;
   QString m_lastUsedPath;
   Parameters m_lastUsedParameters;