]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Allow only sensible input in ExportGraphToImageDialog input fields
authorMichal Malý <madcatxster@devoid-pointer.net>
Thu, 2 Apr 2015 20:15:05 +0000 (22:15 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Thu, 2 Apr 2015 20:15:05 +0000 (22:15 +0200)
gui/exportgraphtoimagedialog.cpp
gui/exportgraphtoimagedialog.h
gui/exportgraphtoimagedialog.ui

index aebaa9856bfff0467f838cbf183902ad0fa39129..4287b620042f0529cc39e10f8ab71c9208b7949a 100644 (file)
@@ -25,6 +25,8 @@
 #include "ui_exportgraphtoimagedialog.h"
 #include <QtCore/QLocale>
 #include <QtWidgets/QFileDialog>
+#include <QDoubleValidator>
+#include <QIntValidator>
 #include <tuple>
 
 /* Public functions */
@@ -54,6 +56,38 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList<QByteArray> formats, Pa
   ui->qle_dpi->setText(m_locale.toString(params.dpi));
   ui->qcbox_outputFormat->setCurrentIndex(params.formatIdx);
   ui->qck_includeInteg->setChecked(params.includePeaks);
+
+  ui->qle_width->setLocale(m_locale);
+  ui->qle_height->setLocale(m_locale);
+  ui->qle_dpi->setLocale(m_locale);
+  ui->qle_fromX->setLocale(m_locale);
+  ui->qle_fromY->setLocale(m_locale);
+  ui->qle_toX->setLocale(m_locale);
+  ui->qle_toY->setLocale(m_locale);
+
+  m_intValidator = new QIntValidator(this);
+  if (m_intValidator != nullptr) {
+    m_intValidator->setLocale(m_locale);
+    m_intValidator->setRange(0, INT_MAX);
+
+    ui->qle_width->setValidator(m_intValidator);
+    ui->qle_height->setValidator(m_intValidator);
+    ui->qle_dpi->setValidator(m_intValidator);
+  } else
+    Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " unable to create IntValidator. Input fields will not be restricted.");
+
+  m_dblValidator = new QDoubleValidator(this);
+  if (m_dblValidator != nullptr) {
+    m_dblValidator->setLocale(m_locale);
+    m_dblValidator->setRange(-__DBL_MAX__, __DBL_MAX__);
+    m_dblValidator->setDecimals(1000);
+
+    ui->qle_fromX->setValidator(m_dblValidator);
+    ui->qle_fromY->setValidator(m_dblValidator);
+    ui->qle_toX->setValidator(m_dblValidator);
+    ui->qle_toY->setValidator(m_dblValidator);
+  } else
+    Logger::log(Logger::Level::WARNING, ME_SENDER_STR, __QFUNC__ + " unable to create DoubleValidator. Chart range fields will not be restricted.");
 }
 
 void ExportGraphToImageDialog::addSignal(const double fromX, const double fromY, const double toX, const double toY, const std::string& key)
index 7c40e5f39607b7c192104009953c029bb0287094..7ed8c24391e4f330daff5309b4179554a1d3004d 100644 (file)
@@ -29,6 +29,9 @@
 #include <QtWidgets/QDialog>
 #include <QLocale>
 
+class QDoubleValidator;
+class QIntValidator;
+
 namespace Ui {
   class ExportGraphToImageDialog;
 }
@@ -90,6 +93,8 @@ private:
   std::vector<std::string> m_signalKeys;
   QString m_lastUsedPath;
   Parameters m_lastUsedParameters;
+  QDoubleValidator* m_dblValidator;
+  QIntValidator* m_intValidator;
 
   Ui::ExportGraphToImageDialog *ui;
 
index 789763d753a0690699a68ed3a2863870197dbb04..ef03ada6ebdcd431ac927dab4f527ef5e426477d 100644 (file)
@@ -82,6 +82,9 @@
      </item>
      <item row="0" column="1">
       <widget class="QLineEdit" name="qle_width">
+       <property name="inputMethodHints">
+        <set>Qt::ImhDigitsOnly</set>
+       </property>
        <property name="text">
         <string>1000</string>
        </property>
      </item>
      <item row="0" column="3">
       <widget class="QLineEdit" name="qle_height">
+       <property name="inputMethodHints">
+        <set>Qt::ImhDigitsOnly</set>
+       </property>
        <property name="text">
         <string>1000</string>
        </property>
      </item>
      <item row="1" column="1">
       <widget class="QLineEdit" name="qle_dpi">
+       <property name="inputMethodHints">
+        <set>Qt::ImhDigitsOnly</set>
+       </property>
        <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
     <layout class="QGridLayout" name="gridLayout_2">
      <item row="0" column="3">
       <widget class="QLineEdit" name="qle_toX">
+       <property name="inputMethodHints">
+        <set>Qt::ImhFormattedNumbersOnly</set>
+       </property>
        <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
      </item>
      <item row="0" column="1">
       <widget class="QLineEdit" name="qle_fromX">
+       <property name="inputMethodHints">
+        <set>Qt::ImhFormattedNumbersOnly</set>
+       </property>
        <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
      </item>
      <item row="1" column="1">
       <widget class="QLineEdit" name="qle_fromY">
+       <property name="inputMethodHints">
+        <set>Qt::ImhFormattedNumbersOnly</set>
+       </property>
        <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
      </item>
      <item row="1" column="3">
       <widget class="QLineEdit" name="qle_toY">
+       <property name="inputMethodHints">
+        <set>Qt::ImhFormattedNumbersOnly</set>
+       </property>
        <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>