Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qspinbox.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5151
    5252#include <math.h>
     53#include <float.h>
    5354
    5455QT_BEGIN_NAMESPACE
     
    6162#endif
    6263
    63 static bool isIntermediateValueHelper(qint64 num, qint64 minimum, qint64 maximum, qint64 *match = 0);
    64 
    6564class QSpinBoxPrivate : public QAbstractSpinBoxPrivate
    6665{
    6766    Q_DECLARE_PUBLIC(QSpinBox)
    6867public:
    69     QSpinBoxPrivate(QWidget *parent = 0);
     68    QSpinBoxPrivate();
    7069    void emitSignals(EmitPolicy ep, const QVariant &);
    7170
     
    7473    QVariant validateAndInterpret(QString &input, int &pos,
    7574                                  QValidator::State &state) const;
    76     bool isIntermediateValue(const QString &str) const;
    77     QChar thousand;
    7875
    7976    inline void init() {
     77        Q_Q(QSpinBox);
     78        q->setInputMethodHints(Qt::ImhDigitsOnly);
    8079        setLayoutItemMargins(QStyle::SE_SpinBoxLayoutItem);
    8180    }
     
    8685    Q_DECLARE_PUBLIC(QDoubleSpinBox)
    8786public:
    88     QDoubleSpinBoxPrivate(QWidget *parent = 0);
     87    QDoubleSpinBoxPrivate();
    8988    void emitSignals(EmitPolicy ep, const QVariant &);
    90     bool isIntermediateValue(const QString &str) const;
    9189
    9290    virtual QVariant valueFromText(const QString &n) const;
     
    9795    // variables
    9896    int decimals;
    99     QChar delimiter, thousand;
     97
     98    inline void init() {
     99        Q_Q(QDoubleSpinBox);
     100        q->setInputMethodHints(Qt::ImhFormattedNumbersOnly);
     101    }
    100102};
    101103
     
    106108
    107109    \ingroup basicwidgets
    108     \mainclass
     110
    109111
    110112    QSpinBox is designed to handle integers and discrete sets of
     
    198200
    199201QSpinBox::QSpinBox(QWidget *parent)
    200     : QAbstractSpinBox(*new QSpinBoxPrivate(parent), parent)
     202    : QAbstractSpinBox(*new QSpinBoxPrivate, parent)
    201203{
    202204    Q_D(QSpinBox);
     
    210212*/
    211213QSpinBox::QSpinBox(QWidget *parent, const char *name)
    212     : QAbstractSpinBox(*new QSpinBoxPrivate(parent), parent)
     214    : QAbstractSpinBox(*new QSpinBoxPrivate, parent)
    213215{
    214216    Q_D(QSpinBox);
     
    222224*/
    223225QSpinBox::QSpinBox(int minimum, int maximum, int step, QWidget *parent, const char *name)
    224     : QAbstractSpinBox(*new QSpinBoxPrivate(parent), parent)
     226    : QAbstractSpinBox(*new QSpinBoxPrivate, parent)
    225227{
    226228    Q_D(QSpinBox);
     
    285287    d->prefix = prefix;
    286288    d->updateEdit();
     289
     290    d->cachedSizeHint = QSize();
     291    updateGeometry();
    287292}
    288293
     
    319324    d->suffix = suffix;
    320325    d->updateEdit();
     326
     327    d->cachedSizeHint = QSize();
     328    updateGeometry();
    321329}
    322330
     
    455463QString QSpinBox::textFromValue(int value) const
    456464{
    457     Q_D(const QSpinBox);
    458465    QString str = locale().toString(value);
    459466    if (qAbs(value) >= 1000 || value == INT_MIN) {
    460         str.remove(d->thousand);
     467        str.remove(locale().groupSeparator());
    461468    }
    462469
     
    507514void QSpinBox::fixup(QString &input) const
    508515{
    509     Q_D(const QSpinBox);
    510 
    511     input.remove(d->thousand);
     516    input.remove(locale().groupSeparator());
    512517}
    513518
     
    521526
    522527    \ingroup basicwidgets
    523     \mainclass
     528
    524529
    525530    QDoubleSpinBox allows the user to choose a value by clicking the
     
    591596*/
    592597QDoubleSpinBox::QDoubleSpinBox(QWidget *parent)
    593     : QAbstractSpinBox(*new QDoubleSpinBoxPrivate(parent), parent)
    594 {
     598    : QAbstractSpinBox(*new QDoubleSpinBoxPrivate, parent)
     599{
     600    Q_D(QDoubleSpinBox);
     601    d->init();
    595602}
    596603
     
    818825     interpreting doubles.
    819826
    820      \warning The results might not be reliable with very high values
    821      for \a decimals.
     827     \warning The maximum value for \a decimals is DBL_MAX_10_EXP +
     828     DBL_DIG (ie. 323) because of the limitations of the double type.
    822829
    823830     Note: The maximum, minimum and value might change as a result of
     
    835842{
    836843    Q_D(QDoubleSpinBox);
    837     d->decimals = qMax(0, decimals);
     844    d->decimals = qBound(0, decimals, DBL_MAX_10_EXP + DBL_DIG);
    838845
    839846    setRange(minimum(), maximum()); // make sure values are rounded
     
    864871    QString str = locale().toString(value, 'f', d->decimals);
    865872    if (qAbs(value) >= 1000.0) {
    866         str.remove(d->thousand);
     873        str.remove(locale().groupSeparator());
    867874    }
    868875    return str;
     
    909916void QDoubleSpinBox::fixup(QString &input) const
    910917{
    911     Q_D(const QDoubleSpinBox);
    912 
    913     input.remove(d->thousand);
     918    input.remove(locale().groupSeparator());
    914919}
    915920
     
    921926*/
    922927
    923 QSpinBoxPrivate::QSpinBoxPrivate(QWidget *parent)
     928QSpinBoxPrivate::QSpinBoxPrivate()
    924929{
    925930    minimum = QVariant((int)0);
     
    928933    singleStep = QVariant((int)1);
    929934    type = QVariant::Int;
    930     const QString str = (parent ? parent->locale() : QLocale()).toString(4567);
    931     if (str.size() == 5) {
    932         thousand = QChar(str.at(1));
    933     }
    934 
    935935}
    936936
     
    976976
    977977/*!
    978   \internal
    979 
    980   Return true if str can become a number which is between minimum and
    981   maximum or false if this is not possible.
    982 */
    983 
    984 bool QSpinBoxPrivate::isIntermediateValue(const QString &str) const
    985 {
    986     const int num = q_func()->locale().toInt(str, 0, 10);
    987     const int min = minimum.toInt();
    988     const int max = maximum.toInt();
    989 
    990     int numDigits = 0;
    991     int digits[10];
    992     int tmp = num;
    993     if (tmp == 0) {
    994         numDigits = 1;
    995         digits[0] = 0;
    996     } else {
    997         tmp = num;
    998         for (int i=0; tmp != 0; ++i) {
    999             digits[numDigits++] = qAbs(tmp % 10);
    1000             tmp /= 10;
    1001         }
    1002     }
    1003 
    1004     int failures = 0;
    1005     for (int number=min; /*number<=max*/; ++number) {
    1006         tmp = number;
    1007         for (int i=0; tmp != 0;) {
    1008             if (digits[i] == qAbs(tmp % 10)) {
    1009                 if (++i == numDigits)
    1010                     return true;
    1011             }
    1012             tmp /= 10;
    1013         }
    1014         if (failures++ == 500000) //upper bound
    1015             return true;
    1016         if (number == max) // needed for INT_MAX
    1017             break;
    1018     }
    1019     return false;
    1020 }
    1021 
    1022 /*!
    1023978    \internal Multi purpose function that parses input, sets state to
    1024979    the appropriate state and returns the value it will be interpreted
     
    1031986    if (cachedText == input && !input.isEmpty()) {
    1032987        state = cachedState;
    1033         QSBDEBUG() << "cachedText was" << "'" << cachedText << "'" << "state was "
     988        QSBDEBUG() << "cachedText was '" << cachedText << "' state was "
    1034989                   << state << " and value was " << cachedValue;
    1035990
     
    10491004        state = QValidator::Intermediate;
    10501005        QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num;
    1051     } else if (copy.startsWith(QLatin1String("-")) && min >= 0) {
     1006    } else if (copy.startsWith(QLatin1Char('-')) && min >= 0) {
    10521007        state = QValidator::Invalid; // special-case -0 will be interpreted as 0 and thus not be invalid with a range from 0-100
    10531008    } else {
    10541009        bool ok = false;
    1055         bool removedThousand = false;
    1056         num = q_func()->locale().toInt(copy, &ok, 10);
    1057         if (!ok && copy.contains(thousand) && (max >= 1000 || min <= -1000)) {
    1058             const int s = copy.size();
    1059             copy.remove(thousand);
    1060             pos = qMax(0, pos - (s - copy.size()));
    1061             removedThousand = true;
    1062             num = q_func()->locale().toInt(copy, &ok, 10);
     1010        num = locale.toInt(copy, &ok, 10);
     1011        if (!ok && copy.contains(locale.groupSeparator()) && (max >= 1000 || min <= -1000)) {
     1012            QString copy2 = copy;
     1013            copy2.remove(locale.groupSeparator());
     1014            num = locale.toInt(copy2, &ok, 10);
    10631015        }
    10641016        QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num;
     
    10661018            state = QValidator::Invalid;
    10671019        } else if (num >= min && num <= max) {
    1068             state = removedThousand ? QValidator::Intermediate : QValidator::Acceptable;
     1020            state = QValidator::Acceptable;
    10691021        } else if (max == min) {
    10701022            state = QValidator::Invalid;
     
    10741026                QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
    10751027            } else {
    1076                 state = isIntermediateValue(copy) ? QValidator::Intermediate : QValidator::Invalid;
    1077                 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to "
    1078                            << (state == QValidator::Intermediate ? "Intermediate" : "Acceptable");
     1028                state = QValidator::Intermediate;
     1029                QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Intermediate";
    10791030            }
    10801031        }
     
    10991050*/
    11001051
    1101 QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate(QWidget *parent)
     1052QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate()
    11021053{
    11031054    minimum = QVariant(0.0);
     
    11071058    decimals = 2;
    11081059    type = QVariant::Double;
    1109     const QString str = (parent ? parent->locale() : QLocale()).toString(4567.1);
    1110     if (str.size() == 6) {
    1111         delimiter = str.at(4);
    1112         thousand = QChar((ushort)0);
    1113     } else if (str.size() == 7) {
    1114         thousand = str.at(1);
    1115         delimiter = str.at(5);
    1116     }
    1117     Q_ASSERT(!delimiter.isNull());
    11181060}
    11191061
     
    11361078
    11371079
    1138 bool QDoubleSpinBoxPrivate::isIntermediateValue(const QString &str) const
    1139 {
    1140     QSBDEBUG() << "input is" << str << minimum << maximum;
    1141     qint64 dec = 1;
    1142     for (int i=0; i<decimals; ++i)
    1143         dec *= 10;
    1144 
    1145     const QLatin1Char dot('.');
    1146 
    1147     // I know QString::number() uses CLocale so I use dot
    1148     const QString minstr = QString::number(minimum.toDouble(), 'f', decimals);
    1149     bool ok;
    1150     qint64 min_left = minstr.left(minstr.indexOf(dot)).toLongLong(&ok);
    1151     if (!ok)
    1152         return false;
    1153     qint64 min_right = minstr.mid(minstr.indexOf(dot) + 1).toLongLong();
    1154 
    1155     const QString maxstr = QString::number(maximum.toDouble(), 'f', decimals);
    1156     qint64 max_left = maxstr.left(maxstr.indexOf(dot)).toLongLong(&ok);
    1157     if (!ok)
    1158         return true;
    1159     qint64 max_right = maxstr.mid(maxstr.indexOf(dot) + 1).toLongLong();
    1160 
    1161     const int dotindex = str.indexOf(delimiter);
    1162     const bool negative = maximum.toDouble() < 0;
    1163     qint64 left = 0, right = 0;
    1164     bool doleft = true;
    1165     bool doright = true;
    1166     if (dotindex == -1) {
    1167         left = str.toLongLong();
    1168         doright = false;
    1169     } else if (dotindex == 0 || (dotindex == 1 && str.at(0) == QLatin1Char('+'))) {
    1170         if (negative) {
    1171             QSBDEBUG() << __FILE__ << __LINE__ << "returns false";
    1172             return false;
    1173         }
    1174         doleft = false;
    1175         right = str.mid(dotindex + 1).toLongLong();
    1176     } else if (dotindex == 1 && str.at(0) == QLatin1Char('-')) {
    1177         if (!negative) {
    1178             QSBDEBUG() << __FILE__ << __LINE__ << "returns false";
    1179             return false;
    1180         }
    1181         doleft = false;
    1182         right = str.mid(dotindex + 1).toLongLong();
    1183     } else {
    1184         left = str.left(dotindex).toLongLong();
    1185         if (dotindex == str.size() - 1) {
    1186             doright = false;
    1187         } else {
    1188             right = str.mid(dotindex + 1).toLongLong();
    1189         }
    1190     }
    1191     if ((left >= 0 && max_left < 0 && !str.startsWith(QLatin1Char('-'))) || (left < 0 && min_left >= 0)) {
    1192         QSBDEBUG("returns false 0");
    1193         return false;
    1194     }
    1195 
    1196     qint64 match = min_left;
    1197     if (doleft && !isIntermediateValueHelper(left, min_left, max_left, &match)) {
    1198         QSBDEBUG() << __FILE__ << __LINE__ << "returns false";
    1199         return false;
    1200     }
    1201     if (doright) {
    1202         QSBDEBUG("match %lld min_left %lld max_left %lld", match, min_left, max_left);
    1203         if (!doleft) {
    1204             if (min_left == max_left) {
    1205                 const bool ret = isIntermediateValueHelper(qAbs(left),
    1206                                                            negative ? max_right : min_right,
    1207                                                            negative ? min_right : max_right);
    1208                 QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;
    1209                 return ret;
    1210             } else if (qAbs(max_left - min_left) == 1) {
    1211                 const bool ret = isIntermediateValueHelper(qAbs(left), min_right, negative ? 0 : dec)
    1212                                  || isIntermediateValueHelper(qAbs(left), negative ? dec : 0, max_right);
    1213                 QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;
    1214                 return ret;
    1215             } else {
    1216                 const bool ret = isIntermediateValueHelper(qAbs(left), 0, dec);
    1217                 QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;
    1218                 return ret;
    1219             }
    1220         }
    1221         if (match != min_left) {
    1222             min_right = negative ? dec : 0;
    1223         }
    1224         if (match != max_left) {
    1225             max_right = negative ? 0 : dec;
    1226         }
    1227         qint64 tmpl = negative ? max_right : min_right;
    1228         qint64 tmpr = negative ? min_right : max_right;
    1229         const bool ret = isIntermediateValueHelper(right, tmpl, tmpr);
    1230         QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;
    1231         return ret;
    1232     }
    1233     QSBDEBUG() << __FILE__ << __LINE__ << "returns true";
    1234     return true;
    1235 }
    1236 
    12371080/*!
    12381081    \internal
     
    12551098double QDoubleSpinBoxPrivate::round(double value) const
    12561099{
    1257     Q_Q(const QDoubleSpinBox);
    1258     const QString strDbl = q->locale().toString(value, 'f', decimals);
    1259     return q->locale().toDouble(strDbl);
     1100    return QString::number(value, 'f', decimals).toDouble();
    12601101}
    12611102
     
    12721113    if (cachedText == input && !input.isEmpty()) {
    12731114        state = cachedState;
    1274         QSBDEBUG() << "cachedText was" << "'" << cachedText << "'" << "state was "
     1115        QSBDEBUG() << "cachedText was '" << cachedText << "' state was "
    12751116                   << state << " and value was " << cachedValue;
    12761117        return cachedValue;
     
    12911132        goto end;
    12921133    case 1:
    1293         if (copy.at(0) == delimiter
     1134        if (copy.at(0) == locale.decimalPoint()
    12941135            || (plus && copy.at(0) == QLatin1Char('+'))
    12951136            || (minus && copy.at(0) == QLatin1Char('-'))) {
     
    12991140        break;
    13001141    case 2:
    1301         if (copy.at(1) == delimiter
     1142        if (copy.at(1) == locale.decimalPoint()
    13021143            && ((plus && copy.at(0) == QLatin1Char('+')) || (minus && copy.at(0) == QLatin1Char('-')))) {
    13031144            state = QValidator::Intermediate;
     
    13081149    }
    13091150
    1310     if (copy.at(0) == thousand) {
     1151    if (copy.at(0) == locale.groupSeparator()) {
    13111152        QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
    13121153        state = QValidator::Invalid;
    13131154        goto end;
    13141155    } else if (len > 1) {
    1315         const int dec = copy.indexOf(delimiter);
     1156        const int dec = copy.indexOf(locale.decimalPoint());
    13161157        if (dec != -1) {
    1317             if (dec + 1 < copy.size() && copy.at(dec + 1) == delimiter && pos == dec + 1) {
     1158            if (dec + 1 < copy.size() && copy.at(dec + 1) == locale.decimalPoint() && pos == dec + 1) {
    13181159                copy.remove(dec + 1, 1); // typing a delimiter when you are on the delimiter
    13191160            } // should be treated as typing right arrow
     
    13251166            }
    13261167            for (int i=dec + 1; i<copy.size(); ++i) {
    1327                 if (copy.at(i).isSpace() || copy.at(i) == thousand) {
     1168                if (copy.at(i).isSpace() || copy.at(i) == locale.groupSeparator()) {
    13281169                    QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
    13291170                    state = QValidator::Invalid;
     
    13341175            const QChar &last = copy.at(len - 1);
    13351176            const QChar &secondLast = copy.at(len - 2);
    1336             if ((last == thousand || last.isSpace())
    1337                 && (secondLast == thousand || secondLast.isSpace())) {
     1177            if ((last == locale.groupSeparator() || last.isSpace())
     1178                && (secondLast == locale.groupSeparator() || secondLast.isSpace())) {
    13381179                state = QValidator::Invalid;
    13391180                QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
    13401181                goto end;
    1341             } else if (last.isSpace() && (!thousand.isSpace() || secondLast.isSpace())) {
     1182            } else if (last.isSpace() && (!locale.groupSeparator().isSpace() || secondLast.isSpace())) {
    13421183                state = QValidator::Invalid;
    13431184                QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
     
    13491190    {
    13501191        bool ok = false;
    1351         QLocale loc(q_func()->locale());
    1352         num = loc.toDouble(copy, &ok);
    1353         QSBDEBUG() << __FILE__ << __LINE__ << loc << copy << num << ok;
    1354         bool notAcceptable = false;
     1192        num = locale.toDouble(copy, &ok);
     1193        QSBDEBUG() << __FILE__ << __LINE__ << locale << copy << num << ok;
    13551194
    13561195        if (!ok) {
    1357             if (thousand.isPrint()) {
    1358                 if (max < 1000 && min > -1000 && copy.contains(thousand)) {
     1196            if (locale.groupSeparator().isPrint()) {
     1197                if (max < 1000 && min > -1000 && copy.contains(locale.groupSeparator())) {
    13591198                    state = QValidator::Invalid;
    13601199                    QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
     
    13641203                const int len = copy.size();
    13651204                for (int i=0; i<len- 1; ++i) {
    1366                     if (copy.at(i) == thousand && copy.at(i + 1) == thousand) {
     1205                    if (copy.at(i) == locale.groupSeparator() && copy.at(i + 1) == locale.groupSeparator()) {
    13671206                        QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
    13681207                        state = QValidator::Invalid;
     
    13711210                }
    13721211
    1373                 const int s = copy.size();
    1374                 copy.remove(thousand);
    1375                 pos = qMax(0, pos - (s - copy.size()));
    1376 
    1377 
    1378                 num = loc.toDouble(copy, &ok);
    1379                 QSBDEBUG() << thousand << num << copy << ok;
     1212                QString copy2 = copy;
     1213                copy2.remove(locale.groupSeparator());
     1214                num = locale.toDouble(copy2, &ok);
     1215                QSBDEBUG() << locale.groupSeparator() << num << copy2 << ok;
    13801216
    13811217                if (!ok) {
     
    13841220                    goto end;
    13851221                }
    1386                 notAcceptable = true;
    13871222            }
    13881223        }
     
    13921227            QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
    13931228        } else if (num >= min && num <= max) {
    1394             state = notAcceptable ? QValidator::Intermediate : QValidator::Acceptable;
    1395             QSBDEBUG() << __FILE__ << __LINE__<< "state is set to "
    1396                        << (state == QValidator::Intermediate ? "Intermediate" : "Acceptable");
     1229            state = QValidator::Acceptable;
     1230            QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Acceptable";
    13971231        } else if (max == min) { // when max and min is the same the only non-Invalid input is max (or min)
    13981232            state = QValidator::Invalid;
     
    14031237                QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
    14041238            } else {
    1405                 state = isIntermediateValue(copy) ? QValidator::Intermediate : QValidator::Invalid;
    1406                 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to "
    1407                            << (state == QValidator::Intermediate ? "Intermediate" : "Acceptable");
     1239                state = QValidator::Intermediate;
     1240                QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Intermediate";
    14081241            }
    14091242        }
     
    14621295    Use minimum() instead.
    14631296*/
    1464 
    1465 /*!
    1466     \internal Returns whether \a str is a string which value cannot be
    1467     parsed but still might turn into something valid.
    1468 */
    1469 
    1470 static bool isIntermediateValueHelper(qint64 num, qint64 min, qint64 max, qint64 *match)
    1471 {
    1472     QSBDEBUG("%lld %lld %lld", num, min, max);
    1473 
    1474     if (num >= min && num <= max) {
    1475         if (match)
    1476             *match = num;
    1477         QSBDEBUG("returns true 0");
    1478         return true;
    1479     }
    1480     qint64 tmp = num;
    1481 
    1482     int numDigits = 0;
    1483     int digits[10];
    1484     if (tmp == 0) {
    1485         numDigits = 1;
    1486         digits[0] = 0;
    1487     } else {
    1488         tmp = qAbs(num);
    1489         for (int i=0; tmp > 0; ++i) {
    1490             digits[numDigits++] = tmp % 10;
    1491             tmp /= 10;
    1492         }
    1493     }
    1494 
    1495     int failures = 0;
    1496     qint64 number;
    1497     for (number=max; number>=min; --number) {
    1498         tmp = qAbs(number);
    1499         for (int i=0; tmp > 0;) {
    1500             if (digits[i] == (tmp % 10)) {
    1501                 if (++i == numDigits) {
    1502                     if (match)
    1503                         *match = number;
    1504                     QSBDEBUG("returns true 1");
    1505                     return true;
    1506                 }
    1507             }
    1508             tmp /= 10;
    1509         }
    1510         if (failures++ == 500000) { //upper bound
    1511             if (match)
    1512                 *match = num;
    1513             QSBDEBUG("returns true 2");
    1514             return true;
    1515         }
    1516     }
    1517     QSBDEBUG("returns false");
    1518     return false;
    1519 }
    15201297
    15211298/*! \reimp */
Note: See TracChangeset for help on using the changeset viewer.