Engauge Digitizer  2
DlgValidatorNumber.cpp
1 #include "DlgValidatorNumber.h"
2 #include "Logger.h"
3 
5  QObject *parent) :
6  DlgValidatorAbstract(parent),
7  m_coordScale (coordScale)
8 {
9  LOG4CPP_INFO_S ((*mainCat)) << "DlgValidatorNumber::DlgValidatorNumber";
10 }
11 
12 QValidator::State DlgValidatorNumber::validate (QString &input,
13  int &pos) const
14 {
15  // First do standard check
16  QValidator::State state = QDoubleValidator::validate (input,
17  pos);
18  if (state == QValidator::Acceptable) {
19 
20  if (m_coordScale == COORD_SCALE_LOG) {
21  if (input.toDouble () < 0.0) {
22 
23  // Cannot allow negative number
24  state = QValidator::Invalid;
25 
26  } if (input.toDouble () == 0.0) {
27 
28  // Treat as a leading zero, which is legal
29  state = QValidator::Intermediate;
30  }
31  }
32  }
33 
34  return state;
35 }
DlgValidatorNumber(CoordScale coordScale, QObject *parent=0)
Single constructor.
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...