QtBase  v6.3.1
Public Types | Signals | Public Member Functions | Properties | List of all members
QDoubleValidator Class Reference

The QDoubleValidator class provides range checking of floating-point numbers. \inmodule QtGui. More...

#include <qvalidator.h>

Inheritance diagram for QDoubleValidator:
Inheritance graph
[legend]
Collaboration diagram for QDoubleValidator:
Collaboration graph
[legend]

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)
 

Public Member Functions

 QDoubleValidator (QObject *parent=nullptr)
 
 QDoubleValidator (double bottom, double top, int decimals, QObject *parent=nullptr)
 
 ~QDoubleValidator ()
 
QValidator::State validate (QString &, int &) const override
 
void fixup (QString &input) const override
 
void setRange (double bottom, double top, int decimals)
 
void setRange (double bottom, double top)
 
void setBottom (double)
 
void setTop (double)
 
void setDecimals (int)
 
void setNotation (Notation)
 
double bottom () const
 
double top () const
 
int decimals () const
 
Notation notation () const
 
- Public Member Functions inherited from QValidator
 QValidator (QObject *parent=nullptr)
 
 ~QValidator ()
 
void setLocale (const QLocale &locale)
 
QLocale locale () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

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...
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QValidator
 QValidator (QObjectPrivate &d, QObject *parent)
 
 QValidator (QValidatorPrivate &d, QObject *parent)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

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.

Note
The QLocale::NumberOptions set on the locale() also affect the way the number is interpreted. For example, since QLocale::RejectGroupSeparator is not set by default, the validator will accept group separators. It is thus recommended to use QLocale::toDouble() to obtain the numeric value.
See also
QIntValidator, QRegularExpressionValidator, QLocale::toDouble(), {Line Edits Example}

Definition at line 124 of file qvalidator.h.

Member Enumeration Documentation

◆ Notation

Since
4.3 This enum defines the allowed notations for entering a double.

\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.

Constructor & Destructor Documentation

◆ QDoubleValidator() [1/2]

QDoubleValidator::QDoubleValidator ( QObject parent = nullptr)
explicit

Constructs a validator object with a parent object that accepts any double.

Definition at line 594 of file qvalidator.cpp.

◆ QDoubleValidator() [2/2]

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::~QDoubleValidator ( )

Destroys the validator.

Definition at line 620 of file qvalidator.cpp.

Member Function Documentation

◆ bottom()

double QDoubleValidator::bottom ( ) const
inline

Definition at line 152 of file qvalidator.h.

◆ bottomChanged

void QDoubleValidator::bottomChanged ( double  bottom)
signal

This signal is emitted after the bottom property changed.

See also
QDoubleValidator::top(), QDoubleValidator::setTop(), QDoubleValidator::bottom(), QDoubleValidator::setBottom()
Here is the caller graph for this function:

◆ decimals()

int QDoubleValidator::decimals ( ) const
inline

Definition at line 154 of file qvalidator.h.

◆ decimalsChanged

void QDoubleValidator::decimalsChanged ( int  decimals)
signal

This signal is emitted after the decimals property changed.

Here is the caller graph for this function:

◆ fixup()

void QDoubleValidator::fixup ( QString input) const
overridevirtual
Since
6.3 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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.

Note
If \l decimals() is set to, and the string provides, more than {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.

Here is the call graph for this function:

◆ notation()

QDoubleValidator::Notation QDoubleValidator::notation ( ) const

Definition at line 908 of file qvalidator.cpp.

◆ notationChanged

void QDoubleValidator::notationChanged ( QDoubleValidator::Notation  notation)
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().

Here is the caller graph for this function:

◆ setBottom()

void QDoubleValidator::setBottom ( double  bottom)

Definition at line 853 of file qvalidator.cpp.

Here is the call graph for this function:

◆ setDecimals()

void QDoubleValidator::setDecimals ( int  decimals)

Definition at line 883 of file qvalidator.cpp.

Here is the call graph for this function:

◆ setNotation()

void QDoubleValidator::setNotation ( Notation  newNotation)

Definition at line 898 of file qvalidator.cpp.

◆ setRange() [1/2]

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.

Here is the call graph for this function:

◆ setRange() [2/2]

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.

Note
Setting the number of decimals to -1 effectively sets it to unlimited. This is also the value used by a default-constructed validator.

Definition at line 809 of file qvalidator.cpp.

Here is the caller graph for this function:

◆ setTop()

void QDoubleValidator::setTop ( double  top)

Definition at line 868 of file qvalidator.cpp.

Here is the call graph for this function:

◆ top()

double QDoubleValidator::top ( ) const
inline

Definition at line 153 of file qvalidator.h.

◆ topChanged

void QDoubleValidator::topChanged ( double  top)
signal

This signal is emitted after the top property changed.

See also
QDoubleValidator::top(), QDoubleValidator::setTop(), QDoubleValidator::bottom(), QDoubleValidator::setBottom()
Here is the caller graph for this function:

◆ validate()

QValidator::State QDoubleValidator::validate ( QString input,
int &  pos 
) const
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.

Here is the call graph for this function:
Here is the caller graph for this function:

Property Documentation

◆ bottom

QDoubleValidator::bottom
readwrite

the validator's minimum acceptable value

By default, this property contains a value of -infinity.

See also
setRange()

Definition at line 119 of file qvalidator.h.

◆ decimals

QDoubleValidator::decimals
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.

See also
setRange()

Definition at line 119 of file qvalidator.h.

◆ notation

QDoubleValidator::notation
readwrite

the notation of how a string can describe a number

Since
4.3

By default, this property is set to ScientificNotation.

See also
Notation

Definition at line 119 of file qvalidator.h.

◆ top

QDoubleValidator::top
readwrite

the validator's maximum acceptable value

By default, this property contains a value of infinity.

See also
setRange()

Definition at line 119 of file qvalidator.h.


The documentation for this class was generated from the following files: