From 26d8e29256f40449f4dead75704faa2439614591 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Thu, 2 Apr 2015 22:15:05 +0200 Subject: [PATCH] Allow only sensible input in ExportGraphToImageDialog input fields --- gui/exportgraphtoimagedialog.cpp | 34 ++++++++++++++++++++++++++++++++ gui/exportgraphtoimagedialog.h | 5 +++++ gui/exportgraphtoimagedialog.ui | 21 ++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/gui/exportgraphtoimagedialog.cpp b/gui/exportgraphtoimagedialog.cpp index aebaa98..4287b62 100644 --- a/gui/exportgraphtoimagedialog.cpp +++ b/gui/exportgraphtoimagedialog.cpp @@ -25,6 +25,8 @@ #include "ui_exportgraphtoimagedialog.h" #include #include +#include +#include #include /* Public functions */ @@ -54,6 +56,38 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList 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) diff --git a/gui/exportgraphtoimagedialog.h b/gui/exportgraphtoimagedialog.h index 7c40e5f..7ed8c24 100644 --- a/gui/exportgraphtoimagedialog.h +++ b/gui/exportgraphtoimagedialog.h @@ -29,6 +29,9 @@ #include #include +class QDoubleValidator; +class QIntValidator; + namespace Ui { class ExportGraphToImageDialog; } @@ -90,6 +93,8 @@ private: std::vector m_signalKeys; QString m_lastUsedPath; Parameters m_lastUsedParameters; + QDoubleValidator* m_dblValidator; + QIntValidator* m_intValidator; Ui::ExportGraphToImageDialog *ui; diff --git a/gui/exportgraphtoimagedialog.ui b/gui/exportgraphtoimagedialog.ui index 789763d..ef03ada 100644 --- a/gui/exportgraphtoimagedialog.ui +++ b/gui/exportgraphtoimagedialog.ui @@ -82,6 +82,9 @@ + + Qt::ImhDigitsOnly + 1000 @@ -99,6 +102,9 @@ + + Qt::ImhDigitsOnly + 1000 @@ -116,6 +122,9 @@ + + Qt::ImhDigitsOnly + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -141,6 +150,9 @@ + + Qt::ImhFormattedNumbersOnly + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -162,6 +174,9 @@ + + Qt::ImhFormattedNumbersOnly + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -176,6 +191,9 @@ + + Qt::ImhFormattedNumbersOnly + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -190,6 +208,9 @@ + + Qt::ImhFormattedNumbersOnly + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter -- 2.43.5