VirtualBox

Changeset 4323 in vbox for trunk/src


Ignore:
Timestamp:
Aug 23, 2007 6:58:03 PM (17 years ago)
Author:
vboxsync
Message:

FE/Qt: Added QIULongValidator.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/QIWidgetValidator.h

    r4071 r4323  
    2020#define __QIWidgetValidator_h__
    2121
     22#include <limits.h>
     23
    2224#include <qobject.h>
     25#include <qvalidator.h>
    2326
    2427class QIWidgetValidator : public QObject
     
    5255};
    5356
     57class QIULongValidator : public QValidator
     58{
     59public:
     60
     61    QIULongValidator (QObject *aParent, const char *aName = 0)
     62        : mBottom (0), mTop (ULONG_MAX)
     63        , QValidator (aParent, aName) {}
     64
     65    QIULongValidator (ulong aMinimum, ulong aMaximum,
     66                      QObject *aParent, const char *aName = 0)
     67        : mBottom (aMinimum), mTop (aMaximum)
     68        , QValidator (aParent, aName) {}
     69
     70    ~QIULongValidator() {}
     71
     72    State validate (QString &aInput, int &aPos) const;
     73    void setBottom (ulong aBottom) { setRange (aBottom, mTop); }
     74    void setTop (ulong aTop) { setRange (mBottom, aTop); }
     75    void setRange (ulong aBottom, ulong aTop) { mBottom = aBottom; mTop = aTop; }
     76    ulong bottom() const { return mBottom; }
     77    ulong top() const { return mTop; }
     78
     79private:
     80
     81    ulong mBottom;
     82    ulong mTop;
     83};
     84
    5485#endif // __QIWidgetValidator_h__
  • trunk/src/VBox/Frontends/VirtualBox/src/QIWidgetValidator.cpp

    r4071 r4323  
    233233 */
    234234
     235
     236/** @class QIULongValidator
     237 *
     238 *  The QIULongValidator class is a QIntValidator-like class to validate
     239 *  unsigned integer numbers. As opposed to QIntValidator, this class accepts
     240 *  all three integer number formats: decimal, hexadecimal (the string starts
     241 *  with "0x") and octal (the string starts with "0").
     242 */
     243
     244QValidator::State QIULongValidator::validate (QString &aInput, int &aPos) const
     245{
     246    Q_UNUSED (aPos);
     247
     248    QString stripped = aInput.stripWhiteSpace();
     249
     250    if (stripped.isEmpty() ||
     251        stripped.upper() == QString ("0x").upper())
     252        return Intermediate;
     253
     254    bool ok;
     255    ulong entered = aInput.toULong (&ok, 0);
     256
     257    if (!ok)
     258        return Invalid;
     259
     260    if (entered >= mBottom && entered <= mTop)
     261        return Acceptable;
     262
     263    return (entered > mTop ) ? Invalid : Intermediate;
     264}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette