Changeset 71410 in vbox for trunk/src/VBox
- Timestamp:
- Mar 20, 2018 4:24:46 PM (7 years ago)
- 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 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 27 27 28 28 29 /********************************************************************************************************************************* 30 * Class QObjectValidator implementation. * 31 *********************************************************************************************************************************/ 29 32 30 33 QObjectValidator::QObjectValidator(QValidator *pValidator, QObject *pParent /* = 0 */) 31 34 : QObject(pParent) 32 35 , m_pValidator(pValidator) 33 , m_ state(QValidator::Invalid)36 , m_enmState(QValidator::Invalid) 34 37 { 35 38 /* Prepare: */ … … 44 47 /* Validate: */ 45 48 int iPosition = 0; 46 const QValidator::State state = m_pValidator->validate(strInput, iPosition);49 const QValidator::State enmState = m_pValidator->validate(strInput, iPosition); 47 50 48 51 /* If validity state changed: */ 49 if (m_ state != state)52 if (m_enmState != enmState) 50 53 { 51 54 /* Update last validity state: */ 52 m_ state = state;55 m_enmState = enmState; 53 56 54 57 /* Notifies listener(s) about validity change: */ 55 emit sigValidityChange(m_ state);58 emit sigValidityChange(m_enmState); 56 59 } 57 60 } … … 70 73 71 74 72 QObjectValidatorGroup::QObjectValidatorGroup(QObject *pParent) 73 : QObject(pParent) 74 , m_fResult(false) 75 { 76 } 75 /********************************************************************************************************************************* 76 * Class QObjectValidatorGroup implementation. * 77 *********************************************************************************************************************************/ 77 78 78 79 void QObjectValidatorGroup::addObjectValidator(QObjectValidator *pObjectValidator) … … 92 93 } 93 94 94 void QObjectValidatorGroup::sltValidate(QValidator::State state)95 void QObjectValidatorGroup::sltValidate(QValidator::State enmState) 95 96 { 96 97 /* Determine sender object-validator: */ … … 100 101 101 102 /* Update internal map: */ 102 m_group[pObjectValidatorSender] = toResult( state);103 m_group[pObjectValidatorSender] = toResult(enmState); 103 104 104 105 /* Enumerate all the registered object-validators: */ … … 123 124 124 125 /* static */ 125 bool QObjectValidatorGroup::toResult(QValidator::State state)126 bool QObjectValidatorGroup::toResult(QValidator::State enmState) 126 127 { 127 return state == QValidator::Acceptable;128 return enmState == QValidator::Acceptable; 128 129 } 129 130 130 131 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 *********************************************************************************************************************************/ 137 135 138 136 QPixmap UIPageValidator::warningPixmap() const … … 165 163 166 164 167 QValidator::State QIULongValidator::validate (QString &aInput, int &aPos) const 165 /********************************************************************************************************************************* 166 * Class QIULongValidator implementation. * 167 *********************************************************************************************************************************/ 168 169 QValidator::State QIULongValidator::validate(QString &strInput, int &iPosition) const 168 170 { 169 Q_UNUSED (aPos);171 Q_UNUSED(iPosition); 170 172 171 QString stripped = aInput.trimmed(); 173 /* Get the stripped string: */ 174 QString strStripped = strInput.trimmed(); 172 175 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()) 175 179 return Intermediate; 176 180 177 bool ok; 178 ulong entered = aInput.toULong (&ok, 0); 181 /* Convert to ulong: */ 182 bool fOk; 183 ulong uEntered = strInput.toULong(&fOk, 0); 179 184 180 if (!ok) 185 /* 'Invalid' if failed to convert: */ 186 if (!fOk) 181 187 return Invalid; 182 188 183 if (entered >= mBottom && entered <= mTop) 189 /* 'Acceptable' if fits the bounds: */ 190 if (uEntered >= m_uBottom && uEntered <= m_uTop) 184 191 return Acceptable; 185 192 186 return (entered > mTop ) ? Invalid : Intermediate; 193 /* 'Invalid' if more than top, 'Intermediate' if less than bottom: */ 194 return uEntered > m_uTop ? Invalid : Intermediate; 187 195 } 188 196 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIWidgetValidator.h
r69500 r71410 5 5 6 6 /* 7 * Copyright (C) 2006-201 7Oracle Corporation7 * Copyright (C) 2006-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ QIWidgetValidator_h__19 #define __ QIWidgetValidator_h__18 #ifndef ___QIWidgetValidator_h___ 19 #define ___QIWidgetValidator_h___ 20 20 21 21 /* Qt includes: */ 22 #include <QMap> 23 #include <QPixmap> 22 24 #include <QValidator> 23 #include <QPixmap>24 #include <QMap>25 26 /* External includes: */27 #ifdef VBOX_WS_X1128 #include <limits.h>29 #endif /* VBOX_WS_X11 */30 25 31 26 /* Forward declarations: */ 27 class QPixmap; 28 class QString; 32 29 class UISettingsPage; 33 30 34 /** QObject reimplementation, 31 32 /** QObject extension, 35 33 * providing passed QObject with validation routine. */ 36 34 class QObjectValidator : public QObject … … 40 38 signals: 41 39 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 43 public: 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. */ 51 48 QObjectValidator(QValidator *pValidator, QObject *pParent = 0); 52 49 53 50 /** Returns last validation state. */ 54 QValidator::State state() const { return m_ state; }51 QValidator::State state() const { return m_enmState; } 55 52 56 53 public slots: … … 64 61 void prepare(); 65 62 66 /** Holds validator. */63 /** Holds the validator reference. */ 67 64 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, 73 72 * which can group various QObjectValidator instances to operate on. */ 74 73 class QObjectValidatorGroup : public QObject … … 78 77 signals: 79 78 80 /** Notifies listener(s) about validity change . */79 /** Notifies listener(s) about validity changed to @a fValid. */ 81 80 void sigValidityChange(bool fValid); 82 81 83 82 public: 84 83 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. 90 91 * @note The ownership of @a pObjectValidator is transferred to the group, 91 92 * and it's the group's responsibility to delete it. */ … … 97 98 private slots: 98 99 99 /** Performs validation :*/100 void sltValidate(QValidator::State state);100 /** Performs validation for a passed @a enmState. */ 101 void sltValidate(QValidator::State enmState); 101 102 102 103 private: 103 104 104 105 /** Converts QValidator::State to bool result. */ 105 static bool toResult(QValidator::State state);106 static bool toResult(QValidator::State enmState); 106 107 107 108 /** Holds object-validators and their states. */ 108 109 QMap<QObjectValidator*, bool> m_group; 110 109 111 /** Holds validation result. */ 110 112 bool m_fResult; 111 113 }; 112 114 113 /* Page validator prototype: */ 115 116 /** Page validator prototype. */ 114 117 class UIPageValidator : public QObject 115 118 { … … 118 121 signals: 119 122 120 /* Notifier: Validation stuff:*/123 /** Notifies about validity change for @a pValidator. */ 121 124 void sigValidityChanged(UIPageValidator *pValidator); 122 125 123 /* Notifiers: Warning stuff:*/126 /** Asks listener to show warning icon. */ 124 127 void sigShowWarningIcon(); 128 /** Asks listener to hide warning icon. */ 125 129 void sigHideWarningIcon(); 126 130 127 131 public: 128 132 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. */ 134 144 QPixmap warningPixmap() const; 145 /** Returns internal name. */ 135 146 QString internalName() const; 136 147 137 /* API: Validity stuff:*/148 /** Returns whether validator is valid. */ 138 149 bool isValid() const { return m_fIsValid; } 150 /** Defines whether validator @a fIsValid. */ 139 151 void setValid(bool fIsValid) { m_fIsValid = fIsValid; } 140 152 141 /* API: Message stuff:*/153 /** Returns last message. */ 142 154 QString lastMessage() const { return m_strLastMessage; } 155 /** Defines @a strLastMessage. */ 143 156 void setLastMessage(const QString &strLastMessage); 144 157 145 158 public slots: 146 159 147 /* API/Handler: Validation stuff:*/160 /** Performs revalidation. */ 148 161 void revalidate(); 149 162 150 163 private: 151 164 152 /* Variables:*/165 /** Holds the validated page. */ 153 166 UISettingsPage *m_pPage; 167 168 /** Holds whether the page is valid. */ 154 169 bool m_fIsValid; 170 171 /** Holds the last message. */ 155 172 QString m_strLastMessage; 156 173 }; 157 174 175 176 /** QValidator extension, 177 * for long number validations. */ 158 178 class QIULongValidator : public QValidator 159 179 { 160 180 public: 161 181 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 214 private: 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.