Engauge Digitizer 2
Loading...
Searching...
No Matches
DlgValidatorNumber.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
8#include "Logger.h"
9#include <QDoubleValidator>
10#include <QLocale>
11
13 const QLocale &locale,
14 QObject *parent) :
16 m_coordScale (coordScale),
17 m_locale (locale)
18{
19 LOG4CPP_INFO_S ((*mainCat)) << "DlgValidatorNumber::DlgValidatorNumber";
20}
21
23 int &pos) const
24{
25 // First do standard check
26 QDoubleValidator validator;
27 validator.setLocale (m_locale);
28 QValidator::State state = validator.validate (input,
29 pos);
30 if (state == QValidator::Acceptable) {
31
32 if (m_coordScale == COORD_SCALE_LOG) {
33 if (m_locale.toDouble (input) < 0.0) {
34
35 // Cannot allow negative number
36 state = QValidator::Invalid;
37
38 } if (m_locale.toDouble (input) == 0.0) {
39
40 // Treat as a leading zero, which is legal
41 state = QValidator::Intermediate;
42 }
43 }
44 }
45
46 return state;
47}
CoordScale
Definition CoordScale.h:12
@ COORD_SCALE_LOG
Definition CoordScale.h:14
const int INNER_RADIUS_MIN
log4cpp::Category * mainCat
Definition Logger.cpp:14
Abstract validator for all numeric formats.
virtual QValidator::State validate(QString &input, int &pos) const =0
Validate according to the numeric format specific to the leaf class.
DlgValidatorNumber(CoordScale coordScale, const QLocale &locale, QObject *parent=0)
Single constructor.
virtual QValidator::State validate(QString &input, int &pos) const
Apply the standard validation with 0 as the exclusive minimum. Call setCoordScale just before calling...
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18