A validator for an input field which only accepts decimals. Source code adapted from StackOverflow
Definition at line 12 of file StrictDoubleValidator.h.
#include <StrictDoubleValidator.h>
◆ StrictDoubleValidator() [1/2]
| StrictDoubleValidator::StrictDoubleValidator |
( |
double | min, |
|
|
double | max, |
|
|
std::size_t | decimals, |
|
|
QObject * | parent = nullptr ) |
|
inline |
◆ StrictDoubleValidator() [2/2]
| StrictDoubleValidator::StrictDoubleValidator |
( |
QObject * | parent = nullptr | ) |
|
|
inlineexplicit |
◆ validate()
| QValidator::State StrictDoubleValidator::validate |
( |
QString & | input, |
|
|
int & | pos ) const |
|
inlineoverride |
Definition at line 23 of file StrictDoubleValidator.h.
24 {
25 Q_UNUSED(pos);
26 if (input.isEmpty() || input == "." || input == "-") return Intermediate;
27
28 QChar const decimalPoint('.');
29 if (input.indexOf(decimalPoint) != -1)
30 {
31 int const charsAfterPoint = input.length() - input.indexOf(decimalPoint) - 1;
32 if (charsAfterPoint > decimals())
33 return QValidator::Invalid;
34 }
35
36 bool ok;
37 double const d = input.toDouble(&ok);
38
39 if (ok && d >= bottom() && d <= top())
40 return QValidator::Acceptable;
41 else
42 return QValidator::Invalid;
43 }
The documentation for this class was generated from the following file: