QtBase
v6.3.1
|
The QDoubleValidator class provides range checking of floating-point numbers. \inmodule QtGui. More...
#include <qvalidator.h>
Public Types | |
enum | Notation { StandardNotation , ScientificNotation } |
Public Types inherited from QValidator | |
enum | State { Invalid , Intermediate , Acceptable } |
Signals | |
void | bottomChanged (double bottom) |
void | topChanged (double top) |
void | decimalsChanged (int decimals) |
void | notationChanged (QDoubleValidator::Notation notation) |
Signals inherited from QValidator | |
void | changed () |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Properties | |
double | bottom |
the validator's minimum acceptable value More... | |
double | top |
the validator's maximum acceptable value More... | |
int | decimals |
the validator's maximum number of digits after the decimal point More... | |
Notation | notation |
the notation of how a string can describe a number More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
The QDoubleValidator class provides range checking of floating-point numbers. \inmodule QtGui.
QDoubleValidator provides an upper bound, a lower bound, and a limit on the number of digits after the decimal point.
You can set the acceptable range in one call with setRange(), or with setBottom() and setTop(). Set the number of decimal places with setDecimals(). The validate() function returns the validation state.
QDoubleValidator uses its locale() to interpret the number. For example, in the German locale, "1,234" will be accepted as the fractional number 1.234. In Arabic locales, QDoubleValidator will accept Arabic digits.
Definition at line 124 of file qvalidator.h.
\value StandardNotation The string is written as a standard number (i.e. 0.015). \value ScientificNotation The string is written in scientific form. It may have an exponent part(i.e. 1.5E-2).
Enumerator | |
---|---|
StandardNotation | |
ScientificNotation |
Definition at line 137 of file qvalidator.h.
Constructs a validator object with a parent object that accepts any double.
Definition at line 594 of file qvalidator.cpp.
QDoubleValidator::QDoubleValidator | ( | double | bottom, |
double | top, | ||
int | decimals, | ||
QObject * | parent = nullptr |
||
) |
Constructs a validator object with a parent object. This validator will accept doubles from bottom to top inclusive, with up to decimals digits after the decimal point.
Definition at line 606 of file qvalidator.cpp.
QDoubleValidator::~QDoubleValidator | ( | ) |
Destroys the validator.
Definition at line 620 of file qvalidator.cpp.
|
inline |
Definition at line 152 of file qvalidator.h.
|
signal |
This signal is emitted after the bottom property changed.
|
inline |
Definition at line 154 of file qvalidator.h.
|
signal |
This signal is emitted after the decimals property changed.
Attempts to fix the input string to an \l Acceptable representation of a double.
The format of the number is determined by \l notation(), \l decimals(), \l locale() and the latter's \l {QLocale::}{numberOptions()}.
To comply with \l notation(), when \l ScientificNotation is used, the fixed value will be represented in its normalized form, which means that any non-zero value will have one non-zero digit before the decimal point.
To comply with \l decimals(), when it is {-1}
the number of digits used will be determined by \l QLocale::FloatingPointShortest. Otherwise, the fractional part of the number is truncated (with rounding, as appropriate) if its length exceeds \l decimals(). When \l notation() is \l ScientificNotation this is done after the number has been put into its normalized form.
{std::numeric_limits<double>::digits10}
, digits beyond that many in the fractional part may be changed. The resulting string shall encode the same floating-point number, when parsed to a double
. Reimplemented from QValidator.
Definition at line 745 of file qvalidator.cpp.
QDoubleValidator::Notation QDoubleValidator::notation | ( | ) | const |
Definition at line 908 of file qvalidator.cpp.
|
signal |
This signal is emitted after the notation property changed.
QDoubleValidator::Notation is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType().
void QDoubleValidator::setBottom | ( | double | bottom | ) |
void QDoubleValidator::setDecimals | ( | int | decimals | ) |
Definition at line 898 of file qvalidator.cpp.
void QDoubleValidator::setRange | ( | double | minimum, |
double | maximum | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Sets the validator to accept doubles from minimum to maximum inclusive without changing the number of digits after the decimal point.
Definition at line 839 of file qvalidator.cpp.
void QDoubleValidator::setRange | ( | double | minimum, |
double | maximum, | ||
int | decimals | ||
) |
Sets the validator to accept doubles from minimum to maximum inclusive, with at most decimals digits after the decimal point.
Definition at line 809 of file qvalidator.cpp.
void QDoubleValidator::setTop | ( | double | top | ) |
|
inline |
Definition at line 153 of file qvalidator.h.
|
signal |
This signal is emitted after the top property changed.
|
overridevirtual |
Returns \l Acceptable if the string input contains a double that is within the valid range and is in the correct format.
Returns \l Intermediate if input contains a double that is outside the range or is in the wrong format; e.g. is empty.
Returns \l Invalid if the input is not a double or with too many digits after the decimal point.
Note: If the valid range consists of just positive doubles (e.g. 0.0 to 100.0) and input is a negative double then \l Invalid is returned. If notation() is set to StandardNotation, and the input contains more digits before the decimal point than a double in the valid range may have, \l Invalid is returned. If notation() is ScientificNotation, and the input is not in the valid range, \l Intermediate is returned. The value may yet become valid by changing the exponent.
By default, the pos parameter is not used by this validator.
Implements QValidator.
Reimplemented in QT_BEGIN_NAMESPACE::ZoomFactorValidator.
Definition at line 651 of file qvalidator.cpp.
|
readwrite |
the validator's minimum acceptable value
By default, this property contains a value of -infinity.
Definition at line 119 of file qvalidator.h.
|
readwrite |
the validator's maximum number of digits after the decimal point
By default, this property contains a value of -1, which means any number of digits is accepted.
Definition at line 119 of file qvalidator.h.
|
readwrite |
the notation of how a string can describe a number
By default, this property is set to ScientificNotation.
Definition at line 119 of file qvalidator.h.
|
readwrite |
the validator's maximum acceptable value
By default, this property contains a value of infinity.
Definition at line 119 of file qvalidator.h.