Source Code (Use browser search to find items of interest.)

Class Index

qt'QDoubleValidator (./qt-2.1.0/src/widgets/qvalidator.h:87)

class Q_EXPORT QDoubleValidator: public QValidator
{
    Q_OBJECT
    Q_PROPERTY( double bottom READ bottom WRITE setBottom )
    Q_PROPERTY( double top READ top WRITE setTop )
    Q_PROPERTY( int decimals READ decimals WRITE setDecimals )

public:
    QDoubleValidator( QWidget * parent, const char *name = 0 );
    QDoubleValidator( double bottom, double top, int decimals,
		      QWidget * parent, const char *name = 0 );
    ~QDoubleValidator();

    QValidator::State validate( QString &, int & ) const;

    virtual void setRange( double bottom, double top, int decimals = 0 );
    void setBottom( double );
    void setTop( double );
    void setDecimals( int );

    double bottom() const { return b; }
    double top() const { return t; }
    int decimals() const { return d; }

private:
    double b, t;
    int d;

private:	// Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
    QDoubleValidator( const QDoubleValidator & );
    QDoubleValidator& operator=( const QDoubleValidator & );
#endif
};


qt'QDoubleValidator::QDoubleValidator() (./qt-2.1.0/src/widgets/qvalidator.cpp:311)

QDoubleValidator::QDoubleValidator( QWidget * parent, const char *name )
    : QValidator( parent, name )
{
    b = -HUGE_VAL;
    t = HUGE_VAL;
    d = 1000;
}


/*!
  Constructs a validator object which accepts all doubles from \a
  bottom up to and including \a top with at most \a decimals digits
  after the decimal point.
*/


qt'QDoubleValidator::QDoubleValidator() (./qt-2.1.0/src/widgets/qvalidator.cpp:326)

QDoubleValidator::QDoubleValidator( double bottom, double top, int decimals,
				    QWidget * parent, const char* name )
    : QValidator( parent, name )
{
    b = bottom;
    t = top;
    d = decimals;
}


/*!
  Destroys the validator, freeing any storage and other resources
  used.
*/


qt'QDoubleValidator::~QDoubleValidator() (./qt-2.1.0/src/widgets/qvalidator.cpp:341)

QDoubleValidator::~QDoubleValidator()
{
    // nothing
}


/*!  Returns \a Acceptable if \a input contains a number in the legal
  range and format, \a Intermediate if it contains another number, a
  number with too many digits after the decimal point or is empty, and
  \a Invalid if \a input is not a number.
*/

QValidator::State QDoubleValidator::validate( QString & input, int & ) const
{
    QRegExp empty( QString::fromLatin1("^ *-?.? *$") );
    if ( empty.match( input ) >= 0 )
	return QValidator::Valid;
    bool ok = TRUE;
    double tmp = input.toDouble( &ok );
    if ( !ok ) {
	QRegExp expexpexp( QString::fromLatin1("e-?\\d*$"), FALSE );
	int eeePos = expexpexp.match( input ); // EXPlicit EXPonent regEXP!
	int nume = input.contains( 'e', FALSE );
	if ( eeePos > 0 && nume < 2 ) {
	    QString mantissa = input.left( eeePos );
	    tmp = input.toDouble( &ok );
	    if ( ok )
		return QValidator::Valid;
	}
	else if ( eeePos == 0 ) {
	    return QValidator::Valid;
	}
	else {
	    return QValidator::Invalid;
	}
    }

    int i = input.find( '.' );
    if ( i >= 0 ) {
	// has decimal point, now count digits after that
	i++;
	int j = i;
	while( input[j].isDigit() )
	    j++;
	if ( j - i > d )
	    return QValidator::Valid;
    }

    if ( tmp < b || tmp > t )
	return QValidator::Valid;
    else
	return QValidator::Acceptable;
}


/*!
  Sets the validator to accept numbers from \a bottom up to and
  including \a top with at most \a decimals digits after the decimal
  point.
*/


qt'QDoubleValidator::setRange() (./qt-2.1.0/src/widgets/qvalidator.cpp:402)

void QDoubleValidator::setRange( double bottom, double top, int decimals )
{
    b = bottom;
    t = top;
    d = decimals;
}

/*!
  Sets the validator to accept no numbers smaller than \a bottom.

  \sa setRange()
*/


qt'QDoubleValidator::setBottom() (./qt-2.1.0/src/widgets/qvalidator.cpp:415)

void QDoubleValidator::setBottom( double bottom )
{
    setRange( bottom, top(), decimals() );
}

/*!
  Sets the validator to accept no numbers bigger than \a top.

  \sa setRange()
*/


qt'QDoubleValidator::setTop() (./qt-2.1.0/src/widgets/qvalidator.cpp:426)

void QDoubleValidator::setTop( double top )
{
    setRange( bottom(), top, decimals() );
}

/*!
  Sets the maximum number of digits after the decimal point.
*/


qt'QDoubleValidator::setDecimals() (./qt-2.1.0/src/widgets/qvalidator.cpp:435)

void QDoubleValidator::setDecimals( int decimals )
{
    setRange( bottom(), top(), decimals );
}

/*!
  \fn double QDoubleValidator::bottom() const

  Returns the lowest valid number according to this validator.

  \sa top() decimals() setRange()
*/


/*!
  \fn double QDoubleValidator::top() const

  Returns the highest valid number according to this validator.

  \sa bottom() decimals() setRange()
*/


/*!
  \fn int QDoubleValidator::decimals() const

  Returns the largest number of digits a valid number can have after
  its decimal point.

  \sa bottom() top() setRange()
*/