VirtualBox

Changeset 71410 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 20, 2018 4:24:46 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for QIWidgetValidator.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIWidgetValidator.cpp

    r69500 r71410  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2727
    2828
     29/*********************************************************************************************************************************
     30*   Class QObjectValidator implementation.                                                                                       *
     31*********************************************************************************************************************************/
    2932
    3033QObjectValidator::QObjectValidator(QValidator *pValidator, QObject *pParent /* = 0 */)
    3134    : QObject(pParent)
    3235    , m_pValidator(pValidator)
    33     , m_state(QValidator::Invalid)
     36    , m_enmState(QValidator::Invalid)
    3437{
    3538    /* Prepare: */
     
    4447    /* Validate: */
    4548    int iPosition = 0;
    46     const QValidator::State state = m_pValidator->validate(strInput, iPosition);
     49    const QValidator::State enmState = m_pValidator->validate(strInput, iPosition);
    4750
    4851    /* If validity state changed: */
    49     if (m_state != state)
     52    if (m_enmState != enmState)
    5053    {
    5154        /* Update last validity state: */
    52         m_state = state;
     55        m_enmState = enmState;
    5356
    5457        /* Notifies listener(s) about validity change: */
    55         emit sigValidityChange(m_state);
     58        emit sigValidityChange(m_enmState);
    5659    }
    5760}
     
    7073
    7174
    72 QObjectValidatorGroup::QObjectValidatorGroup(QObject *pParent)
    73     : QObject(pParent)
    74     , m_fResult(false)
    75 {
    76 }
     75/*********************************************************************************************************************************
     76*   Class QObjectValidatorGroup implementation.                                                                                  *
     77*********************************************************************************************************************************/
    7778
    7879void QObjectValidatorGroup::addObjectValidator(QObjectValidator *pObjectValidator)
     
    9293}
    9394
    94 void QObjectValidatorGroup::sltValidate(QValidator::State state)
     95void QObjectValidatorGroup::sltValidate(QValidator::State enmState)
    9596{
    9697    /* Determine sender object-validator: */
     
    100101
    101102    /* Update internal map: */
    102     m_group[pObjectValidatorSender] = toResult(state);
     103    m_group[pObjectValidatorSender] = toResult(enmState);
    103104
    104105    /* Enumerate all the registered object-validators: */
     
    123124
    124125/* static */
    125 bool QObjectValidatorGroup::toResult(QValidator::State state)
     126bool QObjectValidatorGroup::toResult(QValidator::State enmState)
    126127{
    127     return state == QValidator::Acceptable;
     128    return enmState == QValidator::Acceptable;
    128129}
    129130
    130131
    131 UIPageValidator::UIPageValidator(QObject *pParent, UISettingsPage *pPage)
    132     : QObject(pParent)
    133     , m_pPage(pPage)
    134     , m_fIsValid(true)
    135 {
    136 }
     132/*********************************************************************************************************************************
     133*   Class UIPageValidator implementation.                                                                                        *
     134*********************************************************************************************************************************/
    137135
    138136QPixmap UIPageValidator::warningPixmap() const
     
    165163
    166164
    167 QValidator::State QIULongValidator::validate (QString &aInput, int &aPos) const
     165/*********************************************************************************************************************************
     166*   Class QIULongValidator implementation.                                                                                       *
     167*********************************************************************************************************************************/
     168
     169QValidator::State QIULongValidator::validate(QString &strInput, int &iPosition) const
    168170{
    169     Q_UNUSED (aPos);
     171    Q_UNUSED(iPosition);
    170172
    171     QString stripped = aInput.trimmed();
     173    /* Get the stripped string: */
     174    QString strStripped = strInput.trimmed();
    172175
    173     if (stripped.isEmpty() ||
    174         stripped.toUpper() == QString ("0x").toUpper())
     176    /* 'Intermediate' for empty string or started from '0x': */
     177    if (strStripped.isEmpty() ||
     178        strStripped.toUpper() == QString("0x").toUpper())
    175179        return Intermediate;
    176180
    177     bool ok;
    178     ulong entered = aInput.toULong (&ok, 0);
     181    /* Convert to ulong: */
     182    bool fOk;
     183    ulong uEntered = strInput.toULong(&fOk, 0);
    179184
    180     if (!ok)
     185    /* 'Invalid' if failed to convert: */
     186    if (!fOk)
    181187        return Invalid;
    182188
    183     if (entered >= mBottom && entered <= mTop)
     189    /* 'Acceptable' if fits the bounds: */
     190    if (uEntered >= m_uBottom && uEntered <= m_uTop)
    184191        return Acceptable;
    185192
    186     return (entered > mTop ) ? Invalid : Intermediate;
     193    /* 'Invalid' if more than top, 'Intermediate' if less than bottom: */
     194    return uEntered > m_uTop ? Invalid : Intermediate;
    187195}
    188196
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIWidgetValidator.h

    r69500 r71410  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __QIWidgetValidator_h__
    19 #define __QIWidgetValidator_h__
     18#ifndef ___QIWidgetValidator_h___
     19#define ___QIWidgetValidator_h___
    2020
    2121/* Qt includes: */
     22#include <QMap>
     23#include <QPixmap>
    2224#include <QValidator>
    23 #include <QPixmap>
    24 #include <QMap>
    25 
    26 /* External includes: */
    27 #ifdef VBOX_WS_X11
    28 #include <limits.h>
    29 #endif /* VBOX_WS_X11 */
    3025
    3126/* Forward declarations: */
     27class QPixmap;
     28class QString;
    3229class UISettingsPage;
    3330
    34 /** QObject reimplementation,
     31
     32/** QObject extension,
    3533  * providing passed QObject with validation routine. */
    3634class QObjectValidator : public QObject
     
    4038signals:
    4139
    42     /** Notifies listener(s) about validity change. */
    43     void sigValidityChange(QValidator::State state);
    44 
    45 public:
    46 
    47     /** Constructor.
    48       * @param pParent    is passed on to the QObject constructor,
    49       * @param pValidator is passed on to the OObject children
    50       *                   and used to perform validation itself. */
     40    /** Notifies listener(s) about validity changed to @a enmState. */
     41    void sigValidityChange(QValidator::State enmState);
     42
     43public:
     44
     45    /** Constructs object validator passing @a pParent to the base-class.
     46      * @param  pValidator  Brings the validator passed on to the OObject
     47      *                     children and used to perform validation itself. */
    5148    QObjectValidator(QValidator *pValidator, QObject *pParent = 0);
    5249
    5350    /** Returns last validation state. */
    54     QValidator::State state() const { return m_state; }
     51    QValidator::State state() const { return m_enmState; }
    5552
    5653public slots:
     
    6461    void prepare();
    6562
    66     /** Holds validator. */
     63    /** Holds the validator reference. */
    6764    QValidator *m_pValidator;
    68     /** Holds validation state. */
    69     QValidator::State m_state;
    70 };
    71 
    72 /** QObject reimplementation,
     65
     66    /** Holds the validation state. */
     67    QValidator::State m_enmState;
     68};
     69
     70
     71/** QObject extension,
    7372  * which can group various QObjectValidator instances to operate on. */
    7473class QObjectValidatorGroup : public QObject
     
    7877signals:
    7978
    80     /** Notifies listener(s) about validity change. */
     79    /** Notifies listener(s) about validity changed to @a fValid. */
    8180    void sigValidityChange(bool fValid);
    8281
    8382public:
    8483
    85     /** Constructor.
    86       * @param pParent is passed on to the QObject constructor. */
    87     QObjectValidatorGroup(QObject *pParent);
    88 
    89     /** Adds object-validator.
     84    /** Constructs validation group passing @a pParent to the base-class. */
     85    QObjectValidatorGroup(QObject *pParent)
     86        : QObject(pParent)
     87        , m_fResult(false)
     88    {}
     89
     90    /** Adds @a pObjectValidator.
    9091      * @note The ownership of @a pObjectValidator is transferred to the group,
    9192      *       and it's the group's responsibility to delete it. */
     
    9798private slots:
    9899
    99     /** Performs validation: */
    100     void sltValidate(QValidator::State state);
     100    /** Performs validation for a passed @a enmState. */
     101    void sltValidate(QValidator::State enmState);
    101102
    102103private:
    103104
    104105    /** Converts QValidator::State to bool result. */
    105     static bool toResult(QValidator::State state);
     106    static bool toResult(QValidator::State enmState);
    106107
    107108    /** Holds object-validators and their states. */
    108109    QMap<QObjectValidator*, bool> m_group;
     110
    109111    /** Holds validation result. */
    110112    bool m_fResult;
    111113};
    112114
    113 /* Page validator prototype: */
     115
     116/** Page validator prototype. */
    114117class UIPageValidator : public QObject
    115118{
     
    118121signals:
    119122
    120     /* Notifier: Validation stuff: */
     123    /** Notifies about validity change for @a pValidator. */
    121124    void sigValidityChanged(UIPageValidator *pValidator);
    122125
    123     /* Notifiers: Warning stuff: */
     126    /** Asks listener to show warning icon. */
    124127    void sigShowWarningIcon();
     128    /** Asks listener to hide warning icon. */
    125129    void sigHideWarningIcon();
    126130
    127131public:
    128132
    129     /* Constructor: */
    130     UIPageValidator(QObject *pParent, UISettingsPage *pPage);
    131 
    132     /* API: Page stuff: */
    133     UISettingsPage* page() const { return m_pPage; }
     133    /** Constructs page validator for a certain @a pPage,
     134      * passing @a pParent to the base-class. */
     135    UIPageValidator(QObject *pParent, UISettingsPage *pPage)
     136        : QObject(pParent)
     137        , m_pPage(pPage)
     138        , m_fIsValid(true)
     139    {}
     140
     141    /** Returns page. */
     142    UISettingsPage *page() const { return m_pPage; }
     143    /** Returns warning pixmap. */
    134144    QPixmap warningPixmap() const;
     145    /** Returns internal name. */
    135146    QString internalName() const;
    136147
    137     /* API: Validity stuff: */
     148    /** Returns whether validator is valid. */
    138149    bool isValid() const { return m_fIsValid; }
     150    /** Defines whether validator @a fIsValid. */
    139151    void setValid(bool fIsValid) { m_fIsValid = fIsValid; }
    140152
    141     /* API: Message stuff: */
     153    /** Returns last message. */
    142154    QString lastMessage() const { return m_strLastMessage; }
     155    /** Defines @a strLastMessage. */
    143156    void setLastMessage(const QString &strLastMessage);
    144157
    145158public slots:
    146159
    147     /* API/Handler: Validation stuff: */
     160    /** Performs revalidation. */
    148161    void revalidate();
    149162
    150163private:
    151164
    152     /* Variables: */
     165    /** Holds the validated page. */
    153166    UISettingsPage *m_pPage;
     167
     168    /** Holds whether the page is valid. */
    154169    bool m_fIsValid;
     170
     171    /** Holds the last message. */
    155172    QString m_strLastMessage;
    156173};
    157174
     175
     176/** QValidator extension,
     177  * for long number validations. */
    158178class QIULongValidator : public QValidator
    159179{
    160180public:
    161181
    162     QIULongValidator (QObject *aParent)
    163         : QValidator (aParent)
    164         , mBottom (0), mTop (ULONG_MAX) {}
    165 
    166     QIULongValidator (ulong aMinimum, ulong aMaximum,
    167                       QObject *aParent)
    168         : QValidator (aParent)
    169         , mBottom (aMinimum), mTop (aMaximum) {}
    170 
    171     ~QIULongValidator() {}
    172 
    173     State validate (QString &aInput, int &aPos) const;
    174     void setBottom (ulong aBottom) { setRange (aBottom, mTop); }
    175     void setTop (ulong aTop) { setRange (mBottom, aTop); }
    176     void setRange (ulong aBottom, ulong aTop) { mBottom = aBottom; mTop = aTop; }
    177     ulong bottom() const { return mBottom; }
    178     ulong top() const { return mTop; }
    179 
    180 private:
    181 
    182     ulong mBottom;
    183     ulong mTop;
    184 };
    185 
    186 #endif // __QIWidgetValidator_h__
     182    /** Constructs long validator passing @a pParent to the base-class. */
     183    QIULongValidator(QObject *pParent)
     184        : QValidator(pParent)
     185        , m_uBottom(0), m_uTop(ULONG_MAX)
     186    {}
     187
     188    /** Constructs long validator passing @a pParent to the base-class.
     189      * @param  uMinimum  Holds the minimum valid border.
     190      * @param  uMaximum  Holds the maximum valid border. */
     191    QIULongValidator(ulong uMinimum, ulong uMaximum,
     192                     QObject *pParent)
     193        : QValidator(pParent)
     194        , m_uBottom(uMinimum), m_uTop(uMaximum)
     195    {}
     196
     197    /** Destructs long validator. */
     198    virtual ~QIULongValidator() {}
     199
     200    /** Performs validation for @a strInput at @a iPosition. */
     201    State validate(QString &strInput, int &iPosition) const;
     202
     203    /** Defines @a uBottom. */
     204    void setBottom(ulong uBottom) { setRange(uBottom, m_uTop); }
     205    /** Defines @a uTop. */
     206    void setTop(ulong uTop) { setRange(m_uBottom, uTop); }
     207    /** Defines range based on passed @a uBottom and @a uTop. */
     208    void setRange(ulong uBottom, ulong uTop) { m_uBottom = uBottom; m_uTop = uTop; }
     209    /** Returns bottom. */
     210    ulong bottom() const { return m_uBottom; }
     211    /** Returns top. */
     212    ulong top() const { return m_uTop; }
     213
     214private:
     215
     216    /** Holds the bottom. */
     217    ulong m_uBottom;
     218    /** Holds the top. */
     219    ulong m_uTop;
     220};
     221
     222
     223#endif /* !___QIWidgetValidator_h___ */
     224
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