Changeset 846 for trunk/src/gui/widgets/qvalidator.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/widgets/qvalidator.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 401 401 if (overflow || !ok) 402 402 return Invalid; 403 if (entered >= b && entered <= t) 404 return Acceptable; 403 if (entered >= b && entered <= t) { 404 locale().toInt(input, &ok); 405 return ok ? Acceptable : Intermediate; 406 } 405 407 406 408 if (entered >= 0) { … … 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 /*! … … 484 500 485 501 QDoubleValidator::Notation notation; 502 503 QValidator::State validateWithLocale(QString & input, QLocalePrivate::NumberMode numMode, const QLocale &locale) const; 486 504 }; 487 505 … … 508 526 In addition, QDoubleValidator is always guaranteed to accept a number 509 527 formatted according to the "C" locale. QDoubleValidator will not accept 510 numbers with thousand-sep erators.528 numbers with thousand-separators. 511 529 512 530 \sa QIntValidator, QRegExpValidator, {Line Edits Example} … … 639 657 } 640 658 659 State currentLocaleValidation = d->validateWithLocale(input, numMode, locale()); 660 if (currentLocaleValidation == Acceptable || locale().language() == QLocale::C) 661 return currentLocaleValidation; 662 State cLocaleValidation = d->validateWithLocale(input, numMode, QLocale(QLocale::C)); 663 return qMax(currentLocaleValidation, cLocaleValidation); 664 } 665 666 QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QLocalePrivate::NumberMode numMode, const QLocale &locale) const 667 { 668 Q_Q(const QDoubleValidator); 641 669 QByteArray buff; 642 if (!locale().d()->validateChars(input, numMode, &buff, dec)) { 643 QLocale cl(QLocale::C); 644 if (!cl.d()->validateChars(input, numMode, &buff, dec)) 645 return Invalid; 646 } 670 if (!locale.d()->validateChars(input, numMode, &buff, q->dec)) 671 return QValidator::Invalid; 647 672 648 673 if (buff.isEmpty()) 649 return Intermediate;650 651 if ( b >= 0 && buff.startsWith('-'))652 return Invalid;653 654 if ( t < 0 && buff.startsWith('+'))655 return Invalid;674 return QValidator::Intermediate; 675 676 if (q->b >= 0 && buff.startsWith('-')) 677 return QValidator::Invalid; 678 679 if (q->t < 0 && buff.startsWith('+')) 680 return QValidator::Invalid; 656 681 657 682 bool ok, overflow; 658 683 double i = QLocalePrivate::bytearrayToDouble(buff.constData(), &ok, &overflow); 659 684 if (overflow) 660 return Invalid;685 return QValidator::Invalid; 661 686 if (!ok) 662 return Intermediate;663 664 if (i >= b && i <=t)665 return Acceptable;666 667 if ( d->notation ==StandardNotation) {668 double max = qMax(qAbs( b), qAbs(t));687 return QValidator::Intermediate; 688 689 if (i >= q->b && i <= q->t) 690 return QValidator::Acceptable; 691 692 if (notation == QDoubleValidator::StandardNotation) { 693 double max = qMax(qAbs(q->b), qAbs(q->t)); 669 694 if (max < LLONG_MAX) { 670 695 qlonglong n = pow10(numDigits(qlonglong(max))) - 1; 671 696 if (qAbs(i) > n) 672 return Invalid;697 return QValidator::Invalid; 673 698 } 674 699 } 675 700 676 return Intermediate;701 return QValidator::Intermediate; 677 702 } 678 703
Note:
See TracChangeset
for help on using the changeset viewer.