src/gui/widgets/qvalidator.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   398 
   398 
   399     bool ok, overflow;
   399     bool ok, overflow;
   400     qlonglong entered = QLocalePrivate::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow);
   400     qlonglong entered = QLocalePrivate::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow);
   401     if (overflow || !ok)
   401     if (overflow || !ok)
   402         return Invalid;
   402         return Invalid;
   403     if (entered >= b && entered <= t)
   403     if (entered >= b && entered <= t) {
   404         return Acceptable;
   404         locale().toInt(input, &ok);
       
   405         return ok ? Acceptable : Intermediate;
       
   406     }
   405 
   407 
   406     if (entered >= 0) {
   408     if (entered >= 0) {
   407         // the -entered < b condition is necessary to allow people to type
   409         // the -entered < b condition is necessary to allow people to type
   408         // the minus last (e.g. for right-to-left languages)
   410         // the minus last (e.g. for right-to-left languages)
   409         return (entered > t && -entered < b) ? Invalid : Intermediate;
   411         return (entered > t && -entered < b) ? Invalid : Intermediate;
   410     } else {
   412     } else {
   411         return (entered < b) ? Invalid : Intermediate;
   413         return (entered < b) ? Invalid : Intermediate;
   412     }
   414     }
   413 }
   415 }
   414 
   416 
       
   417 /*! \reimp */
       
   418 void QIntValidator::fixup(QString &input) const
       
   419 {
       
   420     QByteArray buff;
       
   421     if (!locale().d()->validateChars(input, QLocalePrivate::IntegerMode, &buff)) {
       
   422         QLocale cl(QLocale::C);
       
   423         if (!cl.d()->validateChars(input, QLocalePrivate::IntegerMode, &buff))
       
   424             return;
       
   425     }
       
   426     bool ok, overflow;
       
   427     qlonglong entered = QLocalePrivate::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow);
       
   428     if (ok && !overflow)
       
   429         input = locale().toString(entered);
       
   430 }
   415 
   431 
   416 /*!
   432 /*!
   417     Sets the range of the validator to only accept integers between \a
   433     Sets the range of the validator to only accept integers between \a
   418     bottom and \a top inclusive.
   434     bottom and \a top inclusive.
   419 */
   435 */
   505     in the German locale, "1,234" will be accepted as the fractional number
   521     in the German locale, "1,234" will be accepted as the fractional number
   506     1.234. In Arabic locales, QDoubleValidator will accept Arabic digits.
   522     1.234. In Arabic locales, QDoubleValidator will accept Arabic digits.
   507 
   523 
   508     In addition, QDoubleValidator is always guaranteed to accept a number
   524     In addition, QDoubleValidator is always guaranteed to accept a number
   509     formatted according to the "C" locale. QDoubleValidator will not accept
   525     formatted according to the "C" locale. QDoubleValidator will not accept
   510     numbers with thousand-seperators.
   526     numbers with thousand-separators.
   511 
   527 
   512     \sa QIntValidator, QRegExpValidator, {Line Edits Example}
   528     \sa QIntValidator, QRegExpValidator, {Line Edits Example}
   513 */
   529 */
   514 
   530 
   515  /*!
   531  /*!