Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
DlgValidatorNumber.cpp
1 #include "DlgValidatorNumber.h"
2 #include "Logger.h"
3 #include <QDoubleValidator>
4 #include <QLocale>
5 
7  const QLocale &locale,
8  QObject *parent) :
9  DlgValidatorAbstract(parent),
10  m_coordScale (coordScale),
11  m_locale (locale)
12 {
13  LOG4CPP_INFO_S ((*mainCat)) << "DlgValidatorNumber::DlgValidatorNumber";
14 }
15 
16 QValidator::State DlgValidatorNumber::validate (QString &input,
17  int &pos) const
18 {
19  // First do standard check
20  QDoubleValidator validator;
21  validator.setLocale (m_locale);
22  QValidator::State state = validator.validate (input,
23  pos);
24  if (state == QValidator::Acceptable) {
25 
26  if (m_coordScale == COORD_SCALE_LOG) {
27  if (input.toDouble () < 0.0) {
28 
29  // Cannot allow negative number
30  state = QValidator::Invalid;
31 
32  } if (input.toDouble () == 0.0) {
33 
34  // Treat as a leading zero, which is legal
35  state = QValidator::Intermediate;
36  }
37  }
38  }
39 
40  return state;
41 }
Abstract validator for all numeric formats.
virtual QValidator::State validate(QString &input, int &pos) const
Apply the standard validation with 0 as the exclusive minimum. Call setCoordScale just before calling...
DlgValidatorNumber(CoordScale coordScale, const QLocale &locale, QObject *parent=0)
Single constructor.